@jeniex/utils 1.0.4 → 1.0.6
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 +21 -11
- package/browser/index.d.ts +7 -7
- package/browser/{index.mjs → index.js} +19 -9
- package/package.json +3 -3
- /package/node/{index.mjs → index.js} +0 -0
package/browser/index.cjs
CHANGED
|
@@ -38,25 +38,35 @@ async function sleep(milliSeconds) {
|
|
|
38
38
|
});
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
let infoObject;
|
|
42
|
+
if (typeof GM !== 'undefined') {
|
|
43
|
+
infoObject = GM.info;
|
|
44
|
+
// eslint-disable-next-line unicorn/no-negated-condition
|
|
45
|
+
}
|
|
46
|
+
else if (typeof GM_info !== 'undefined') {
|
|
47
|
+
infoObject = GM_info;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
infoObject = { script: { name: document.title } };
|
|
51
|
+
}
|
|
52
|
+
const scriptName = infoObject.script.name;
|
|
43
53
|
/** The identifier of the script to be used in logging */
|
|
44
|
-
const
|
|
54
|
+
const logId = `[${scriptName}]:`;
|
|
45
55
|
/** The initial tab URL on the script run */
|
|
46
|
-
const
|
|
56
|
+
const tabURL = window.location.href;
|
|
47
57
|
|
|
48
58
|
function alert(message) {
|
|
49
59
|
if (message === undefined) {
|
|
50
|
-
window.alert(`[ ${
|
|
60
|
+
window.alert(`[ ${scriptName} ]`);
|
|
51
61
|
return;
|
|
52
62
|
}
|
|
53
|
-
window.alert(`[ ${
|
|
63
|
+
window.alert(`[ ${scriptName} ]\n\n${message}`);
|
|
54
64
|
}
|
|
55
65
|
function confirm(message) {
|
|
56
|
-
return window.confirm(`[ ${
|
|
66
|
+
return window.confirm(`[ ${scriptName} ]\n\n${message}`);
|
|
57
67
|
}
|
|
58
68
|
function prompt(message, _default) {
|
|
59
|
-
return window.prompt(`[ ${
|
|
69
|
+
return window.prompt(`[ ${scriptName} ]\n\n${message}`, _default);
|
|
60
70
|
}
|
|
61
71
|
|
|
62
72
|
function $(selectors, parent) {
|
|
@@ -151,9 +161,6 @@ async function getOptions(flags) {
|
|
|
151
161
|
|
|
152
162
|
exports.$ = $;
|
|
153
163
|
exports.$$ = $$;
|
|
154
|
-
exports.LOG_ID = LOG_ID;
|
|
155
|
-
exports.SCRIPT_NAME = SCRIPT_NAME;
|
|
156
|
-
exports.TAB_URL = TAB_URL;
|
|
157
164
|
exports.alert = alert;
|
|
158
165
|
exports.asserted = asserted;
|
|
159
166
|
exports.confirm = confirm;
|
|
@@ -164,6 +171,9 @@ exports.isNotNullish = isNotNullish;
|
|
|
164
171
|
exports.isNullish = isNullish;
|
|
165
172
|
exports.isString = isString;
|
|
166
173
|
exports.isTruthy = isTruthy;
|
|
174
|
+
exports.logId = logId;
|
|
167
175
|
exports.noop = noop;
|
|
168
176
|
exports.prompt = prompt;
|
|
177
|
+
exports.scriptName = scriptName;
|
|
169
178
|
exports.sleep = sleep;
|
|
179
|
+
exports.tabURL = tabURL;
|
package/browser/index.d.ts
CHANGED
|
@@ -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,
|
|
59
|
+
export { $, $$, Flag, Fn, Nullable, alert, asserted, confirm, ensureJoin, getOptions, isFalsy, isNotNullish, isNullish, isString, isTruthy, logId, noop, prompt, scriptName, sleep, tabURL };
|
|
@@ -36,25 +36,35 @@ async function sleep(milliSeconds) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
let infoObject;
|
|
40
|
+
if (typeof GM !== 'undefined') {
|
|
41
|
+
infoObject = GM.info;
|
|
42
|
+
// eslint-disable-next-line unicorn/no-negated-condition
|
|
43
|
+
}
|
|
44
|
+
else if (typeof GM_info !== 'undefined') {
|
|
45
|
+
infoObject = GM_info;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
infoObject = { script: { name: document.title } };
|
|
49
|
+
}
|
|
50
|
+
const scriptName = infoObject.script.name;
|
|
41
51
|
/** The identifier of the script to be used in logging */
|
|
42
|
-
const
|
|
52
|
+
const logId = `[${scriptName}]:`;
|
|
43
53
|
/** The initial tab URL on the script run */
|
|
44
|
-
const
|
|
54
|
+
const tabURL = window.location.href;
|
|
45
55
|
|
|
46
56
|
function alert(message) {
|
|
47
57
|
if (message === undefined) {
|
|
48
|
-
window.alert(`[ ${
|
|
58
|
+
window.alert(`[ ${scriptName} ]`);
|
|
49
59
|
return;
|
|
50
60
|
}
|
|
51
|
-
window.alert(`[ ${
|
|
61
|
+
window.alert(`[ ${scriptName} ]\n\n${message}`);
|
|
52
62
|
}
|
|
53
63
|
function confirm(message) {
|
|
54
|
-
return window.confirm(`[ ${
|
|
64
|
+
return window.confirm(`[ ${scriptName} ]\n\n${message}`);
|
|
55
65
|
}
|
|
56
66
|
function prompt(message, _default) {
|
|
57
|
-
return window.prompt(`[ ${
|
|
67
|
+
return window.prompt(`[ ${scriptName} ]\n\n${message}`, _default);
|
|
58
68
|
}
|
|
59
69
|
|
|
60
70
|
function $(selectors, parent) {
|
|
@@ -147,4 +157,4 @@ async function getOptions(flags) {
|
|
|
147
157
|
return options;
|
|
148
158
|
}
|
|
149
159
|
|
|
150
|
-
export { $, $$,
|
|
160
|
+
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
|
+
"version": "1.0.6",
|
|
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.
|
|
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.
|
|
18
|
+
"import": "./node/index.js",
|
|
19
19
|
"require": "./node/index.cjs"
|
|
20
20
|
}
|
|
21
21
|
},
|
|
File without changes
|