@jeniex/utils 1.0.4 → 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 +20 -11
- package/browser/index.d.ts +7 -7
- package/browser/{index.mjs → index.js} +18 -9
- package/package.json +3 -3
- /package/node/{index.mjs → index.js} +0 -0
package/browser/index.cjs
CHANGED
|
@@ -38,25 +38,34 @@ 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
|
+
}
|
|
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
|
|
53
|
+
const logId = `[${scriptName}]:`;
|
|
45
54
|
/** The initial tab URL on the script run */
|
|
46
|
-
const
|
|
55
|
+
const tabURL = window.location.href;
|
|
47
56
|
|
|
48
57
|
function alert(message) {
|
|
49
58
|
if (message === undefined) {
|
|
50
|
-
window.alert(`[ ${
|
|
59
|
+
window.alert(`[ ${scriptName} ]`);
|
|
51
60
|
return;
|
|
52
61
|
}
|
|
53
|
-
window.alert(`[ ${
|
|
62
|
+
window.alert(`[ ${scriptName} ]\n\n${message}`);
|
|
54
63
|
}
|
|
55
64
|
function confirm(message) {
|
|
56
|
-
return window.confirm(`[ ${
|
|
65
|
+
return window.confirm(`[ ${scriptName} ]\n\n${message}`);
|
|
57
66
|
}
|
|
58
67
|
function prompt(message, _default) {
|
|
59
|
-
return window.prompt(`[ ${
|
|
68
|
+
return window.prompt(`[ ${scriptName} ]\n\n${message}`, _default);
|
|
60
69
|
}
|
|
61
70
|
|
|
62
71
|
function $(selectors, parent) {
|
|
@@ -151,9 +160,6 @@ async function getOptions(flags) {
|
|
|
151
160
|
|
|
152
161
|
exports.$ = $;
|
|
153
162
|
exports.$$ = $$;
|
|
154
|
-
exports.LOG_ID = LOG_ID;
|
|
155
|
-
exports.SCRIPT_NAME = SCRIPT_NAME;
|
|
156
|
-
exports.TAB_URL = TAB_URL;
|
|
157
163
|
exports.alert = alert;
|
|
158
164
|
exports.asserted = asserted;
|
|
159
165
|
exports.confirm = confirm;
|
|
@@ -164,6 +170,9 @@ exports.isNotNullish = isNotNullish;
|
|
|
164
170
|
exports.isNullish = isNullish;
|
|
165
171
|
exports.isString = isString;
|
|
166
172
|
exports.isTruthy = isTruthy;
|
|
173
|
+
exports.logId = logId;
|
|
167
174
|
exports.noop = noop;
|
|
168
175
|
exports.prompt = prompt;
|
|
176
|
+
exports.scriptName = scriptName;
|
|
169
177
|
exports.sleep = sleep;
|
|
178
|
+
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,34 @@ 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
|
+
}
|
|
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
|
|
51
|
+
const logId = `[${scriptName}]:`;
|
|
43
52
|
/** The initial tab URL on the script run */
|
|
44
|
-
const
|
|
53
|
+
const tabURL = window.location.href;
|
|
45
54
|
|
|
46
55
|
function alert(message) {
|
|
47
56
|
if (message === undefined) {
|
|
48
|
-
window.alert(`[ ${
|
|
57
|
+
window.alert(`[ ${scriptName} ]`);
|
|
49
58
|
return;
|
|
50
59
|
}
|
|
51
|
-
window.alert(`[ ${
|
|
60
|
+
window.alert(`[ ${scriptName} ]\n\n${message}`);
|
|
52
61
|
}
|
|
53
62
|
function confirm(message) {
|
|
54
|
-
return window.confirm(`[ ${
|
|
63
|
+
return window.confirm(`[ ${scriptName} ]\n\n${message}`);
|
|
55
64
|
}
|
|
56
65
|
function prompt(message, _default) {
|
|
57
|
-
return window.prompt(`[ ${
|
|
66
|
+
return window.prompt(`[ ${scriptName} ]\n\n${message}`, _default);
|
|
58
67
|
}
|
|
59
68
|
|
|
60
69
|
function $(selectors, parent) {
|
|
@@ -147,4 +156,4 @@ async function getOptions(flags) {
|
|
|
147
156
|
return options;
|
|
148
157
|
}
|
|
149
158
|
|
|
150
|
-
export { $, $$,
|
|
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
|
+
"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.
|
|
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
|