@jeniex/utils 1.0.3 → 1.0.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/browser/index.cjs CHANGED
@@ -38,25 +38,34 @@ async function sleep(milliSeconds) {
38
38
  });
39
39
  }
40
40
 
41
- const scriptInfo = typeof GM === 'undefined' ? GM_info : GM.info;
42
- const SCRIPT_NAME = scriptInfo.script.name;
41
+ let infoObject;
42
+ if (typeof GM !== 'undefined') {
43
+ infoObject = GM.info;
44
+ }
45
+ else if (typeof GM_info === 'undefined') {
46
+ infoObject = GM_info;
47
+ }
48
+ else {
49
+ infoObject = { script: { name: document.title } };
50
+ }
51
+ const scriptName = infoObject.script.name;
43
52
  /** The identifier of the script to be used in logging */
44
- const LOG_ID = `[${SCRIPT_NAME}]:`;
53
+ const logId = `[${scriptName}]:`;
45
54
  /** The initial tab URL on the script run */
46
- const TAB_URL = window.location.href;
55
+ const tabURL = window.location.href;
47
56
 
48
57
  function alert(message) {
49
58
  if (message === undefined) {
50
- window.alert(`[ ${SCRIPT_NAME} ]`);
59
+ window.alert(`[ ${scriptName} ]`);
51
60
  return;
52
61
  }
53
- window.alert(`[ ${SCRIPT_NAME} ]\n\n${message}`);
62
+ window.alert(`[ ${scriptName} ]\n\n${message}`);
54
63
  }
55
64
  function confirm(message) {
56
- return window.confirm(`[ ${SCRIPT_NAME} ]\n\n${message}`);
65
+ return window.confirm(`[ ${scriptName} ]\n\n${message}`);
57
66
  }
58
67
  function prompt(message, _default) {
59
- return window.prompt(`[ ${SCRIPT_NAME} ]\n\n${message}`, _default);
68
+ return window.prompt(`[ ${scriptName} ]\n\n${message}`, _default);
60
69
  }
61
70
 
62
71
  function $(selectors, parent) {
@@ -81,6 +90,7 @@ function createFlagMessage(flag) {
81
90
  message += `\n\n${values.join(' | ')}`;
82
91
  }
83
92
  if (type === 'number' && flag.range !== undefined) {
93
+ message += '\n';
84
94
  const [min, max] = flag.range;
85
95
  if (min !== undefined) {
86
96
  message += `\nMinimum: ${min}`;
@@ -150,9 +160,6 @@ async function getOptions(flags) {
150
160
 
151
161
  exports.$ = $;
152
162
  exports.$$ = $$;
153
- exports.LOG_ID = LOG_ID;
154
- exports.SCRIPT_NAME = SCRIPT_NAME;
155
- exports.TAB_URL = TAB_URL;
156
163
  exports.alert = alert;
157
164
  exports.asserted = asserted;
158
165
  exports.confirm = confirm;
@@ -163,6 +170,9 @@ exports.isNotNullish = isNotNullish;
163
170
  exports.isNullish = isNullish;
164
171
  exports.isString = isString;
165
172
  exports.isTruthy = isTruthy;
173
+ exports.logId = logId;
166
174
  exports.noop = noop;
167
175
  exports.prompt = prompt;
176
+ exports.scriptName = scriptName;
168
177
  exports.sleep = sleep;
178
+ exports.tabURL = tabURL;
@@ -15,12 +15,6 @@ declare function sleep(milliSeconds: number): Promise<void>;
15
15
  type Nullable<T> = T | null | undefined;
16
16
  type Fn<T = any, U = void> = (param: T) => U;
17
17
 
18
- declare const SCRIPT_NAME: string;
19
- /** The identifier of the script to be used in logging */
20
- declare const LOG_ID: string;
21
- /** The initial tab URL on the script run */
22
- declare const TAB_URL: string;
23
-
24
18
  declare function alert(message?: string): void;
25
19
  declare function confirm(message: string): boolean;
26
20
  declare function prompt(message: string, _default?: string): string | null;
@@ -30,6 +24,12 @@ type Selectors = string[] | string;
30
24
  declare function $<T = HTMLElement>(selectors: Selectors, parent?: Parent): T;
31
25
  declare function $$<T extends Element = HTMLElement>(selectors: Selectors, parent?: Parent): NodeListOf<T>;
32
26
 
27
+ declare const scriptName: string;
28
+ /** The identifier of the script to be used in logging */
29
+ declare const logId: string;
30
+ /** The initial tab URL on the script run */
31
+ declare const tabURL: string;
32
+
33
33
  interface FlagBase {
34
34
  name: string;
35
35
  message: string;
@@ -56,4 +56,4 @@ type Options = Record<string, FlagValue>;
56
56
 
57
57
  declare function getOptions(flags: Flag[]): Promise<Options>;
58
58
 
59
- export { $, $$, Flag, Fn, LOG_ID, Nullable, SCRIPT_NAME, TAB_URL, alert, asserted, confirm, ensureJoin, getOptions, isFalsy, isNotNullish, isNullish, isString, isTruthy, noop, prompt, sleep };
59
+ export { $, $$, Flag, Fn, Nullable, alert, asserted, confirm, ensureJoin, getOptions, isFalsy, isNotNullish, isNullish, isString, isTruthy, logId, noop, prompt, scriptName, sleep, tabURL };
@@ -36,25 +36,34 @@ async function sleep(milliSeconds) {
36
36
  });
37
37
  }
38
38
 
39
- const scriptInfo = typeof GM === 'undefined' ? GM_info : GM.info;
40
- const SCRIPT_NAME = scriptInfo.script.name;
39
+ let infoObject;
40
+ if (typeof GM !== 'undefined') {
41
+ infoObject = GM.info;
42
+ }
43
+ else if (typeof GM_info === 'undefined') {
44
+ infoObject = GM_info;
45
+ }
46
+ else {
47
+ infoObject = { script: { name: document.title } };
48
+ }
49
+ const scriptName = infoObject.script.name;
41
50
  /** The identifier of the script to be used in logging */
42
- const LOG_ID = `[${SCRIPT_NAME}]:`;
51
+ const logId = `[${scriptName}]:`;
43
52
  /** The initial tab URL on the script run */
44
- const TAB_URL = window.location.href;
53
+ const tabURL = window.location.href;
45
54
 
46
55
  function alert(message) {
47
56
  if (message === undefined) {
48
- window.alert(`[ ${SCRIPT_NAME} ]`);
57
+ window.alert(`[ ${scriptName} ]`);
49
58
  return;
50
59
  }
51
- window.alert(`[ ${SCRIPT_NAME} ]\n\n${message}`);
60
+ window.alert(`[ ${scriptName} ]\n\n${message}`);
52
61
  }
53
62
  function confirm(message) {
54
- return window.confirm(`[ ${SCRIPT_NAME} ]\n\n${message}`);
63
+ return window.confirm(`[ ${scriptName} ]\n\n${message}`);
55
64
  }
56
65
  function prompt(message, _default) {
57
- return window.prompt(`[ ${SCRIPT_NAME} ]\n\n${message}`, _default);
66
+ return window.prompt(`[ ${scriptName} ]\n\n${message}`, _default);
58
67
  }
59
68
 
60
69
  function $(selectors, parent) {
@@ -79,6 +88,7 @@ function createFlagMessage(flag) {
79
88
  message += `\n\n${values.join(' | ')}`;
80
89
  }
81
90
  if (type === 'number' && flag.range !== undefined) {
91
+ message += '\n';
82
92
  const [min, max] = flag.range;
83
93
  if (min !== undefined) {
84
94
  message += `\nMinimum: ${min}`;
@@ -146,4 +156,4 @@ async function getOptions(flags) {
146
156
  return options;
147
157
  }
148
158
 
149
- export { $, $$, LOG_ID, SCRIPT_NAME, TAB_URL, alert, asserted, confirm, ensureJoin, getOptions, isFalsy, isNotNullish, isNullish, isString, isTruthy, noop, prompt, sleep };
159
+ export { $, $$, alert, asserted, confirm, ensureJoin, getOptions, isFalsy, isNotNullish, isNullish, isString, isTruthy, logId, noop, prompt, scriptName, sleep, tabURL };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jeniex/utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "author": "JenieX",
5
5
  "homepage": "https://github.com/JenieX/utils",
6
6
  "type": "module",
@@ -10,12 +10,12 @@
10
10
  "exports": {
11
11
  "./browser": {
12
12
  "types": "./browser/index.d.ts",
13
- "import": "./browser/index.mjs",
13
+ "import": "./browser/index.js",
14
14
  "require": "./browser/index.cjs"
15
15
  },
16
16
  "./node": {
17
17
  "types": "./node/index.d.ts",
18
- "import": "./node/index.mjs",
18
+ "import": "./node/index.js",
19
19
  "require": "./node/index.cjs"
20
20
  }
21
21
  },
File without changes