@bobfrankston/msgapidefs 0.1.1 → 0.1.2
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.
- package/.claude/settings.local.json +9 -0
- package/.gitattributes +17 -0
- package/.vscode/settings.json +22 -0
- package/.vscode/tasks.json +20 -0
- package/msgapidefs.d.ts +6 -31
- package/msgapidefs.d.ts.map +1 -0
- package/msgapidefs.js +7 -94
- package/msgapidefs.js.map +1 -0
- package/msgapidefs.ts +6 -96
- package/package.json +1 -8
- package/tsconfig.json +18 -0
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/msgapidefs.d.ts
CHANGED
|
@@ -6,15 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* ```typescript
|
|
9
|
-
*
|
|
9
|
+
* // Import to register global window.msgapi type (browser direct import)
|
|
10
|
+
* import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
11
|
+
* // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* msgapi?: MsgAPI;
|
|
14
|
-
* }
|
|
15
|
-
* }
|
|
13
|
+
* // Or import types explicitly
|
|
14
|
+
* import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
16
15
|
*
|
|
17
|
-
* //
|
|
16
|
+
* // window.msgapi is now typed automatically
|
|
18
17
|
* if (window.msgapi) {
|
|
19
18
|
* window.msgapi.setTitle('My App');
|
|
20
19
|
* }
|
|
@@ -287,25 +286,6 @@ export interface MsgAPI {
|
|
|
287
286
|
delete(path: string): Promise<void>;
|
|
288
287
|
};
|
|
289
288
|
}
|
|
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
289
|
/**
|
|
310
290
|
* Declare global window.msgapi
|
|
311
291
|
*/
|
|
@@ -314,8 +294,3 @@ declare global {
|
|
|
314
294
|
msgapi?: MsgAPI;
|
|
315
295
|
}
|
|
316
296
|
}
|
|
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,CA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AM,EACf,eAAe,CAAC,EAAE,MAAM,EACxB,OAAO,CAAC,EAAE,iBAAiB,GAC5B,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;QAE1B;;;;;;;;WAQG;QACH,YAAY,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,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
|
@@ -6,104 +6,17 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* ```typescript
|
|
9
|
-
*
|
|
9
|
+
* // Import to register global window.msgapi type (browser direct import)
|
|
10
|
+
* import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
11
|
+
* // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* msgapi?: MsgAPI;
|
|
14
|
-
* }
|
|
15
|
-
* }
|
|
13
|
+
* // Or import types explicitly
|
|
14
|
+
* import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
16
15
|
*
|
|
17
|
-
* //
|
|
16
|
+
* // window.msgapi is now typed automatically
|
|
18
17
|
* if (window.msgapi) {
|
|
19
18
|
* window.msgapi.setTitle('My App');
|
|
20
19
|
* }
|
|
21
20
|
* ```
|
|
22
21
|
*/
|
|
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
|
|
42
|
-
*/
|
|
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
|
-
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgapidefs.js","sourceRoot":"","sources":["msgapidefs.ts"],"names":[],"mappings":"A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gB,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
|
@@ -6,15 +6,14 @@
|
|
|
6
6
|
*
|
|
7
7
|
* Usage:
|
|
8
8
|
* ```typescript
|
|
9
|
-
*
|
|
9
|
+
* // Import to register global window.msgapi type (browser direct import)
|
|
10
|
+
* import '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
11
|
+
* // Note: '../node_modules/@bobfrankston/msgapidefs/index.js' may also work via package.json exports
|
|
10
12
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* msgapi?: MsgAPI;
|
|
14
|
-
* }
|
|
15
|
-
* }
|
|
13
|
+
* // Or import types explicitly
|
|
14
|
+
* import type { MsgAPI, MsgResult } from '../node_modules/@bobfrankston/msgapidefs/msgapidefs.js';
|
|
16
15
|
*
|
|
17
|
-
* //
|
|
16
|
+
* // window.msgapi is now typed automatically
|
|
18
17
|
* if (window.msgapi) {
|
|
19
18
|
* window.msgapi.setTitle('My App');
|
|
20
19
|
* }
|
|
@@ -328,90 +327,6 @@ export interface MsgAPI {
|
|
|
328
327
|
};
|
|
329
328
|
}
|
|
330
329
|
|
|
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
330
|
/**
|
|
416
331
|
* Declare global window.msgapi
|
|
417
332
|
*/
|
|
@@ -420,8 +335,3 @@ declare global {
|
|
|
420
335
|
msgapi?: MsgAPI;
|
|
421
336
|
}
|
|
422
337
|
}
|
|
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.
|
|
3
|
+
"version": "0.1.2",
|
|
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
|
+
}
|