@bobfrankston/msgapidefs 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(tsc:*)"
5
+ ],
6
+ "deny": [],
7
+ "ask": []
8
+ }
9
+ }
package/.gitattributes ADDED
@@ -0,0 +1,17 @@
1
+ # Force LF line endings for all text files
2
+ * text=auto eol=lf
3
+
4
+ # Explicit text files
5
+ *.ts text eol=lf
6
+ *.js text eol=lf
7
+ *.json text eol=lf
8
+ *.md text eol=lf
9
+ *.html text eol=lf
10
+ *.css text eol=lf
11
+ *.sh text eol=lf
12
+
13
+ # Binary files
14
+ *.png binary
15
+ *.jpg binary
16
+ *.ico binary
17
+ *.pdf binary
@@ -0,0 +1,22 @@
1
+ {
2
+ "workbench.colorCustomizations": {
3
+ "activityBar.activeBackground": "#c3b9ff",
4
+ "activityBar.background": "#c3b9ff",
5
+ "activityBar.foreground": "#15202b",
6
+ "activityBar.inactiveForeground": "#15202b99",
7
+ "activityBarBadge.background": "#ff2400",
8
+ "activityBarBadge.foreground": "#e7e7e7",
9
+ "commandCenter.border": "#15202b99",
10
+ "sash.hoverBorder": "#c3b9ff",
11
+ "statusBar.background": "#9786ff",
12
+ "statusBar.foreground": "#15202b",
13
+ "statusBarItem.hoverBackground": "#6b53ff",
14
+ "statusBarItem.remoteBackground": "#9786ff",
15
+ "statusBarItem.remoteForeground": "#15202b",
16
+ "titleBar.activeBackground": "#9786ff",
17
+ "titleBar.activeForeground": "#15202b",
18
+ "titleBar.inactiveBackground": "#9786ff99",
19
+ "titleBar.inactiveForeground": "#15202b99"
20
+ },
21
+ "peacock.color": "#9786ff"
22
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "version": "2.0.0",
3
+ "tasks": [
4
+ {
5
+ "label": "tsc: watch",
6
+ "type": "shell",
7
+ "command": "tsc",
8
+ "args": ["--watch"],
9
+ "runOptions": {
10
+ "runOn": "folderOpen"
11
+ },
12
+ "problemMatcher": "$tsc-watch",
13
+ "isBackground": true,
14
+ "group": {
15
+ "kind": "build",
16
+ "isDefault": true
17
+ }
18
+ }
19
+ ]
20
+ }
package/README.md CHANGED
@@ -10,47 +10,28 @@ npm install @bobfrankston/msgapidefs
10
10
 
11
11
  ## Usage
12
12
 
13
- ### TypeScript
14
-
15
13
  ```typescript
16
- import type { MsgAPI } from '@bobfrankston/msgapidefs';
17
- import { isMsgAPI, getMsgAPI } from '@bobfrankston/msgapidefs';
18
-
19
- // Option 1: Type the global window.msgapi
20
- declare global {
21
- interface Window {
22
- msgapi?: MsgAPI;
23
- }
24
- }
25
-
26
- // Check if running in msgview/msger
27
- if (isMsgAPI()) {
28
- window.msgapi!.setTitle('My Application');
29
- window.msgapi!.saveData('lastOpened', new Date().toISOString());
30
- }
31
-
32
- // Option 2: Use getMsgAPI() for cross-platform compatibility
33
- const msgapi = getMsgAPI();
34
- msgapi.saveData('userPrefs', { theme: 'dark' }); // Works in both msgview/msger and browser!
35
- msgapi.setTitle('My App'); // Only works in msgview/msger, no-op in browser
36
- ```
37
-
38
- ### JavaScript
14
+ // Import to register global window.msgapi type
15
+ import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
16
+ // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
39
17
 
40
- ```javascript
41
- import { isMsgAPI, getMsgAPI } from '@bobfrankston/msgapidefs';
18
+ // Or import types explicitly
19
+ import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
42
20
 
43
- const msgapi = getMsgAPI();
21
+ // msgapi provides APIs not available in browsers/webviews
22
+ if (window.msgapi) {
23
+ // Window control beyond browser capabilities
24
+ window.msgapi.setFullscreen(true);
25
+ window.msgapi.setAlwaysOnTop(true);
44
26
 
45
- // Data persistence (works in both msgview/msger and browser)
46
- msgapi.saveData('userSettings', { fontSize: 14, theme: 'dark' });
47
- const settings = msgapi.loadData('userSettings', { fontSize: 12 });
48
-
49
- // Window control (msgview/msger only, gracefully degrades in browser)
50
- if (isMsgAPI()) {
51
- msgapi.toggleFullscreen();
52
- msgapi.setAlwaysOnTop(true);
27
+ // File system access (requires allowFs flag)
28
+ const file = await window.msgapi.fs?.selectFile();
53
29
  }
30
+
31
+ // For standard browser APIs, use native methods:
32
+ document.title = 'My App'; // Instead of msgapi.setTitle()
33
+ localStorage.setItem('key', 'value'); // Instead of msgapi.saveData()
34
+ window.close(); // Instead of msgapi.close() if not passing result
54
35
  ```
55
36
 
56
37
  ## API Reference
@@ -64,17 +45,9 @@ if (isMsgAPI()) {
64
45
  - `setSize(width, height)` - Set window size
65
46
  - `setPosition(x, y)` - Set window position
66
47
  - `setAlwaysOnTop(enabled: boolean)` - Keep window on top
67
- - `setTitle(title: string)` - Set window title
68
- - `close(result?)` - Close window with optional result
69
-
70
- ### Data Persistence
71
-
72
- - `saveData(key, value)` - Save data to localStorage
73
- - `loadData(key, defaultValue?)` - Load data from localStorage
74
- - `removeData(key)` - Remove data
75
- - `clearData()` - Clear all msgapi data
48
+ - `close(result?)` - Close window and return result to parent process
76
49
 
77
- ### File System (Coming Soon)
50
+ ### File System
78
51
 
79
52
  - `fs.selectFile(options?)` - Open file picker
80
53
  - `fs.selectFiles(options?)` - Open multi-file picker
@@ -112,15 +85,6 @@ The samples demonstrate:
112
85
  - Session management
113
86
  - And more!
114
87
 
115
- ## Browser Compatibility
116
-
117
- The `getMsgAPI()` function returns a browser-compatible implementation:
118
-
119
- - **Data persistence**: Uses localStorage in both msgview/msger and browser
120
- - **Window control**: No-op in browser (except `setTitle` updates document.title)
121
- - **File system**: Not available in browser (`fs` is undefined)
122
-
123
- This allows you to write code once that works in both environments!
124
88
 
125
89
  ## Related Packages
126
90
 
package/msgapidefs.d.ts CHANGED
@@ -4,21 +4,7 @@
4
4
  * This module provides type-safe access to msgapi's window control,
5
5
  * data persistence, and file system features (used by msgview and msger).
6
6
  *
7
- * Usage:
8
- * ```typescript
9
- * import type { MsgAPI } from '@bobfrankston/msgapidefs';
10
- *
11
- * declare global {
12
- * interface Window {
13
- * msgapi?: MsgAPI;
14
- * }
15
- * }
16
- *
17
- * // Check if running in msgview/msger
18
- * if (window.msgapi) {
19
- * window.msgapi.setTitle('My App');
20
- * }
21
- * ```
7
+ * See README.md for complete usage documentation and examples.
22
8
  */
23
9
  /**
24
10
  * Result object returned when the window closes
@@ -134,14 +120,7 @@ export interface MsgAPI {
134
120
  */
135
121
  setAlwaysOnTop(enabled: boolean): void;
136
122
  /**
137
- * Set window title
138
- * @param title - New window title
139
- * @example
140
- * msgapi.setTitle("My Application");
141
- */
142
- setTitle(title: string): void;
143
- /**
144
- * Close the window
123
+ * Close the window and return result to parent process
145
124
  * @param result - Optional result to return to parent process
146
125
  * @example
147
126
  * // Close with default dismissed result
@@ -151,48 +130,6 @@ export interface MsgAPI {
151
130
  * msgapi.close({button: 'OK', value: 'user data'});
152
131
  */
153
132
  close(result?: Partial<MsgResult>): void;
154
- /**
155
- * Send result and close window (legacy compatibility)
156
- * @param result - Result to return to parent process
157
- * @example
158
- * msgapi.sendResult({button: 'Submit', value: 'form data'});
159
- */
160
- sendResult(result: Partial<MsgResult>): void;
161
- /**
162
- * Save data to persistent storage
163
- * Data is stored with 'msgapi_' prefix in localStorage
164
- * @param key - Storage key
165
- * @param value - Value to store (will be JSON.stringify'd)
166
- * @returns true on success, false on failure
167
- * @example
168
- * msgapi.saveData('userPrefs', {theme: 'dark', fontSize: 14});
169
- */
170
- saveData(key: string, value: any): boolean;
171
- /**
172
- * Load data from persistent storage
173
- * @param key - Storage key
174
- * @param defaultValue - Default value if key not found
175
- * @returns Stored value or defaultValue
176
- * @example
177
- * const prefs = msgapi.loadData('userPrefs', {theme: 'light'});
178
- */
179
- loadData<T = any>(key: string, defaultValue?: T): T;
180
- /**
181
- * Remove data from persistent storage
182
- * @param key - Storage key to remove
183
- * @returns true on success, false on failure
184
- * @example
185
- * msgapi.removeData('tempData');
186
- */
187
- removeData(key: string): boolean;
188
- /**
189
- * Clear all msgapi data from persistent storage
190
- * Only removes items with 'msgapi_' prefix
191
- * @returns true on success, false on failure
192
- * @example
193
- * msgapi.clearData();
194
- */
195
- clearData(): boolean;
196
133
  /**
197
134
  * File system operations namespace
198
135
  */
@@ -287,25 +224,6 @@ export interface MsgAPI {
287
224
  delete(path: string): Promise<void>;
288
225
  };
289
226
  }
290
- /**
291
- * Helper to check if code is running in msgview/msger
292
- * @returns true if running in msgapi environment
293
- * @example
294
- * if (isMsgAPI()) {
295
- * msgapi.setTitle('Running in msgview/msger!');
296
- * } else {
297
- * console.log('Running in browser');
298
- * }
299
- */
300
- export declare function isMsgAPI(): boolean;
301
- /**
302
- * Get msgapi API with fallback for browser compatibility
303
- * @returns msgapi API if available, or stub implementation for browser
304
- * @example
305
- * const api = getMsgAPI();
306
- * api.saveData('key', 'value'); // Works in both msgview/msger and browser
307
- */
308
- export declare function getMsgAPI(): MsgAPI;
309
227
  /**
310
228
  * Declare global window.msgapi
311
229
  */
@@ -314,8 +232,3 @@ declare global {
314
232
  msgapi?: MsgAPI;
315
233
  }
316
234
  }
317
- declare const _default: {
318
- isMsgAPI: typeof isMsgAPI;
319
- getMsgAPI: typeof getMsgAPI;
320
- };
321
- export default _default;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msgapidefs.d.ts","sourceRoot":"","sources":["msgapidefs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACtB,8BAA8B;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,iCAAiC;IACjC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,iDAAiD;IACjD,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,kDAAkD;IAClD,SAAS,CAAC,E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AAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QAElE;;;;;;;WAOG;QACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAEpC;;;;;;;WAOG;QACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;QAEpD;;;;;;;WAOG;QACH,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QAExC;;;;;;;WAOG;QACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;QAEvC;;;;;;WAMG;QACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KACvC,CAAC;CACL;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,IAAI,OAAO,CAElC;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,MAAM,CA6DlC;AAED;;GAEG;AACH,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,MAAM,CAAC,EAAE,MAAM,CAAC;KACnB;CACJ;;;;;AAED,wBAGE"}
package/msgapidefs.js CHANGED
@@ -4,106 +4,6 @@
4
4
  * This module provides type-safe access to msgapi's window control,
5
5
  * data persistence, and file system features (used by msgview and msger).
6
6
  *
7
- * Usage:
8
- * ```typescript
9
- * import type { MsgAPI } from '@bobfrankston/msgapidefs';
10
- *
11
- * declare global {
12
- * interface Window {
13
- * msgapi?: MsgAPI;
14
- * }
15
- * }
16
- *
17
- * // Check if running in msgview/msger
18
- * if (window.msgapi) {
19
- * window.msgapi.setTitle('My App');
20
- * }
21
- * ```
22
- */
23
- /**
24
- * Helper to check if code is running in msgview/msger
25
- * @returns true if running in msgapi environment
26
- * @example
27
- * if (isMsgAPI()) {
28
- * msgapi.setTitle('Running in msgview/msger!');
29
- * } else {
30
- * console.log('Running in browser');
31
- * }
32
- */
33
- export function isMsgAPI() {
34
- return typeof window !== 'undefined' && typeof window.msgapi !== 'undefined';
35
- }
36
- /**
37
- * Get msgapi API with fallback for browser compatibility
38
- * @returns msgapi API if available, or stub implementation for browser
39
- * @example
40
- * const api = getMsgAPI();
41
- * api.saveData('key', 'value'); // Works in both msgview/msger and browser
7
+ * See README.md for complete usage documentation and examples.
42
8
  */
43
- export function getMsgAPI() {
44
- if (isMsgAPI()) {
45
- return window.msgapi;
46
- }
47
- // Return browser-compatible stub
48
- return {
49
- // Window control - no-op in browser
50
- toggleFullscreen: () => { },
51
- setFullscreen: () => { },
52
- minimize: () => { },
53
- maximize: () => { },
54
- setSize: () => { },
55
- setPosition: () => { },
56
- setAlwaysOnTop: () => { },
57
- setTitle: (title) => { document.title = title; },
58
- close: () => { window.close(); },
59
- sendResult: () => { window.close(); },
60
- // Data persistence - use localStorage in browser
61
- saveData: (key, value) => {
62
- try {
63
- localStorage.setItem('msgapi_' + key, JSON.stringify(value));
64
- return true;
65
- }
66
- catch {
67
- return false;
68
- }
69
- },
70
- loadData: (key, defaultValue) => {
71
- try {
72
- const item = localStorage.getItem('msgapi_' + key);
73
- return item ? JSON.parse(item) : defaultValue;
74
- }
75
- catch {
76
- return defaultValue;
77
- }
78
- },
79
- removeData: (key) => {
80
- try {
81
- localStorage.removeItem('msgapi_' + key);
82
- return true;
83
- }
84
- catch {
85
- return false;
86
- }
87
- },
88
- clearData: () => {
89
- try {
90
- const keys = Object.keys(localStorage);
91
- for (const key of keys) {
92
- if (key.startsWith('msgapi_')) {
93
- localStorage.removeItem(key);
94
- }
95
- }
96
- return true;
97
- }
98
- catch {
99
- return false;
100
- }
101
- },
102
- // File system - not available in browser
103
- fs: undefined
104
- };
105
- }
106
- export default {
107
- isMsgAPI,
108
- getMsgAPI
109
- };
9
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"msgapidefs.js","sourceRoot":"","sources":["msgapidefs.ts"],"names":[],"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AE,YAAgB,EAAK,EAAE;YACpD,IAAI,CAAC;gBACD,MAAM,IAAI,GAAG,YAAY,CAAC,OAAO,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC;gBACnD,OAAO,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,YAAkB,CAAC;YACzD,CAAC;YAAC,MAAM,CAAC;gBACL,OAAO,YAAiB,CAAC;YAC7B,CAAC;QACL,CAAC;QACD,UAAU,EAAE,CAAC,GAAW,EAAW,EAAE;YACjC,IAAI,CAAC;gBACD,YAAY,CAAC,UAAU,CAAC,SAAS,GAAG,GAAG,CAAC,CAAC;gBACzC,OAAO,IAAI,CAAC;YAChB,CAAC;YAAC,MAAM,CAAC;gBACL,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QACD,SAAS,EAAE,GAAY,EAAE;YACrB,IAAI,CAAC;gBACD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACvC,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;oBACrB,IAAI,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;wBAC5B,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;oBACjC,CAAC;gBACL,CAAC;gBACD,OAAO,IAAI,CAAC;YAChB,CAAC;YAAC,MAAM,CAAC;gBACL,OAAO,KAAK,CAAC;YACjB,CAAC;QACL,CAAC;QAED,yCAAyC;QACzC,EAAE,EAAE,SAAS;KAChB,CAAC;AACN,CAAC;AAWD,eAAe;IACX,QAAQ;IACR,SAAS;CACZ,CAAC"}
package/msgapidefs.ts CHANGED
@@ -4,21 +4,7 @@
4
4
  * This module provides type-safe access to msgapi's window control,
5
5
  * data persistence, and file system features (used by msgview and msger).
6
6
  *
7
- * Usage:
8
- * ```typescript
9
- * import type { MsgAPI } from '@bobfrankston/msgapidefs';
10
- *
11
- * declare global {
12
- * interface Window {
13
- * msgapi?: MsgAPI;
14
- * }
15
- * }
16
- *
17
- * // Check if running in msgview/msger
18
- * if (window.msgapi) {
19
- * window.msgapi.setTitle('My App');
20
- * }
21
- * ```
7
+ * See README.md for complete usage documentation and examples.
22
8
  */
23
9
 
24
10
  /**
@@ -147,15 +133,7 @@ export interface MsgAPI {
147
133
  setAlwaysOnTop(enabled: boolean): void;
148
134
 
149
135
  /**
150
- * Set window title
151
- * @param title - New window title
152
- * @example
153
- * msgapi.setTitle("My Application");
154
- */
155
- setTitle(title: string): void;
156
-
157
- /**
158
- * Close the window
136
+ * Close the window and return result to parent process
159
137
  * @param result - Optional result to return to parent process
160
138
  * @example
161
139
  * // Close with default dismissed result
@@ -166,59 +144,8 @@ export interface MsgAPI {
166
144
  */
167
145
  close(result?: Partial<MsgResult>): void;
168
146
 
169
- /**
170
- * Send result and close window (legacy compatibility)
171
- * @param result - Result to return to parent process
172
- * @example
173
- * msgapi.sendResult({button: 'Submit', value: 'form data'});
174
- */
175
- sendResult(result: Partial<MsgResult>): void;
176
-
177
147
  // ========================================
178
- // Data Persistence (localStorage wrapper)
179
- // ========================================
180
-
181
- /**
182
- * Save data to persistent storage
183
- * Data is stored with 'msgapi_' prefix in localStorage
184
- * @param key - Storage key
185
- * @param value - Value to store (will be JSON.stringify'd)
186
- * @returns true on success, false on failure
187
- * @example
188
- * msgapi.saveData('userPrefs', {theme: 'dark', fontSize: 14});
189
- */
190
- saveData(key: string, value: any): boolean;
191
-
192
- /**
193
- * Load data from persistent storage
194
- * @param key - Storage key
195
- * @param defaultValue - Default value if key not found
196
- * @returns Stored value or defaultValue
197
- * @example
198
- * const prefs = msgapi.loadData('userPrefs', {theme: 'light'});
199
- */
200
- loadData<T = any>(key: string, defaultValue?: T): T;
201
-
202
- /**
203
- * Remove data from persistent storage
204
- * @param key - Storage key to remove
205
- * @returns true on success, false on failure
206
- * @example
207
- * msgapi.removeData('tempData');
208
- */
209
- removeData(key: string): boolean;
210
-
211
- /**
212
- * Clear all msgapi data from persistent storage
213
- * Only removes items with 'msgapi_' prefix
214
- * @returns true on success, false on failure
215
- * @example
216
- * msgapi.clearData();
217
- */
218
- clearData(): boolean;
219
-
220
- // ========================================
221
- // File System Access (to be implemented)
148
+ // File System Access
222
149
  // ========================================
223
150
 
224
151
  /**
@@ -328,90 +255,6 @@ export interface MsgAPI {
328
255
  };
329
256
  }
330
257
 
331
- /**
332
- * Helper to check if code is running in msgview/msger
333
- * @returns true if running in msgapi environment
334
- * @example
335
- * if (isMsgAPI()) {
336
- * msgapi.setTitle('Running in msgview/msger!');
337
- * } else {
338
- * console.log('Running in browser');
339
- * }
340
- */
341
- export function isMsgAPI(): boolean {
342
- return typeof window !== 'undefined' && typeof window.msgapi !== 'undefined';
343
- }
344
-
345
- /**
346
- * Get msgapi API with fallback for browser compatibility
347
- * @returns msgapi API if available, or stub implementation for browser
348
- * @example
349
- * const api = getMsgAPI();
350
- * api.saveData('key', 'value'); // Works in both msgview/msger and browser
351
- */
352
- export function getMsgAPI(): MsgAPI {
353
- if (isMsgAPI()) {
354
- return window.msgapi!;
355
- }
356
-
357
- // Return browser-compatible stub
358
- return {
359
- // Window control - no-op in browser
360
- toggleFullscreen: () => {},
361
- setFullscreen: () => {},
362
- minimize: () => {},
363
- maximize: () => {},
364
- setSize: () => {},
365
- setPosition: () => {},
366
- setAlwaysOnTop: () => {},
367
- setTitle: (title: string) => { document.title = title; },
368
- close: () => { window.close(); },
369
- sendResult: () => { window.close(); },
370
-
371
- // Data persistence - use localStorage in browser
372
- saveData: (key: string, value: any): boolean => {
373
- try {
374
- localStorage.setItem('msgapi_' + key, JSON.stringify(value));
375
- return true;
376
- } catch {
377
- return false;
378
- }
379
- },
380
- loadData: <T = any>(key: string, defaultValue?: T): T => {
381
- try {
382
- const item = localStorage.getItem('msgapi_' + key);
383
- return item ? JSON.parse(item) : (defaultValue as T);
384
- } catch {
385
- return defaultValue as T;
386
- }
387
- },
388
- removeData: (key: string): boolean => {
389
- try {
390
- localStorage.removeItem('msgapi_' + key);
391
- return true;
392
- } catch {
393
- return false;
394
- }
395
- },
396
- clearData: (): boolean => {
397
- try {
398
- const keys = Object.keys(localStorage);
399
- for (const key of keys) {
400
- if (key.startsWith('msgapi_')) {
401
- localStorage.removeItem(key);
402
- }
403
- }
404
- return true;
405
- } catch {
406
- return false;
407
- }
408
- },
409
-
410
- // File system - not available in browser
411
- fs: undefined
412
- };
413
- }
414
-
415
258
  /**
416
259
  * Declare global window.msgapi
417
260
  */
@@ -420,8 +263,3 @@ declare global {
420
263
  msgapi?: MsgAPI;
421
264
  }
422
265
  }
423
-
424
- export default {
425
- isMsgAPI,
426
- getMsgAPI
427
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bobfrankston/msgapidefs",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "TypeScript definitions for msgapi JavaScript API (msgview/msger)",
5
5
  "type": "module",
6
6
  "main": "./msgapidefs.js",
@@ -11,13 +11,6 @@
11
11
  "types": "./msgapidefs.d.ts"
12
12
  }
13
13
  },
14
- "files": [
15
- "msgapidefs.js",
16
- "msgapidefs.d.ts",
17
- "msgapidefs.ts",
18
- "README.md",
19
- "samples.html"
20
- ],
21
14
  "keywords": [
22
15
  "msgapi",
23
16
  "msgview",
package/tsconfig.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "lib": ["ES2020", "DOM"],
6
+ "declaration": true,
7
+ "outDir": ".",
8
+ "rootDir": ".",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "moduleResolution": "node",
14
+ "newLine": "lf"
15
+ },
16
+ "include": ["msgapidefs.ts"],
17
+ "exclude": ["node_modules"]
18
+ }