@sv443-network/userutils 8.3.2 → 8.4.0
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/CHANGELOG.md +15 -0
- package/README.md +322 -84
- package/dist/index.cjs +1548 -0
- package/dist/index.global.js +54 -27
- package/dist/index.js +48 -24
- package/dist/lib/DataStore.d.ts +0 -1
- package/dist/lib/math.d.ts +5 -0
- package/dist/lib/misc.d.ts +22 -1
- package/dist/lib/translation.d.ts +41 -8
- package/dist/lib/types.d.ts +3 -1
- package/package.json +35 -34
package/dist/index.global.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// ==UserLibrary==
|
|
9
9
|
// @name UserUtils
|
|
10
10
|
// @description Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more
|
|
11
|
-
// @version 8.
|
|
11
|
+
// @version 8.4.0
|
|
12
12
|
// @license MIT
|
|
13
13
|
// @copyright Sv443 (https://github.com/Sv443)
|
|
14
14
|
|
|
@@ -48,10 +48,7 @@ var UserUtils = (function (exports) {
|
|
|
48
48
|
}
|
|
49
49
|
return target;
|
|
50
50
|
};
|
|
51
|
-
var __publicField = (obj, key, value) =>
|
|
52
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
53
|
-
return value;
|
|
54
|
-
};
|
|
51
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
55
52
|
var __async = (__this, __arguments, generator) => {
|
|
56
53
|
return new Promise((resolve, reject) => {
|
|
57
54
|
var fulfilled = (value) => {
|
|
@@ -75,14 +72,17 @@ var UserUtils = (function (exports) {
|
|
|
75
72
|
|
|
76
73
|
// lib/math.ts
|
|
77
74
|
function clamp(value, min, max) {
|
|
75
|
+
if (typeof max !== "number") {
|
|
76
|
+
max = min;
|
|
77
|
+
min = 0;
|
|
78
|
+
}
|
|
78
79
|
return Math.max(Math.min(value, max), min);
|
|
79
80
|
}
|
|
80
81
|
function mapRange(value, range1min, range1max, range2min, range2max) {
|
|
81
|
-
if (typeof range2min === "undefined" || range2max ===
|
|
82
|
+
if (typeof range2min === "undefined" || typeof range2max === "undefined") {
|
|
82
83
|
range2max = range1max;
|
|
83
|
-
range2min = 0;
|
|
84
84
|
range1max = range1min;
|
|
85
|
-
range1min = 0;
|
|
85
|
+
range2min = range1min = 0;
|
|
86
86
|
}
|
|
87
87
|
if (Number(range1min) === 0 && Number(range2min) === 0)
|
|
88
88
|
return value * (range2max / range1max);
|
|
@@ -96,7 +96,7 @@ var UserUtils = (function (exports) {
|
|
|
96
96
|
min = 0;
|
|
97
97
|
[max] = args;
|
|
98
98
|
} else
|
|
99
|
-
throw new TypeError(`Wrong parameter(s) provided - expected
|
|
99
|
+
throw new TypeError(`Wrong parameter(s) provided - expected (number, boolean|undefined) or (number, number, boolean|undefined) but got (${args.map((a) => typeof a).join(", ")}) instead`);
|
|
100
100
|
if (typeof args[2] === "boolean")
|
|
101
101
|
enhancedEntropy = args[2];
|
|
102
102
|
else if (typeof args[1] === "boolean")
|
|
@@ -117,6 +117,14 @@ var UserUtils = (function (exports) {
|
|
|
117
117
|
} else
|
|
118
118
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
119
119
|
}
|
|
120
|
+
function digitCount(num) {
|
|
121
|
+
num = Number(!["string", "number"].includes(typeof num) ? String(num) : num);
|
|
122
|
+
if (typeof num === "number" && isNaN(num))
|
|
123
|
+
return NaN;
|
|
124
|
+
return num === 0 ? 1 : Math.floor(
|
|
125
|
+
Math.log10(Math.abs(Number(num))) + 1
|
|
126
|
+
);
|
|
127
|
+
}
|
|
120
128
|
|
|
121
129
|
// lib/array.ts
|
|
122
130
|
function randomItem(array) {
|
|
@@ -766,10 +774,10 @@ Has: ${checksum}`);
|
|
|
766
774
|
}
|
|
767
775
|
};
|
|
768
776
|
|
|
769
|
-
// node_modules/nanoevents/index.js
|
|
777
|
+
// node_modules/.pnpm/nanoevents@9.1.0/node_modules/nanoevents/index.js
|
|
770
778
|
var createNanoEvents = () => ({
|
|
771
779
|
emit(event, ...args) {
|
|
772
|
-
for (let
|
|
780
|
+
for (let callbacks = this.events[event] || [], i = 0, length = callbacks.length; i < length; i++) {
|
|
773
781
|
callbacks[i](...args);
|
|
774
782
|
}
|
|
775
783
|
},
|
|
@@ -1181,8 +1189,7 @@ Has: ${checksum}`);
|
|
|
1181
1189
|
if (interactionKeys.includes(e.key)) {
|
|
1182
1190
|
preventDefault && e.preventDefault();
|
|
1183
1191
|
stopPropagation && e.stopPropagation();
|
|
1184
|
-
} else
|
|
1185
|
-
return;
|
|
1192
|
+
} else return;
|
|
1186
1193
|
} else if (e instanceof MouseEvent) {
|
|
1187
1194
|
preventDefault && e.preventDefault();
|
|
1188
1195
|
stopPropagation && e.stopPropagation();
|
|
@@ -1308,6 +1315,18 @@ Has: ${checksum}`);
|
|
|
1308
1315
|
}
|
|
1309
1316
|
});
|
|
1310
1317
|
}
|
|
1318
|
+
function consumeGen(valGen) {
|
|
1319
|
+
return __async(this, null, function* () {
|
|
1320
|
+
return yield typeof valGen === "function" ? valGen() : valGen;
|
|
1321
|
+
});
|
|
1322
|
+
}
|
|
1323
|
+
function consumeStringGen(strGen) {
|
|
1324
|
+
return __async(this, null, function* () {
|
|
1325
|
+
return typeof strGen === "string" ? strGen : String(
|
|
1326
|
+
typeof strGen === "function" ? yield strGen() : strGen
|
|
1327
|
+
);
|
|
1328
|
+
});
|
|
1329
|
+
}
|
|
1311
1330
|
|
|
1312
1331
|
// lib/SelectorObserver.ts
|
|
1313
1332
|
var domLoaded = false;
|
|
@@ -1487,23 +1506,28 @@ Has: ${checksum}`);
|
|
|
1487
1506
|
|
|
1488
1507
|
// lib/translation.ts
|
|
1489
1508
|
var trans = {};
|
|
1490
|
-
var curLang;
|
|
1491
|
-
|
|
1509
|
+
var curLang = "";
|
|
1510
|
+
function translate(language, key, ...args) {
|
|
1492
1511
|
var _a;
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
const trText = (_a = trans[language]) == null ? void 0 : _a[key];
|
|
1496
|
-
if (!trText)
|
|
1512
|
+
const trObj = (_a = trans[language]) == null ? void 0 : _a.data;
|
|
1513
|
+
if (typeof language !== "string" || typeof trObj !== "object" || trObj === null)
|
|
1497
1514
|
return key;
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1515
|
+
const keyParts = key.split(".");
|
|
1516
|
+
let value = trObj;
|
|
1517
|
+
for (const part of keyParts) {
|
|
1518
|
+
if (typeof value !== "object" || value === null)
|
|
1519
|
+
break;
|
|
1520
|
+
value = value == null ? void 0 : value[part];
|
|
1521
|
+
}
|
|
1522
|
+
if (typeof value === "string")
|
|
1523
|
+
return insertValues(value, args);
|
|
1524
|
+
value = trObj == null ? void 0 : trObj[key];
|
|
1525
|
+
if (typeof value === "string")
|
|
1526
|
+
return insertValues(value, args);
|
|
1527
|
+
return key;
|
|
1505
1528
|
}
|
|
1506
|
-
tr
|
|
1529
|
+
var tr = (key, ...args) => translate(curLang, key, ...args);
|
|
1530
|
+
tr.forLang = translate;
|
|
1507
1531
|
tr.addLanguage = (language, translations) => {
|
|
1508
1532
|
trans[language] = translations;
|
|
1509
1533
|
};
|
|
@@ -1528,11 +1552,14 @@ Has: ${checksum}`);
|
|
|
1528
1552
|
exports.clamp = clamp;
|
|
1529
1553
|
exports.compress = compress;
|
|
1530
1554
|
exports.computeHash = computeHash;
|
|
1555
|
+
exports.consumeGen = consumeGen;
|
|
1556
|
+
exports.consumeStringGen = consumeStringGen;
|
|
1531
1557
|
exports.darkenColor = darkenColor;
|
|
1532
1558
|
exports.debounce = debounce;
|
|
1533
1559
|
exports.decompress = decompress;
|
|
1534
1560
|
exports.defaultDialogCss = defaultDialogCss;
|
|
1535
1561
|
exports.defaultStrings = defaultStrings;
|
|
1562
|
+
exports.digitCount = digitCount;
|
|
1536
1563
|
exports.fetchAdvanced = fetchAdvanced;
|
|
1537
1564
|
exports.getSiblingsFrame = getSiblingsFrame;
|
|
1538
1565
|
exports.getUnsafeWindow = getUnsafeWindow;
|
package/dist/index.js
CHANGED
|
@@ -28,10 +28,7 @@ var __objRest = (source, exclude) => {
|
|
|
28
28
|
}
|
|
29
29
|
return target;
|
|
30
30
|
};
|
|
31
|
-
var __publicField = (obj, key, value) =>
|
|
32
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
33
|
-
return value;
|
|
34
|
-
};
|
|
31
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
35
32
|
var __async = (__this, __arguments, generator) => {
|
|
36
33
|
return new Promise((resolve, reject) => {
|
|
37
34
|
var fulfilled = (value) => {
|
|
@@ -55,14 +52,17 @@ var __async = (__this, __arguments, generator) => {
|
|
|
55
52
|
|
|
56
53
|
// lib/math.ts
|
|
57
54
|
function clamp(value, min, max) {
|
|
55
|
+
if (typeof max !== "number") {
|
|
56
|
+
max = min;
|
|
57
|
+
min = 0;
|
|
58
|
+
}
|
|
58
59
|
return Math.max(Math.min(value, max), min);
|
|
59
60
|
}
|
|
60
61
|
function mapRange(value, range1min, range1max, range2min, range2max) {
|
|
61
|
-
if (typeof range2min === "undefined" || range2max ===
|
|
62
|
+
if (typeof range2min === "undefined" || typeof range2max === "undefined") {
|
|
62
63
|
range2max = range1max;
|
|
63
|
-
range2min = 0;
|
|
64
64
|
range1max = range1min;
|
|
65
|
-
range1min = 0;
|
|
65
|
+
range2min = range1min = 0;
|
|
66
66
|
}
|
|
67
67
|
if (Number(range1min) === 0 && Number(range2min) === 0)
|
|
68
68
|
return value * (range2max / range1max);
|
|
@@ -76,7 +76,7 @@ function randRange(...args) {
|
|
|
76
76
|
min = 0;
|
|
77
77
|
[max] = args;
|
|
78
78
|
} else
|
|
79
|
-
throw new TypeError(`Wrong parameter(s) provided - expected
|
|
79
|
+
throw new TypeError(`Wrong parameter(s) provided - expected (number, boolean|undefined) or (number, number, boolean|undefined) but got (${args.map((a) => typeof a).join(", ")}) instead`);
|
|
80
80
|
if (typeof args[2] === "boolean")
|
|
81
81
|
enhancedEntropy = args[2];
|
|
82
82
|
else if (typeof args[1] === "boolean")
|
|
@@ -97,6 +97,14 @@ function randRange(...args) {
|
|
|
97
97
|
} else
|
|
98
98
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
99
99
|
}
|
|
100
|
+
function digitCount(num) {
|
|
101
|
+
num = Number(!["string", "number"].includes(typeof num) ? String(num) : num);
|
|
102
|
+
if (typeof num === "number" && isNaN(num))
|
|
103
|
+
return NaN;
|
|
104
|
+
return num === 0 ? 1 : Math.floor(
|
|
105
|
+
Math.log10(Math.abs(Number(num))) + 1
|
|
106
|
+
);
|
|
107
|
+
}
|
|
100
108
|
|
|
101
109
|
// lib/array.ts
|
|
102
110
|
function randomItem(array) {
|
|
@@ -1141,8 +1149,7 @@ var Dialog = class _Dialog extends NanoEmitter {
|
|
|
1141
1149
|
if (interactionKeys.includes(e.key)) {
|
|
1142
1150
|
preventDefault && e.preventDefault();
|
|
1143
1151
|
stopPropagation && e.stopPropagation();
|
|
1144
|
-
} else
|
|
1145
|
-
return;
|
|
1152
|
+
} else return;
|
|
1146
1153
|
} else if (e instanceof MouseEvent) {
|
|
1147
1154
|
preventDefault && e.preventDefault();
|
|
1148
1155
|
stopPropagation && e.stopPropagation();
|
|
@@ -1268,6 +1275,18 @@ function fetchAdvanced(_0) {
|
|
|
1268
1275
|
}
|
|
1269
1276
|
});
|
|
1270
1277
|
}
|
|
1278
|
+
function consumeGen(valGen) {
|
|
1279
|
+
return __async(this, null, function* () {
|
|
1280
|
+
return yield typeof valGen === "function" ? valGen() : valGen;
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
function consumeStringGen(strGen) {
|
|
1284
|
+
return __async(this, null, function* () {
|
|
1285
|
+
return typeof strGen === "string" ? strGen : String(
|
|
1286
|
+
typeof strGen === "function" ? yield strGen() : strGen
|
|
1287
|
+
);
|
|
1288
|
+
});
|
|
1289
|
+
}
|
|
1271
1290
|
|
|
1272
1291
|
// lib/SelectorObserver.ts
|
|
1273
1292
|
var domLoaded = false;
|
|
@@ -1447,23 +1466,28 @@ var SelectorObserver = class {
|
|
|
1447
1466
|
|
|
1448
1467
|
// lib/translation.ts
|
|
1449
1468
|
var trans = {};
|
|
1450
|
-
var curLang;
|
|
1451
|
-
|
|
1469
|
+
var curLang = "";
|
|
1470
|
+
function translate(language, key, ...args) {
|
|
1452
1471
|
var _a;
|
|
1453
|
-
|
|
1472
|
+
const trObj = (_a = trans[language]) == null ? void 0 : _a.data;
|
|
1473
|
+
if (typeof language !== "string" || typeof trObj !== "object" || trObj === null)
|
|
1454
1474
|
return key;
|
|
1455
|
-
const
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1475
|
+
const keyParts = key.split(".");
|
|
1476
|
+
let value = trObj;
|
|
1477
|
+
for (const part of keyParts) {
|
|
1478
|
+
if (typeof value !== "object" || value === null)
|
|
1479
|
+
break;
|
|
1480
|
+
value = value == null ? void 0 : value[part];
|
|
1460
1481
|
}
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1482
|
+
if (typeof value === "string")
|
|
1483
|
+
return insertValues(value, args);
|
|
1484
|
+
value = trObj == null ? void 0 : trObj[key];
|
|
1485
|
+
if (typeof value === "string")
|
|
1486
|
+
return insertValues(value, args);
|
|
1487
|
+
return key;
|
|
1465
1488
|
}
|
|
1466
|
-
tr
|
|
1489
|
+
var tr = (key, ...args) => translate(curLang, key, ...args);
|
|
1490
|
+
tr.forLang = translate;
|
|
1467
1491
|
tr.addLanguage = (language, translations) => {
|
|
1468
1492
|
trans[language] = translations;
|
|
1469
1493
|
};
|
|
@@ -1477,4 +1501,4 @@ tr.getTranslations = (language) => {
|
|
|
1477
1501
|
return trans[language != null ? language : curLang];
|
|
1478
1502
|
};
|
|
1479
1503
|
|
|
1480
|
-
export { DataStore, DataStoreSerializer, Dialog, NanoEmitter, SelectorObserver, addGlobalStyle, addParent, autoPlural, clamp, compress, computeHash, currentDialogId, darkenColor, debounce, decompress, defaultDialogCss, defaultStrings, fetchAdvanced, getSiblingsFrame, getUnsafeWindow, hexToRgb, insertValues, interceptEvent, interceptWindowEvent, isScrollable, lightenColor, mapRange, observeElementProp, openDialogs, openInNewTab, pauseFor, preloadImages, randRange, randomId, randomItem, randomItemIndex, randomizeArray, rgbToHex, setInnerHtmlUnsafe, takeRandomItem, tr };
|
|
1504
|
+
export { DataStore, DataStoreSerializer, Dialog, NanoEmitter, SelectorObserver, addGlobalStyle, addParent, autoPlural, clamp, compress, computeHash, consumeGen, consumeStringGen, currentDialogId, darkenColor, debounce, decompress, defaultDialogCss, defaultStrings, digitCount, fetchAdvanced, getSiblingsFrame, getUnsafeWindow, hexToRgb, insertValues, interceptEvent, interceptWindowEvent, isScrollable, lightenColor, mapRange, observeElementProp, openDialogs, openInNewTab, pauseFor, preloadImages, randRange, randomId, randomItem, randomItemIndex, randomizeArray, rgbToHex, setInnerHtmlUnsafe, takeRandomItem, tr };
|
package/dist/lib/DataStore.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="greasemonkey" />
|
|
2
1
|
import type { Prettify } from "./types.js";
|
|
3
2
|
/** Function that takes the data in the old format and returns the data in the new format. Also supports an asynchronous migration. */
|
|
4
3
|
type MigrationFunc = (oldData: any) => any | Promise<any>;
|
package/dist/lib/math.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import type { Stringifiable } from "./types.js";
|
|
1
2
|
/** Ensures the passed {@linkcode value} always stays between {@linkcode min} and {@linkcode max} */
|
|
2
3
|
export declare function clamp(value: number, min: number, max: number): number;
|
|
4
|
+
/** Ensures the passed {@linkcode value} always stays between 0 and {@linkcode max} */
|
|
5
|
+
export declare function clamp(value: number, max: number): number;
|
|
3
6
|
/**
|
|
4
7
|
* Transforms the value parameter from the numerical range `range1min` to `range1max` to the numerical range `range2min` to `range2max`
|
|
5
8
|
* For example, you can map the value 2 in the range of 0-5 to the range of 0-10 and you'd get a 4 as a result.
|
|
@@ -20,3 +23,5 @@ export declare function randRange(min: number, max: number, enhancedEntropy?: bo
|
|
|
20
23
|
* Set {@linkcode enhancedEntropy} to true to use `crypto.getRandomValues()` for better cryptographic randomness (this also makes it take longer to generate)
|
|
21
24
|
*/
|
|
22
25
|
export declare function randRange(max: number, enhancedEntropy?: boolean): number;
|
|
26
|
+
/** Calculates the amount of digits in the given number - the given number or string will be passed to the `Number()` constructor. Returns NaN if the number is invalid. */
|
|
27
|
+
export declare function digitCount(num: number | Stringifiable): number;
|
package/dist/lib/misc.d.ts
CHANGED
|
@@ -29,4 +29,25 @@ export type FetchAdvancedOpts = Prettify<Partial<{
|
|
|
29
29
|
timeout: number;
|
|
30
30
|
}> & RequestInit>;
|
|
31
31
|
/** Calls the fetch API with special options like a timeout */
|
|
32
|
-
export declare function fetchAdvanced(input: RequestInfo | URL, options?: FetchAdvancedOpts): Promise<Response>;
|
|
32
|
+
export declare function fetchAdvanced(input: string | RequestInfo | URL, options?: FetchAdvancedOpts): Promise<Response>;
|
|
33
|
+
/**
|
|
34
|
+
* A ValueGen value is either its type, a promise that resolves to its type, or a function that returns its type, either synchronous or asynchronous.
|
|
35
|
+
* ValueGen allows for the utmost flexibility when applied to any type, as long as {@linkcode consumeGen()} is used to get the final value.
|
|
36
|
+
* @template TValueType The type of the value that the ValueGen should yield
|
|
37
|
+
*/
|
|
38
|
+
export type ValueGen<TValueType> = TValueType | Promise<TValueType> | (() => TValueType | Promise<TValueType>);
|
|
39
|
+
/**
|
|
40
|
+
* Turns a {@linkcode ValueGen} into its final value.
|
|
41
|
+
* @template TValueType The type of the value that the ValueGen should yield
|
|
42
|
+
*/
|
|
43
|
+
export declare function consumeGen<TValueType>(valGen: ValueGen<TValueType>): Promise<TValueType>;
|
|
44
|
+
/**
|
|
45
|
+
* A StringGen value is either a string, anything that can be converted to a string, or a function that returns one of the previous two, either synchronous or asynchronous, or a promise that returns a string.
|
|
46
|
+
* StringGen allows for the utmost flexibility when dealing with strings, as long as {@linkcode consumeStringGen()} is used to get the final string.
|
|
47
|
+
*/
|
|
48
|
+
export type StringGen = ValueGen<Stringifiable>;
|
|
49
|
+
/**
|
|
50
|
+
* Turns a {@linkcode StringGen} into its final string value.
|
|
51
|
+
* @template TStrUnion The union of strings that the StringGen should yield - this allows for finer type control compared to {@linkcode consumeGen()}
|
|
52
|
+
*/
|
|
53
|
+
export declare function consumeStringGen<TStrUnion extends string>(strGen: StringGen): Promise<TStrUnion>;
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
import type { Stringifiable } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Translation object to pass to {@linkcode tr.addLanguage()}
|
|
4
|
+
* Can be a flat object of identifier keys and the translation text as the value, or an infinitely nestable object containing the same.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* // Flat object:
|
|
8
|
+
* const tr_en: TrObject = {
|
|
9
|
+
* hello: "Hello, %1!",
|
|
10
|
+
* foo: "Foo",
|
|
11
|
+
* };
|
|
12
|
+
*
|
|
13
|
+
* // Nested object:
|
|
14
|
+
* const tr_de: TrObject = {
|
|
15
|
+
* hello: "Hallo, %1!",
|
|
16
|
+
* foo: {
|
|
17
|
+
* bar: "Foo bar",
|
|
18
|
+
* },
|
|
19
|
+
* };
|
|
20
|
+
*/
|
|
21
|
+
export interface TrObject {
|
|
22
|
+
[key: string]: string | TrObject;
|
|
23
|
+
}
|
|
24
|
+
/** Common function to resolve the translation text in a specific language. */
|
|
25
|
+
declare function translate(language: string, key: string, ...args: Stringifiable[]): string;
|
|
2
26
|
/**
|
|
3
27
|
* Returns the translated text for the specified key in the current language set by {@linkcode tr.setLanguage()}
|
|
4
28
|
* Use {@linkcode tr.forLang()} to get the translation for a specific language instead of the currently set one.
|
|
@@ -8,12 +32,21 @@ import type { Stringifiable } from "./types.js";
|
|
|
8
32
|
* @param key Key of the translation to return
|
|
9
33
|
* @param args Optional arguments to be passed to the translated text. They will replace placeholders in the format `%n`, where `n` is the 1-indexed argument number
|
|
10
34
|
*/
|
|
11
|
-
declare
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
35
|
+
declare const tr: {
|
|
36
|
+
(key: string, ...args: Stringifiable[]): string;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the translated text for the specified key in the specified language.
|
|
39
|
+
* If the key is not found in the specified previously registered translation, the key itself is returned.
|
|
40
|
+
*
|
|
41
|
+
* ⚠️ Remember to register a language with {@linkcode tr.addLanguage()} before using this function, otherwise it will always return the key itself.
|
|
42
|
+
* @param language Language to use for the translation
|
|
43
|
+
* @param key Key of the translation to return
|
|
44
|
+
* @param args Optional arguments to be passed to the translated text. They will replace placeholders in the format `%n`, where `n` is the 1-indexed argument number
|
|
45
|
+
*/
|
|
46
|
+
forLang: typeof translate;
|
|
47
|
+
addLanguage(language: string, translations: TrObject): void;
|
|
48
|
+
setLanguage(language: string): void;
|
|
49
|
+
getLanguage(): string;
|
|
50
|
+
getTranslations(language?: string): TrObject | undefined;
|
|
51
|
+
};
|
|
19
52
|
export { tr };
|
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
/** Represents any value that is either a string itself or can be converted to one (implicitly and explicitly) because it has a toString() method */
|
|
2
2
|
export type Stringifiable = string | {
|
|
3
3
|
toString(): string;
|
|
4
|
-
}
|
|
4
|
+
} | {
|
|
5
|
+
[Symbol.toStringTag]: string;
|
|
6
|
+
} | number | boolean | null | undefined;
|
|
5
7
|
/**
|
|
6
8
|
* A type that offers autocomplete for the passed union but also allows any arbitrary value of the same type to be passed.
|
|
7
9
|
* Supports unions of strings, numbers and objects.
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/userutils",
|
|
3
3
|
"libName": "UserUtils",
|
|
4
|
-
"version": "8.
|
|
4
|
+
"version": "8.4.0",
|
|
5
5
|
"description": "Library with various utilities for userscripts - register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and more",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -15,24 +15,6 @@
|
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"type": "module",
|
|
18
|
-
"scripts": {
|
|
19
|
-
"lint": "tsc --noEmit && eslint .",
|
|
20
|
-
"build-types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
21
|
-
"build-common": "tsup lib/index.ts --format cjs,esm --clean --treeshake",
|
|
22
|
-
"build-all": "tsup lib/index.ts --format cjs,esm,iife --treeshake --onSuccess \"npm run build-types && npm run post-build-global && echo Finished building.\"",
|
|
23
|
-
"build": "npm run build-common -- && npm run build-types",
|
|
24
|
-
"post-build-global": "npm run node-ts -- ./tools/post-build-global.mts",
|
|
25
|
-
"dev": "npm run build-common -- --sourcemap --watch --onSuccess \"npm run build-types && echo Finished building.\"",
|
|
26
|
-
"dev-all": "npm run build-all -- --watch",
|
|
27
|
-
"update-jsr-version": "npm run node-ts -- ./tools/update-jsr-version.mts",
|
|
28
|
-
"publish-package": "changeset publish",
|
|
29
|
-
"publish-package-jsr": "npm run update-jsr-version && npx jsr publish --allow-dirty",
|
|
30
|
-
"change": "changeset",
|
|
31
|
-
"node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm",
|
|
32
|
-
"test-serve": "npm run node-ts -- ./test/TestPage/server.mts",
|
|
33
|
-
"test-dev": "cd test/TestScript && npm run dev",
|
|
34
|
-
"test": "concurrently \"npm run test-serve\" \"npm run test-dev\""
|
|
35
|
-
},
|
|
36
18
|
"repository": {
|
|
37
19
|
"type": "git",
|
|
38
20
|
"url": "git+https://github.com/Sv443-Network/UserUtils.git"
|
|
@@ -51,25 +33,26 @@
|
|
|
51
33
|
},
|
|
52
34
|
"homepage": "https://github.com/Sv443-Network/UserUtils",
|
|
53
35
|
"dependencies": {
|
|
54
|
-
"nanoevents": "^9.
|
|
36
|
+
"nanoevents": "^9.1.0"
|
|
55
37
|
},
|
|
56
38
|
"devDependencies": {
|
|
57
|
-
"@changesets/cli": "^2.
|
|
58
|
-
"@types/express": "^4.17.
|
|
59
|
-
"@types/greasemonkey": "^4.0.
|
|
60
|
-
"@types/node": "^20.
|
|
61
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
62
|
-
"@typescript-eslint/parser": "^6.
|
|
63
|
-
"concurrently": "^8.2.
|
|
64
|
-
"eslint": "^8.
|
|
65
|
-
"express": "^4.
|
|
66
|
-
"ts-node": "^10.9.
|
|
67
|
-
"tslib": "^2.
|
|
68
|
-
"tsup": "^
|
|
69
|
-
"typescript": "^5.
|
|
39
|
+
"@changesets/cli": "^2.27.11",
|
|
40
|
+
"@types/express": "^4.17.21",
|
|
41
|
+
"@types/greasemonkey": "^4.0.7",
|
|
42
|
+
"@types/node": "^20.17.10",
|
|
43
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
44
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
45
|
+
"concurrently": "^8.2.2",
|
|
46
|
+
"eslint": "^8.57.1",
|
|
47
|
+
"express": "^4.21.2",
|
|
48
|
+
"ts-node": "^10.9.2",
|
|
49
|
+
"tslib": "^2.8.1",
|
|
50
|
+
"tsup": "^8.3.5",
|
|
51
|
+
"typescript": "^5.7.2"
|
|
70
52
|
},
|
|
71
53
|
"files": [
|
|
72
54
|
"/dist/index.js",
|
|
55
|
+
"/dist/index.cjs",
|
|
73
56
|
"/dist/index.mjs",
|
|
74
57
|
"/dist/index.global.js",
|
|
75
58
|
"/dist/lib/**.d.ts",
|
|
@@ -77,5 +60,23 @@
|
|
|
77
60
|
"/README.md",
|
|
78
61
|
"/CHANGELOG.md",
|
|
79
62
|
"/LICENSE.txt"
|
|
80
|
-
]
|
|
63
|
+
],
|
|
64
|
+
"scripts": {
|
|
65
|
+
"lint": "eslint . && tsc --noEmit",
|
|
66
|
+
"build-types": "tsc --emitDeclarationOnly --declaration --outDir dist",
|
|
67
|
+
"build-common": "tsup lib/index.ts --format cjs,esm --clean --treeshake",
|
|
68
|
+
"build-all": "tsup lib/index.ts --format cjs,esm,iife --treeshake --onSuccess \"npm run build-types && npm run post-build-global && echo Finished building.\"",
|
|
69
|
+
"build": "npm run build-common -- && npm run build-types",
|
|
70
|
+
"post-build-global": "npm run node-ts -- ./tools/post-build-global.mts",
|
|
71
|
+
"dev": "npm run build-common -- --sourcemap --watch --onSuccess \"npm run build-types && echo Finished building.\"",
|
|
72
|
+
"dev-all": "npm run build-all -- --watch",
|
|
73
|
+
"update-jsr-version": "npm run node-ts -- ./tools/update-jsr-version.mts",
|
|
74
|
+
"publish-package": "changeset publish",
|
|
75
|
+
"publish-package-jsr": "npm run update-jsr-version && npx jsr publish --allow-dirty",
|
|
76
|
+
"change": "changeset",
|
|
77
|
+
"node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm",
|
|
78
|
+
"test-serve": "npm run node-ts -- ./test/TestPage/server.mts",
|
|
79
|
+
"test-dev": "cd test/TestScript && npm run dev",
|
|
80
|
+
"test": "concurrently \"npm run test-serve\" \"npm run test-dev\""
|
|
81
|
+
}
|
|
81
82
|
}
|