webext-schema 5.1.4 → 5.1.5

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/README.md CHANGED
@@ -16,7 +16,7 @@ npm i webext-schema
16
16
  ## Usage
17
17
 
18
18
  ```
19
- const {Schema} = require("webext-schema");
19
+ import { Schema } from 'webext-schema';
20
20
 
21
21
  const schema = new Schema();
22
22
  ```
package/index.js CHANGED
@@ -8,8 +8,8 @@
8
8
 
9
9
  /* api */
10
10
  import process from 'node:process';
11
+ import { parseCommand } from './modules/commander.js';
11
12
  import { logErr, throwErr } from './modules/common.js';
12
- import { parseCommand } from './modules/update.js';
13
13
  export { Schema } from './modules/schema.js';
14
14
 
15
15
  /* process */
@@ -12,7 +12,7 @@ const { permissions, runtime, tabs, windows } = browser;
12
12
  * check if permission is granted
13
13
  *
14
14
  * @param {object} perm - permissions.Permission
15
- * @returns {boolean} - result
15
+ * @returns {Promise.<boolean>} - result
16
16
  */
17
17
  export const isPermissionGranted = async perm => {
18
18
  const bool = await permissions.contains(perm);
@@ -24,7 +24,7 @@ export const isPermissionGranted = async perm => {
24
24
  * create bookmark
25
25
  *
26
26
  * @param {object} opt - bookmarks.CreateDetails
27
- * @returns {object} - bookmarks.BookmarkTreeNode
27
+ * @returns {Promise.<object>} - bookmarks.BookmarkTreeNode
28
28
  */
29
29
  export const createBookmark = async opt => {
30
30
  const isGranted = await isPermissionGranted({
@@ -42,7 +42,7 @@ export const createBookmark = async opt => {
42
42
  * get bookmark tree node
43
43
  *
44
44
  * @param {string|Array} id - bookmark ID or array of bookmark IDs
45
- * @returns {?Array} - array of bookmarks.BookmarkTreeNode
45
+ * @returns {Promise.<?Array>} - array of bookmarks.BookmarkTreeNode
46
46
  */
47
47
  export const getBookmarkTreeNode = async id => {
48
48
  const isGranted = await isPermissionGranted({
@@ -66,7 +66,7 @@ export const getBookmarkTreeNode = async id => {
66
66
  /**
67
67
  * get closeTabsByDoubleClick user value
68
68
  *
69
- * @returns {object} - user value
69
+ * @returns {Promise.<object>} - user value
70
70
  */
71
71
  export const getCloseTabsByDoubleClickValue = async () => {
72
72
  const isGranted = await isPermissionGranted({
@@ -83,7 +83,7 @@ export const getCloseTabsByDoubleClickValue = async () => {
83
83
  /**
84
84
  * set context menu on mouseup
85
85
  *
86
- * @returns {boolean} - result
86
+ * @returns {Promise.<boolean>} - result
87
87
  */
88
88
  export const setContextMenuOnMouseup = async () => {
89
89
  const isGranted = await isPermissionGranted({
@@ -107,7 +107,7 @@ export const setContextMenuOnMouseup = async () => {
107
107
  /**
108
108
  * clear context menu on mouseup
109
109
  *
110
- * @returns {boolean} - result
110
+ * @returns {Promise.<boolean>} - result
111
111
  */
112
112
  export const clearContextMenuOnMouseup = async () => {
113
113
  const isGranted = await isPermissionGranted({
@@ -124,7 +124,7 @@ export const clearContextMenuOnMouseup = async () => {
124
124
  /**
125
125
  * get new tab position value
126
126
  *
127
- * @returns {object} - result
127
+ * @returns {Promise.<object>} - result
128
128
  */
129
129
  export const getNewTabPositionValue = async () => {
130
130
  const isGranted = await isPermissionGranted({
@@ -142,7 +142,7 @@ export const getNewTabPositionValue = async () => {
142
142
  /**
143
143
  * is command customizable
144
144
  *
145
- * @returns {boolean} - result
145
+ * @returns {Promise.<boolean>} - result
146
146
  */
147
147
  export const isCommandCustomizable = async () => {
148
148
  const isGranted = await isPermissionGranted({
@@ -162,7 +162,7 @@ export const isCommandCustomizable = async () => {
162
162
  *
163
163
  * @param {string} id - command ID
164
164
  * @param {string} value - key value
165
- * @returns {?Function} - commands.update() | commands.reset()
165
+ * @returns {Promise.<?void>} - commands.update() | commands.reset()
166
166
  */
167
167
  export const updateCommand = async (id, value = '') => {
168
168
  if (!isString(id)) {
@@ -192,7 +192,7 @@ export const updateCommand = async (id, value = '') => {
192
192
  /**
193
193
  * get all contextual identities
194
194
  *
195
- * @returns {?Array} - array of contextualIdentities.ContextualIdentity
195
+ * @returns {Promise.<?Array>} - array of contextualIdentities.ContextualIdentity
196
196
  */
197
197
  export const getAllContextualIdentities = async () => {
198
198
  const isGranted = await isPermissionGranted({
@@ -210,7 +210,7 @@ export const getAllContextualIdentities = async () => {
210
210
  * get contextual identities
211
211
  *
212
212
  * @param {string} cookieStoreId - cookie store ID
213
- * @returns {object} - contextualIdentities.ContextualIdentity
213
+ * @returns {Promise.<object>} - contextualIdentities.ContextualIdentity
214
214
  */
215
215
  export const getContextualId = async cookieStoreId => {
216
216
  if (!isString(cookieStoreId)) {
@@ -231,7 +231,7 @@ export const getContextualId = async cookieStoreId => {
231
231
  /**
232
232
  * get enabled theme
233
233
  *
234
- * @returns {?Array} - array of management.ExtensionInfo
234
+ * @returns {Promise.<?Array>} - array of management.ExtensionInfo
235
235
  */
236
236
  export const getEnabledTheme = async () => {
237
237
  const isGranted = await isPermissionGranted({
@@ -252,7 +252,7 @@ export const getEnabledTheme = async () => {
252
252
  * get extension info
253
253
  *
254
254
  * @param {string} id - extension ID
255
- * @returns {object} - management.extensionInfo
255
+ * @returns {Promise.<object>} - management.extensionInfo
256
256
  */
257
257
  export const getExtensionInfo = async id => {
258
258
  if (!isString(id)) {
@@ -272,7 +272,7 @@ export const getExtensionInfo = async id => {
272
272
  /**
273
273
  * get external extensions
274
274
  *
275
- * @returns {?Array|boolean} - array of management.extensionInfo
275
+ * @returns {Promise.<?Array|boolean>} - array of management.extensionInfo
276
276
  */
277
277
  export const getExternalExtensions = async () => {
278
278
  const isGranted = await isPermissionGranted({
@@ -294,7 +294,7 @@ export const getExternalExtensions = async () => {
294
294
  * clear notification
295
295
  *
296
296
  * @param {string} id - notification ID
297
- * @returns {?Function} - notifications.clear()
297
+ * @returns {Promise.<?boolean>} - notifications.clear()
298
298
  */
299
299
  export const clearNotification = async id => {
300
300
  if (!isString(id)) {
@@ -316,7 +316,7 @@ export const clearNotification = async id => {
316
316
  *
317
317
  * @param {string} id - notification ID
318
318
  * @param {object} opt - options
319
- * @returns {?Function} - notifications.create()
319
+ * @returns {Promise.<?string>} - notifications.create()
320
320
  */
321
321
  export const createNotification = async (id, opt) => {
322
322
  if (!isString(id)) {
@@ -341,7 +341,7 @@ export const createNotification = async (id, opt) => {
341
341
  * remove permission
342
342
  *
343
343
  * @param {string|Array} perm - permission
344
- * @returns {boolean} - result
344
+ * @returns {Promise.<boolean>} - result
345
345
  */
346
346
  export const removePermission = async perm => {
347
347
  if (!(isString(perm) || Array.isArray(perm))) {
@@ -364,7 +364,7 @@ export const removePermission = async perm => {
364
364
  * request permission
365
365
  *
366
366
  * @param {string|Array} perm - permission
367
- * @returns {boolean} - result
367
+ * @returns {Promise.<boolean>} - result
368
368
  */
369
369
  export const requestPermission = async perm => {
370
370
  if (!(isString(perm) || Array.isArray(perm))) {
@@ -407,7 +407,7 @@ export const getManifestVersion = () => {
407
407
  /**
408
408
  * get OS
409
409
  *
410
- * @returns {string} - OS
410
+ * @returns {Promise.<string>} - OS
411
411
  */
412
412
  export const getOs = async () => {
413
413
  const { os } = await runtime.getPlatformInfo();
@@ -419,7 +419,7 @@ export const getOs = async () => {
419
419
  *
420
420
  * @param {number|string} [id] - tab ID / extension ID / host name
421
421
  * @param {object|boolean} [info] - connection info / connect to native app
422
- * @returns {object} - runtime.Port
422
+ * @returns {Promise.<object>} - runtime.Port
423
423
  */
424
424
  export const makeConnection = async (id, info) => {
425
425
  let port;
@@ -453,7 +453,7 @@ export const makeConnection = async (id, info) => {
453
453
  * @param {number|string} id - tab ID / extension ID
454
454
  * @param {*} msg - message
455
455
  * @param {object} opt - options
456
- * @returns {?Function} - tabs.sendMessage() | runtime.sendMessage()
456
+ * @returns {Promise.<object>} - tabs.sendMessage() | runtime.sendMessage()
457
457
  */
458
458
  export const sendMessage = async (id, msg, opt) => {
459
459
  let func;
@@ -476,7 +476,7 @@ export const sendMessage = async (id, msg, opt) => {
476
476
  /**
477
477
  * is scripting available
478
478
  *
479
- * @returns {boolean} - result
479
+ * @returns {Promise.<boolean>} - result
480
480
  */
481
481
  export const isScriptingAvailable = async () => {
482
482
  const isGranted = await isPermissionGranted({
@@ -494,7 +494,7 @@ export const isScriptingAvailable = async () => {
494
494
  * execute script to tab
495
495
  *
496
496
  * @param {object} opt - options
497
- * @returns {?Array|boolean} - array of InjectionResult object
497
+ * @returns {Promise.<?Array|boolean>} - array of InjectionResult object
498
498
  */
499
499
  export const executeScriptToTab = async (opt = {}) => {
500
500
  const { args, injectImmediately, files, func, target } = opt;
@@ -526,7 +526,7 @@ export const executeScriptToTab = async (opt = {}) => {
526
526
  *
527
527
  * @param {string} query - search query
528
528
  * @param {object} opt - options
529
- * @returns {void}
529
+ * @returns {Promise.<void>} - void
530
530
  */
531
531
  export const searchWithSearchEngine = async (query, opt = {}) => {
532
532
  if (!isString(query)) {
@@ -546,8 +546,8 @@ export const searchWithSearchEngine = async (query, opt = {}) => {
546
546
  /**
547
547
  * get recently closed tab
548
548
  *
549
- * @param {number} windowId - window ID
550
- * @returns {object} - tabs.Tab
549
+ * @param {number} [windowId] - window ID
550
+ * @returns {Promise.<object>} - tabs.Tab
551
551
  */
552
552
  export const getRecentlyClosedTab = async windowId => {
553
553
  const isGranted = await isPermissionGranted({
@@ -580,8 +580,8 @@ export const getRecentlyClosedTab = async windowId => {
580
580
  * get session window value
581
581
  *
582
582
  * @param {string} key - key
583
- * @param {number} windowId - window ID
584
- * @returns {string} - value
583
+ * @param {number} [windowId] - window ID
584
+ * @returns {Promise.<?string>} - value
585
585
  */
586
586
  export const getSessionWindowValue = async (key, windowId) => {
587
587
  if (!isString(key)) {
@@ -605,7 +605,7 @@ export const getSessionWindowValue = async (key, windowId) => {
605
605
  * restore session
606
606
  *
607
607
  * @param {string} sessionId - session ID
608
- * @returns {object} - sessions.Session
608
+ * @returns {Promise.<object>} - sessions.Session
609
609
  */
610
610
  export const restoreSession = async sessionId => {
611
611
  if (!isString(sessionId)) {
@@ -627,8 +627,8 @@ export const restoreSession = async sessionId => {
627
627
  *
628
628
  * @param {string} key - key
629
629
  * @param {string|object} value - value
630
- * @param {number} windowId - window ID
631
- * @returns {void}
630
+ * @param {number} [windowId] - window ID
631
+ * @returns {Promise.<void>} - void
632
632
  */
633
633
  export const setSessionWindowValue = async (key, value, windowId) => {
634
634
  if (!isString(key)) {
@@ -651,7 +651,7 @@ export const setSessionWindowValue = async (key, value, windowId) => {
651
651
  * clear storage
652
652
  *
653
653
  * @param {string} area - storage area
654
- * @returns {void}
654
+ * @returns {Promise.<void>} - void
655
655
  */
656
656
  export const clearStorage = async (area = 'local') => {
657
657
  const isGranted = await isPermissionGranted({
@@ -668,7 +668,7 @@ export const clearStorage = async (area = 'local') => {
668
668
  * get all storage
669
669
  *
670
670
  * @param {string} area - storage area
671
- * @returns {object} - stored data
671
+ * @returns {Promise.<object>} - stored data
672
672
  */
673
673
  export const getAllStorage = async (area = 'local') => {
674
674
  const isGranted = await isPermissionGranted({
@@ -688,7 +688,7 @@ export const getAllStorage = async (area = 'local') => {
688
688
  *
689
689
  * @param {*} key - key
690
690
  * @param {string} area - storage area
691
- * @returns {object} - stored data
691
+ * @returns {Promise.<object>} - stored data
692
692
  */
693
693
  export const getStorage = async (key, area = 'local') => {
694
694
  const isGranted = await isPermissionGranted({
@@ -708,7 +708,7 @@ export const getStorage = async (key, area = 'local') => {
708
708
  *
709
709
  * @param {*} key - key
710
710
  * @param {string} area - storage area
711
- * @returns {void}
711
+ * @returns {Promise.<void>} - void
712
712
  */
713
713
  export const removeStorage = async (key, area = 'local') => {
714
714
  const isGranted = await isPermissionGranted({
@@ -726,7 +726,7 @@ export const removeStorage = async (key, area = 'local') => {
726
726
  *
727
727
  * @param {object} obj - object to store
728
728
  * @param {string} area - storage area
729
- * @returns {void}
729
+ * @returns {Promise.<void>} - void
730
730
  */
731
731
  export const setStorage = async (obj, area = 'local') => {
732
732
  const isGranted = await isPermissionGranted({
@@ -744,7 +744,7 @@ export const setStorage = async (obj, area = 'local') => {
744
744
  * create tab
745
745
  *
746
746
  * @param {object} opt - options
747
- * @returns {object} - tabs.Tab
747
+ * @returns {Promise.<object>} - tabs.Tab
748
748
  */
749
749
  export const createTab = async (opt = {}) => {
750
750
  const tab = await tabs.create(isObjectNotEmpty(opt) ? opt : null);
@@ -756,7 +756,7 @@ export const createTab = async (opt = {}) => {
756
756
  *
757
757
  * @param {number} tabId - tab ID
758
758
  * @param {object} opt - options
759
- * @returns {object} - tabs.Tab
759
+ * @returns {Promise.<object>} - tabs.Tab
760
760
  */
761
761
  export const duplicateTab = async (tabId, opt) => {
762
762
  if (!Number.isInteger(tabId)) {
@@ -770,7 +770,7 @@ export const duplicateTab = async (tabId, opt) => {
770
770
  * query tabs
771
771
  *
772
772
  * @param {object} opt - options
773
- * @returns {?Array} - result
773
+ * @returns {Promise.<?Array>} - result
774
774
  */
775
775
  export const queryTabs = async opt => {
776
776
  const res = await tabs.query(opt);
@@ -782,7 +782,7 @@ export const queryTabs = async opt => {
782
782
  *
783
783
  * @param {number|object} tabId - tab ID or options
784
784
  * @param {object} opt - options
785
- * @returns {?Array|boolean} - result
785
+ * @returns {Promise.<?Array|boolean>} - result
786
786
  */
787
787
  export const execScriptToTab = async (tabId, opt = {}) => {
788
788
  let res;
@@ -829,7 +829,7 @@ export const execScriptToTabs = async (opt = {}) => {
829
829
  *
830
830
  * @param {number|Array} tabId - tabId or array of options
831
831
  * @param {Array} opts - array of options
832
- * @returns {*} - result of the last executed script
832
+ * @returns {Promise.<*>} - result of the last executed script
833
833
  */
834
834
  export const execScriptsToTabInOrder = async (tabId, opts = []) => {
835
835
  const func = [];
@@ -859,8 +859,8 @@ export const execScriptsToTabInOrder = async (tabId, opts = []) => {
859
859
  /**
860
860
  * get active tab
861
861
  *
862
- * @param {number} windowId - window ID
863
- * @returns {object} - tabs.Tab
862
+ * @param {number} [windowId] - window ID
863
+ * @returns {Promise.<object>} - tabs.Tab
864
864
  */
865
865
  export const getActiveTab = async windowId => {
866
866
  if (!Number.isInteger(windowId)) {
@@ -877,8 +877,8 @@ export const getActiveTab = async windowId => {
877
877
  /**
878
878
  * get active tab ID
879
879
  *
880
- * @param {number} windowId - window ID
881
- * @returns {?number} - tab ID
880
+ * @param {number} [windowId] - window ID
881
+ * @returns {Promise.<?number>} - tab ID
882
882
  */
883
883
  export const getActiveTabId = async windowId => {
884
884
  if (!Number.isInteger(windowId)) {
@@ -895,8 +895,8 @@ export const getActiveTabId = async windowId => {
895
895
  /**
896
896
  * get all tabs in window
897
897
  *
898
- * @param {number} windowId - window ID
899
- * @returns {?Array} - array of tabs.Tab
898
+ * @param {number} [windowId] - window ID
899
+ * @returns {Promise.<?Array>} - array of tabs.Tab
900
900
  */
901
901
  export const getAllTabsInWindow = async windowId => {
902
902
  if (!Number.isInteger(windowId)) {
@@ -912,8 +912,8 @@ export const getAllTabsInWindow = async windowId => {
912
912
  /**
913
913
  * get highlighted tab
914
914
  *
915
- * @param {number} windowId - window ID
916
- * @returns {?Array} - array of tabs.Tab
915
+ * @param {number} [windowId] - window ID
916
+ * @returns {Promise.<?Array>} - array of tabs.Tab
917
917
  */
918
918
  export const getHighlightedTab = async windowId => {
919
919
  if (!Number.isInteger(windowId)) {
@@ -931,7 +931,7 @@ export const getHighlightedTab = async windowId => {
931
931
  * get tab
932
932
  *
933
933
  * @param {number} tabId - tab ID
934
- * @returns {object} - tabs.Tab
934
+ * @returns {Promise.<object>} - tabs.Tab
935
935
  */
936
936
  export const getTab = async tabId => {
937
937
  if (!Number.isInteger(tabId)) {
@@ -945,8 +945,8 @@ export const getTab = async tabId => {
945
945
  * highlight tab
946
946
  *
947
947
  * @param {number|Array} index - tab index
948
- * @param {number} windowId - window ID
949
- * @returns {object} - windows.Window
948
+ * @param {number} [windowId] - window ID
949
+ * @returns {Promise.<object>} - windows.Window
950
950
  */
951
951
  export const highlightTab = async (index, windowId) => {
952
952
  if (!(Array.isArray(index) || Number.isInteger(index))) {
@@ -968,7 +968,7 @@ export const highlightTab = async (index, windowId) => {
968
968
  *
969
969
  * @param {number|Array} tabId - tab ID
970
970
  * @param {object} opt - options
971
- * @returns {?Array} - array of tabs.Tab
971
+ * @returns {Promise.<?Array>} - array of tabs.Tab
972
972
  */
973
973
  export const moveTab = async (tabId, opt) => {
974
974
  if (!(Array.isArray(tabId) || Number.isInteger(tabId))) {
@@ -986,7 +986,7 @@ export const moveTab = async (tabId, opt) => {
986
986
  *
987
987
  * @param {number} tabId - tab ID
988
988
  * @param {object} opt - options
989
- * @returns {void}
989
+ * @returns {Promise.<void>} - void
990
990
  */
991
991
  export const reloadTab = async (tabId, opt) => {
992
992
  if (!Number.isInteger(tabId)) {
@@ -999,7 +999,7 @@ export const reloadTab = async (tabId, opt) => {
999
999
  * remove tab
1000
1000
  *
1001
1001
  * @param {number|Array} arg - tab ID or array of tab ID
1002
- * @returns {void}
1002
+ * @returns {Promise.<void>} - void
1003
1003
  */
1004
1004
  export const removeTab = async arg => {
1005
1005
  if (Number.isInteger(arg)) {
@@ -1016,7 +1016,7 @@ export const removeTab = async arg => {
1016
1016
  *
1017
1017
  * @param {number} tabId - tab ID
1018
1018
  * @param {object} opt - options
1019
- * @returns {object} - tabs.Tab
1019
+ * @returns {Promise.<object>} - tabs.Tab
1020
1020
  */
1021
1021
  export const updateTab = async (tabId, opt) => {
1022
1022
  if (!Number.isInteger(tabId)) {
@@ -1030,7 +1030,7 @@ export const updateTab = async (tabId, opt) => {
1030
1030
  * warmup tab
1031
1031
  *
1032
1032
  * @param {number} tabId - tab ID
1033
- * @returns {void}
1033
+ * @returns {Promise.<void>} - void
1034
1034
  */
1035
1035
  export const warmupTab = async tabId => {
1036
1036
  if (!Number.isInteger(tabId)) {
@@ -1045,7 +1045,7 @@ export const warmupTab = async tabId => {
1045
1045
  * is tab
1046
1046
  *
1047
1047
  * @param {*} tabId - tab ID
1048
- * @returns {boolean} - result
1048
+ * @returns {Promise.<boolean>} - result
1049
1049
  */
1050
1050
  export const isTab = async tabId => {
1051
1051
  if (!Number.isInteger(tabId)) {
@@ -1066,8 +1066,8 @@ export const isTab = async tabId => {
1066
1066
  /**
1067
1067
  * get current theme
1068
1068
  *
1069
- * @param {number} windowId - window ID
1070
- * @returns {object} - theme.Theme
1069
+ * @param {number} [windowId] - window ID
1070
+ * @returns {Promise.<object>} - theme.Theme
1071
1071
  */
1072
1072
  export const getCurrentTheme = async windowId => {
1073
1073
  const isGranted = await isPermissionGranted({
@@ -1087,7 +1087,7 @@ export const getCurrentTheme = async windowId => {
1087
1087
  * create new window
1088
1088
  *
1089
1089
  * @param {object} opt - options
1090
- * @returns {object} - windows.Window
1090
+ * @returns {Promise.<object>} - windows.Window
1091
1091
  */
1092
1092
  export const createNewWindow = async opt => {
1093
1093
  const win = await windows.create(isObjectNotEmpty(opt) ? opt : null);
@@ -1098,7 +1098,7 @@ export const createNewWindow = async opt => {
1098
1098
  * get all windows
1099
1099
  *
1100
1100
  * @param {boolean} populate - populate tabs
1101
- * @returns {Array} - array of windows.Window
1101
+ * @returns {Promise.<Array>} - array of windows.Window
1102
1102
  */
1103
1103
  export const getAllNormalWindows = async (populate = false) => {
1104
1104
  const arr = await windows.getAll({
@@ -1112,7 +1112,7 @@ export const getAllNormalWindows = async (populate = false) => {
1112
1112
  * get current window
1113
1113
  *
1114
1114
  * @param {object} opt - options
1115
- * @returns {object} - windows.Window
1115
+ * @returns {Promise.<object>} - windows.Window
1116
1116
  */
1117
1117
  export const getCurrentWindow = async opt => {
1118
1118
  const win = await windows.getCurrent(isObjectNotEmpty(opt) ? opt : null);
@@ -1124,7 +1124,7 @@ export const getCurrentWindow = async opt => {
1124
1124
  *
1125
1125
  * @param {number} windowId - window ID
1126
1126
  * @param {object} opt - options
1127
- * @returns {object} - windows.Window
1127
+ * @returns {Promise.<object>} - windows.Window
1128
1128
  */
1129
1129
  export const getWindow = async (windowId, opt) => {
1130
1130
  if (!Number.isInteger(windowId)) {
@@ -1137,7 +1137,7 @@ export const getWindow = async (windowId, opt) => {
1137
1137
  /**
1138
1138
  * check whether incognito window exists
1139
1139
  *
1140
- * @returns {boolean} - result
1140
+ * @returns {Promise.<boolean>} - result
1141
1141
  */
1142
1142
  export const checkIncognitoWindowExists = async () => {
1143
1143
  const arr = await getAllNormalWindows();
@@ -0,0 +1,58 @@
1
+ /**
2
+ * commander.js
3
+ */
4
+
5
+ /* api */
6
+ import path from 'node:path';
7
+ import process from 'node:process';
8
+ import { program as commander } from 'commander';
9
+ import { isDir, removeDir } from './file-util.js';
10
+ import { updateSchemas } from './update.js';
11
+
12
+ /* constants */
13
+ const DIR_CWD = process.cwd();
14
+
15
+ /**
16
+ * clean directory
17
+ *
18
+ * @param {object} cmdOpts - command options
19
+ * @returns {void}
20
+ */
21
+ export const cleanDirectory = (cmdOpts = {}) => {
22
+ const { dir, info } = cmdOpts;
23
+ if (isDir(dir)) {
24
+ removeDir(path.resolve(dir), DIR_CWD);
25
+ if (info) {
26
+ console.info(`Removed: ${path.resolve(dir)}`);
27
+ }
28
+ }
29
+ };
30
+
31
+ /**
32
+ * parse command
33
+ *
34
+ * @param {Array} args - process.argv
35
+ * @returns {void}
36
+ */
37
+ export const parseCommand = args => {
38
+ const reg = /^(?:(?:--)?help|-[h|v]|--version|c(?:lean)?|u(?:pdate)?)$/;
39
+ if (Array.isArray(args) && args.some(arg => reg.test(arg))) {
40
+ commander.exitOverride();
41
+ commander.version(process.env.npm_package_version, '-v, --version');
42
+ commander.command('clean').alias('c')
43
+ .description('clean directory')
44
+ .option('-d, --dir <name>', 'specify directory')
45
+ .option('-i, --info', 'console info')
46
+ .action(cleanDirectory);
47
+ commander.command('update').alias('u').description('update schemas')
48
+ .option('-c, --channel <name>', 'specify the release channel')
49
+ .option('-i, --info', 'console info')
50
+ .action(updateSchemas);
51
+ commander.parse(args);
52
+ }
53
+ };
54
+
55
+ /* For test */
56
+ export {
57
+ commander
58
+ };
@@ -158,7 +158,7 @@ export const removeDir = (dir, baseDir) => {
158
158
  *
159
159
  * @param {string} dir - directory path
160
160
  * @param {string} baseDir - base directory path
161
- * @returns {void}
161
+ * @returns {Promise.<void>} - void
162
162
  */
163
163
  export const removeDirectory = async (dir, baseDir) => {
164
164
  if (isDir(dir)) {
@@ -177,7 +177,7 @@ export const removeDirectory = async (dir, baseDir) => {
177
177
  *
178
178
  * @param {string} dir - directory path to create
179
179
  * @param {number} [mode] - permission
180
- * @returns {string} - directory path
180
+ * @returns {Promise.<string>} - directory path
181
181
  */
182
182
  export const createDirectory = async (dir, mode = PERM_DIR) => {
183
183
  if (!isString(dir)) {
@@ -204,7 +204,7 @@ export const createDirectory = async (dir, mode = PERM_DIR) => {
204
204
  * @param {string} [opt.encoding] - encoding
205
205
  * @param {string} [opt.flag] - flag
206
206
  * @param {number|string} [opt.mode] - file permission
207
- * @returns {string} - file path
207
+ * @returns {Promise.<string>} - file path
208
208
  */
209
209
  export const createFile = async (file, value, opt = {
210
210
  encoding: null, flag: 'w', mode: PERM_FILE
@@ -230,7 +230,7 @@ export const createFile = async (file, value, opt = {
230
230
  * @param {object} [opt] - options
231
231
  * @param {string} [opt.encoding] - encoding
232
232
  * @param {string} [opt.flag] - flag
233
- * @returns {string|Buffer} - file content
233
+ * @returns {Promise.<string|Buffer>} - file content
234
234
  */
235
235
  export const readFile = async (file, opt = { encoding: null, flag: 'r' }) => {
236
236
  if (!isFile(file)) {
package/modules/update.js CHANGED
@@ -6,7 +6,6 @@
6
6
  import path from 'node:path';
7
7
  import process from 'node:process';
8
8
  import JSON5 from 'json5';
9
- import { program as commander } from 'commander';
10
9
  import { getType, isString } from './common.js';
11
10
  import { createFile } from './file-util.js';
12
11
  import { CHAR, INDENT } from './constant.js';
@@ -20,7 +19,7 @@ export const ESR_VER = 102;
20
19
  * fetch text
21
20
  *
22
21
  * @param {string} url - URL
23
- * @returns {string} - content text
22
+ * @returns {Promise.<string>} - content text
24
23
  */
25
24
  export const fetchText = async url => {
26
25
  if (!isString(url)) {
@@ -67,7 +66,7 @@ export const getChannelUrl = channel => {
67
66
  *
68
67
  * @param {string} file - file name
69
68
  * @param {string} baseUrl - base URL
70
- * @returns {object} - schema data
69
+ * @returns {Promise.<object>} - schema data
71
70
  */
72
71
  export const getSchemaData = async (file, baseUrl) => {
73
72
  if (!isString(file)) {
@@ -88,7 +87,7 @@ export const getSchemaData = async (file, baseUrl) => {
88
87
  * get schema file list from jar manifest
89
88
  *
90
89
  * @param {string} baseUrl - base URL
91
- * @returns {Array} - schema file list
90
+ * @returns {Promise.<Array.<string>>} - schema file list
92
91
  */
93
92
  export const getFileList = async baseUrl => {
94
93
  if (!isString(baseUrl)) {
@@ -176,7 +175,7 @@ export const getMailExtSchemaData = async baseUrl => {
176
175
  * create unified schema
177
176
  *
178
177
  * @param {string} channel - release channel
179
- * @returns {object} - schema
178
+ * @returns {Promise.<object>} - schema
180
179
  */
181
180
  export const createUnifiedSchema = async channel => {
182
181
  const channelUrl = getChannelUrl(channel);
@@ -220,7 +219,7 @@ export const createUnifiedSchema = async channel => {
220
219
  *
221
220
  * @param {string} channel - release channel
222
221
  * @param {boolean} info - console info
223
- * @returns {string} - file path
222
+ * @returns {Promise.<string>} - file path
224
223
  */
225
224
  export const saveSchemaFile = async (channel, info) => {
226
225
  if (!isString(channel)) {
@@ -244,7 +243,7 @@ export const saveSchemaFile = async (channel, info) => {
244
243
  * update schemas files
245
244
  *
246
245
  * @param {object} cmdOpts - command options
247
- * @returns {void}
246
+ * @returns {Promise.<void>} - void
248
247
  */
249
248
  export const updateSchemas = async (cmdOpts = {}) => {
250
249
  const { channel, info } = cmdOpts;
@@ -268,26 +267,3 @@ export const updateSchemas = async (cmdOpts = {}) => {
268
267
  }
269
268
  }
270
269
  };
271
-
272
- /**
273
- * parse command
274
- *
275
- * @param {Array} args - process.argv
276
- * @returns {void}
277
- */
278
- export const parseCommand = args => {
279
- const reg = /^(?:(?:--)?help|-[h|v]|--version|u(?:pdate)?)$/;
280
- if (Array.isArray(args) && args.some(arg => reg.test(arg))) {
281
- commander.exitOverride();
282
- commander.version(process.env.npm_package_version, '-v, --version');
283
- commander.command('update').alias('u').description('update schemas')
284
- .option('-c, --channel <name>', 'specify the release channel')
285
- .option('-i, --info', 'console info')
286
- .action(updateSchemas);
287
- commander.parse(args);
288
- }
289
- };
290
-
291
- export {
292
- commander
293
- };
package/package.json CHANGED
@@ -13,7 +13,8 @@
13
13
  "main": "index.js",
14
14
  "types": "types/index.d.ts",
15
15
  "dependencies": {
16
- "@types/node": "^18.14.0",
16
+ "@types/firefox-webext-browser": "^109.0.0",
17
+ "@types/node": "^18.14.1",
17
18
  "@types/sinon": "^10.0.13",
18
19
  "camelize": "^1.0.1",
19
20
  "commander": "^10.0.0",
@@ -22,7 +23,7 @@
22
23
  "sinon": "^15.0.1"
23
24
  },
24
25
  "devDependencies": {
25
- "c8": "^7.12.0",
26
+ "c8": "^7.13.0",
26
27
  "chai": "^4.3.7",
27
28
  "eslint": "^8.34.0",
28
29
  "eslint-config-standard": "^17.0.0",
@@ -34,7 +35,7 @@
34
35
  "mocha": "^10.2.0",
35
36
  "npm-run-all": "^4.1.5",
36
37
  "typescript": "^4.9.5",
37
- "undici": "^5.19.1"
38
+ "undici": "^5.20.0"
38
39
  },
39
40
  "scripts": {
40
41
  "build": "npm run tsc && npm run lint && npm run test",
@@ -46,7 +47,7 @@
46
47
  "test-esr": "c8 mocha --require=test/mocha/setup.js --channel=esr --exit test/*.test.js",
47
48
  "test-release": "c8 mocha --require=test/mocha/setup.js --channel=release --exit test/*.test.js",
48
49
  "test_all": "npm-run-all -s test-*",
49
- "tsc": "node -e \"fs.rmSync('types',{recursive:true,force:true})\" && npx tsc",
50
+ "tsc": "node index clean --dir=types -i && npx tsc",
50
51
  "update": "node index update -i",
51
52
  "update-beta": "node index update --channel=beta -i",
52
53
  "update-central": "node index update --channel=central -i",
@@ -54,5 +55,5 @@
54
55
  "update-mail": "node index update --channel=mail -i",
55
56
  "update-release": "node index update --channel=release -i"
56
57
  },
57
- "version": "5.1.4"
58
+ "version": "5.1.5"
58
59
  }
package/tsconfig.json CHANGED
@@ -1,12 +1,16 @@
1
1
  {
2
- "include": ["index.js"],
3
2
  "compilerOptions": {
4
3
  "allowJs": true,
5
4
  "allowSyntheticDefaultImports": true,
6
5
  "declaration": true,
7
6
  "declarationDir": "types",
8
7
  "emitDeclarationOnly": true,
8
+ "module": "esnext",
9
+ "moduleResolution": "node",
9
10
  "newLine": "LF",
10
- "removeComments": true
11
- }
11
+ "removeComments": true,
12
+ "resolveJsonModule": true,
13
+ "target": "esnext"
14
+ },
15
+ "include": ["index.js", "modules/browser.js"]
12
16
  }
@@ -0,0 +1,59 @@
1
+ export function isPermissionGranted(perm: object): Promise<boolean>;
2
+ export function createBookmark(opt: object): Promise<object>;
3
+ export function getBookmarkTreeNode(id: string | any[]): Promise<any[] | null>;
4
+ export function getCloseTabsByDoubleClickValue(): Promise<object>;
5
+ export function setContextMenuOnMouseup(): Promise<boolean>;
6
+ export function clearContextMenuOnMouseup(): Promise<boolean>;
7
+ export function getNewTabPositionValue(): Promise<object>;
8
+ export function isCommandCustomizable(): Promise<boolean>;
9
+ export function updateCommand(id: string, value?: string): Promise<void | null>;
10
+ export function getAllContextualIdentities(): Promise<any[] | null>;
11
+ export function getContextualId(cookieStoreId: string): Promise<object>;
12
+ export function getEnabledTheme(): Promise<any[] | null>;
13
+ export function getExtensionInfo(id: string): Promise<object>;
14
+ export function getExternalExtensions(): Promise<(any[] | boolean) | null>;
15
+ export function clearNotification(id: string): Promise<boolean | null>;
16
+ export function createNotification(id: string, opt: object): Promise<string | null>;
17
+ export function removePermission(perm: string | any[]): Promise<boolean>;
18
+ export function requestPermission(perm: string | any[]): Promise<boolean>;
19
+ export function getManifestIcons(): object | string;
20
+ export function getManifestVersion(): number;
21
+ export function getOs(): Promise<string>;
22
+ export function makeConnection(id?: number | string, info?: object | boolean): Promise<object>;
23
+ export function sendMessage(id: number | string, msg: any, opt: object): Promise<object>;
24
+ export function isScriptingAvailable(): Promise<boolean>;
25
+ export function executeScriptToTab(opt?: object): Promise<(any[] | boolean) | null>;
26
+ export function searchWithSearchEngine(query: string, opt?: object): Promise<void>;
27
+ export function getRecentlyClosedTab(windowId?: number): Promise<object>;
28
+ export function getSessionWindowValue(key: string, windowId?: number): Promise<string | null>;
29
+ export function restoreSession(sessionId: string): Promise<object>;
30
+ export function setSessionWindowValue(key: string, value: string | object, windowId?: number): Promise<void>;
31
+ export function clearStorage(area?: string): Promise<void>;
32
+ export function getAllStorage(area?: string): Promise<object>;
33
+ export function getStorage(key: any, area?: string): Promise<object>;
34
+ export function removeStorage(key: any, area?: string): Promise<void>;
35
+ export function setStorage(obj: object, area?: string): Promise<void>;
36
+ export function createTab(opt?: object): Promise<object>;
37
+ export function duplicateTab(tabId: number, opt: object): Promise<object>;
38
+ export function queryTabs(opt: object): Promise<any[] | null>;
39
+ export function execScriptToTab(tabId: number | object, opt?: object): Promise<(any[] | boolean) | null>;
40
+ export function execScriptToTabs(opt?: object): Promise<any[]>;
41
+ export function execScriptsToTabInOrder(tabId: number | any[], opts?: any[]): Promise<any>;
42
+ export function getActiveTab(windowId?: number): Promise<object>;
43
+ export function getActiveTabId(windowId?: number): Promise<number | null>;
44
+ export function getAllTabsInWindow(windowId?: number): Promise<any[] | null>;
45
+ export function getHighlightedTab(windowId?: number): Promise<any[] | null>;
46
+ export function getTab(tabId: number): Promise<object>;
47
+ export function highlightTab(index: number | any[], windowId?: number): Promise<object>;
48
+ export function moveTab(tabId: number | any[], opt: object): Promise<any[] | null>;
49
+ export function reloadTab(tabId: number, opt: object): Promise<void>;
50
+ export function removeTab(arg: number | any[]): Promise<void>;
51
+ export function updateTab(tabId: number, opt: object): Promise<object>;
52
+ export function warmupTab(tabId: number): Promise<void>;
53
+ export function isTab(tabId: any): Promise<boolean>;
54
+ export function getCurrentTheme(windowId?: number): Promise<object>;
55
+ export function createNewWindow(opt: object): Promise<object>;
56
+ export function getAllNormalWindows(populate?: boolean): Promise<any[]>;
57
+ export function getCurrentWindow(opt: object): Promise<object>;
58
+ export function getWindow(windowId: number, opt: object): Promise<object>;
59
+ export function checkIncognitoWindowExists(): Promise<boolean>;
@@ -0,0 +1,4 @@
1
+ export function cleanDirectory(cmdOpts?: object): void;
2
+ export function parseCommand(args: any[]): void;
3
+ export { commander };
4
+ import { program as commander } from "commander";
@@ -8,14 +8,14 @@ export function isExecutable(file: string, mask?: number): boolean;
8
8
  export function getFileTimestamp(file: string): number;
9
9
  export function getFileNameFromFilePath(file: string, subst?: string): string;
10
10
  export function removeDir(dir: string, baseDir: string): void;
11
- export function removeDirectory(dir: string, baseDir: string): void;
12
- export function createDirectory(dir: string, mode?: number): string;
11
+ export function removeDirectory(dir: string, baseDir: string): Promise<void>;
12
+ export function createDirectory(dir: string, mode?: number): Promise<string>;
13
13
  export function createFile(file: string, value: string | Buffer | Uint8Array, opt?: {
14
14
  encoding?: string;
15
15
  flag?: string;
16
16
  mode?: number | string;
17
- }): string;
17
+ }): Promise<string>;
18
18
  export function readFile(file: string, opt?: {
19
19
  encoding?: string;
20
20
  flag?: string;
21
- }): string | Buffer;
21
+ }): Promise<string | Buffer>;
@@ -1,14 +1,11 @@
1
1
  export const ESR_VER: 102;
2
- export function fetchText(url: string): string;
2
+ export function fetchText(url: string): Promise<string>;
3
3
  export function getChannelUrl(channel: string): string;
4
- export function getSchemaData(file: string, baseUrl: string): object;
5
- export function getFileList(baseUrl: string): any[];
4
+ export function getSchemaData(file: string, baseUrl: string): Promise<object>;
5
+ export function getFileList(baseUrl: string): Promise<Array<string>>;
6
6
  export function getAllSchemaData(baseUrl: string): Promise<any[]>;
7
7
  export function getListedSchemaData(baseUrl: string, arr: any[]): Promise<any[]>;
8
8
  export function getMailExtSchemaData(baseUrl: string): Promise<any[]>;
9
- export function createUnifiedSchema(channel: string): object;
10
- export function saveSchemaFile(channel: string, info: boolean): string;
11
- export function updateSchemas(cmdOpts?: object): void;
12
- export function parseCommand(args: any[]): void;
13
- export { commander };
14
- import { program as commander } from "commander";
9
+ export function createUnifiedSchema(channel: string): Promise<object>;
10
+ export function saveSchemaFile(channel: string, info: boolean): Promise<string>;
11
+ export function updateSchemas(cmdOpts?: object): Promise<void>;