@sv443-network/userutils 9.2.0 → 9.3.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 +14 -1
- package/README-summary.md +2 -1
- package/README.md +2 -1
- package/dist/index.cjs +31 -7
- package/dist/index.global.js +32 -8
- package/dist/index.js +31 -8
- package/dist/lib/DataStoreSerializer.d.ts +32 -6
- package/dist/lib/misc.d.ts +6 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @sv443-network/userutils
|
|
2
2
|
|
|
3
|
+
## 9.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 89d7970: Added `DataStoreSerializer` methods `serializePartial()` and `deserializePartial()` for partial data exports and imports
|
|
8
|
+
- 5d71770: Added function `purifyObj()` to remove an object's prototype chain (i.e. omit all inherited properties like `toString`, `__proto__`, etc.)
|
|
9
|
+
|
|
10
|
+
## 9.2.1
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 24dad2b: Fixed TS type for `DataStoreSerializer.serialize()`
|
|
15
|
+
|
|
3
16
|
## 9.2.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -11,7 +24,7 @@
|
|
|
11
24
|
- 905fea4: Added function `onDomLoad()` to call a callback and/or resolve a Promise when the DOM is loaded, even retroactively
|
|
12
25
|
- 4264154: Added function `bitSetHas()` to check if a given value is present in a [bitset](https://www.geeksforgeeks.org/cpp-bitset-and-its-application/)
|
|
13
26
|
- bf55335: Replaced a bunch of generic `Error`s with the new custom error class instances
|
|
14
|
-
- bf55335: Added custom error classes `ChecksumMismatchError`, `
|
|
27
|
+
- bf55335: Added custom error classes `ChecksumMismatchError`, `MigrationError` and `PlatformError`, extending from the base class `UUError`
|
|
15
28
|
The base class has the additional property `date` which is the time of the error creation
|
|
16
29
|
|
|
17
30
|
### Patch Changes
|
package/README-summary.md
CHANGED
|
@@ -74,6 +74,7 @@ View the documentation of previous major releases:
|
|
|
74
74
|
- [`consumeGen()`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#consumegen) - consumes a ValueGen and returns the value
|
|
75
75
|
- [`consumeStringGen()`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#consumestringgen) - consumes a StringGen and returns the string
|
|
76
76
|
- [`getListLength()`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#getlistlength) - get the length of any object with a numeric `length`, `count` or `size` property
|
|
77
|
+
- [`purifyObj()`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#purifyobj) - removes the prototype chain (all default properties like `toString`, `__proto__`, etc.) from an object
|
|
77
78
|
- **Arrays:**
|
|
78
79
|
- [`randomItem()`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#randomitem) - returns a random item from an array
|
|
79
80
|
- [`randomItemIndex()`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#randomitemindex) - returns a tuple of a random item and its index from an array
|
|
@@ -109,7 +110,7 @@ View the documentation of previous major releases:
|
|
|
109
110
|
- **Custom Error classes:**
|
|
110
111
|
- [`UUError`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#uuerror) - base class for all custom UserUtils errors - has a custom `date` prop set to the time of creation
|
|
111
112
|
- [`ChecksumMismatchError`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#checksummismatcherror) - thrown when a string of data doesn't match its checksum
|
|
112
|
-
- [`
|
|
113
|
+
- [`MigrationError`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#migrationerror) - thrown when a data migration fails
|
|
113
114
|
- [`PlatformError`](https://github.com/Sv443-Network/UserUtils/blob/main/docs.md#platformerror) - thrown when a function is called in an unsupported environment
|
|
114
115
|
|
|
115
116
|
<br><br>
|
package/README.md
CHANGED
|
@@ -77,6 +77,7 @@ View the documentation of previous major releases:
|
|
|
77
77
|
- [`consumeGen()`](./docs.md#consumegen) - consumes a ValueGen and returns the value
|
|
78
78
|
- [`consumeStringGen()`](./docs.md#consumestringgen) - consumes a StringGen and returns the string
|
|
79
79
|
- [`getListLength()`](./docs.md#getlistlength) - get the length of any object with a numeric `length`, `count` or `size` property
|
|
80
|
+
- [`purifyObj()`](./docs.md#purifyobj) - removes the prototype chain (all default properties like `toString`, `__proto__`, etc.) from an object
|
|
80
81
|
- [**Arrays:**](./docs.md#arrays)
|
|
81
82
|
- [`randomItem()`](./docs.md#randomitem) - returns a random item from an array
|
|
82
83
|
- [`randomItemIndex()`](./docs.md#randomitemindex) - returns a tuple of a random item and its index from an array
|
|
@@ -112,7 +113,7 @@ View the documentation of previous major releases:
|
|
|
112
113
|
- [**Custom Error classes**](./docs.md#error-classes)
|
|
113
114
|
- [`UUError`](./docs.md#uuerror) - base class for all custom UserUtils errors - has a custom `date` prop set to the time of creation
|
|
114
115
|
- [`ChecksumMismatchError`](./docs.md#checksummismatcherror) - thrown when a string of data doesn't match its checksum
|
|
115
|
-
- [`
|
|
116
|
+
- [`MigrationError`](./docs.md#migrationerror) - thrown when a data migration fails
|
|
116
117
|
- [`PlatformError`](./docs.md#platformerror) - thrown when a function is called in an unsupported environment
|
|
117
118
|
|
|
118
119
|
<br><br>
|
package/dist/index.cjs
CHANGED
|
@@ -747,14 +747,15 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
747
747
|
});
|
|
748
748
|
}
|
|
749
749
|
/**
|
|
750
|
-
* Serializes the data stores into a string.
|
|
750
|
+
* Serializes only a subset of the data stores into a string.
|
|
751
|
+
* @param stores An array of store IDs or functions that take a store ID and return a boolean
|
|
751
752
|
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
752
753
|
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
753
754
|
*/
|
|
754
|
-
|
|
755
|
+
serializePartial(stores, useEncoding = true, stringified = true) {
|
|
755
756
|
return __async(this, null, function* () {
|
|
756
757
|
const serData = [];
|
|
757
|
-
for (const storeInst of this.stores) {
|
|
758
|
+
for (const storeInst of this.stores.filter((s) => typeof stores === "function" ? stores(s.id) : stores.includes(s.id))) {
|
|
758
759
|
const data = useEncoding && storeInst.encodingEnabled() ? yield storeInst.encodeData(JSON.stringify(storeInst.getData())) : JSON.stringify(storeInst.getData());
|
|
759
760
|
serData.push({
|
|
760
761
|
id: storeInst.id,
|
|
@@ -768,15 +769,25 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
768
769
|
});
|
|
769
770
|
}
|
|
770
771
|
/**
|
|
771
|
-
*
|
|
772
|
+
* Serializes the data stores into a string.
|
|
773
|
+
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
774
|
+
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
775
|
+
*/
|
|
776
|
+
serialize(useEncoding = true, stringified = true) {
|
|
777
|
+
return __async(this, null, function* () {
|
|
778
|
+
return this.serializePartial(this.stores.map((s) => s.id), useEncoding, stringified);
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
/**
|
|
782
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports only a subset into the DataStore instances.
|
|
772
783
|
* Also triggers the migration process if the data format has changed.
|
|
773
784
|
*/
|
|
774
|
-
|
|
785
|
+
deserializePartial(stores, data) {
|
|
775
786
|
return __async(this, null, function* () {
|
|
776
|
-
const deserStores = typeof
|
|
787
|
+
const deserStores = typeof data === "string" ? JSON.parse(data) : data;
|
|
777
788
|
if (!Array.isArray(deserStores) || !deserStores.every(_DataStoreSerializer.isSerializedDataStore))
|
|
778
789
|
throw new TypeError("Invalid serialized data format! Expected an array of SerializedDataStore objects.");
|
|
779
|
-
for (const storeData of deserStores) {
|
|
790
|
+
for (const storeData of deserStores.filter((s) => typeof stores === "function" ? stores(s.id) : stores.includes(s.id))) {
|
|
780
791
|
const storeInst = this.stores.find((s) => s.id === storeData.id);
|
|
781
792
|
if (!storeInst)
|
|
782
793
|
throw new Error(`DataStore instance with ID "${storeData.id}" not found! Make sure to provide it in the DataStoreSerializer constructor.`);
|
|
@@ -795,6 +806,15 @@ Has: ${checksum}`);
|
|
|
795
806
|
}
|
|
796
807
|
});
|
|
797
808
|
}
|
|
809
|
+
/**
|
|
810
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports the data into all matching DataStore instances.
|
|
811
|
+
* Also triggers the migration process if the data format has changed.
|
|
812
|
+
*/
|
|
813
|
+
deserialize(data) {
|
|
814
|
+
return __async(this, null, function* () {
|
|
815
|
+
return this.deserializePartial(this.stores.map((s) => s.id), data);
|
|
816
|
+
});
|
|
817
|
+
}
|
|
798
818
|
/**
|
|
799
819
|
* Loads the persistent data of the DataStore instances into the in-memory cache.
|
|
800
820
|
* Also triggers the migration process if the data format has changed.
|
|
@@ -1472,6 +1492,9 @@ function consumeStringGen(strGen) {
|
|
|
1472
1492
|
function getListLength(obj, zeroOnInvalid = true) {
|
|
1473
1493
|
return "length" in obj ? obj.length : "size" in obj ? obj.size : "count" in obj ? obj.count : zeroOnInvalid ? 0 : NaN;
|
|
1474
1494
|
}
|
|
1495
|
+
function purifyObj(obj) {
|
|
1496
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), obj);
|
|
1497
|
+
}
|
|
1475
1498
|
|
|
1476
1499
|
// lib/SelectorObserver.ts
|
|
1477
1500
|
var SelectorObserver = class {
|
|
@@ -1853,6 +1876,7 @@ exports.openInNewTab = openInNewTab;
|
|
|
1853
1876
|
exports.pauseFor = pauseFor;
|
|
1854
1877
|
exports.preloadImages = preloadImages;
|
|
1855
1878
|
exports.probeElementStyle = probeElementStyle;
|
|
1879
|
+
exports.purifyObj = purifyObj;
|
|
1856
1880
|
exports.randRange = randRange;
|
|
1857
1881
|
exports.randomId = randomId;
|
|
1858
1882
|
exports.randomItem = randomItem;
|
package/dist/index.global.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// ==UserLibrary==
|
|
9
9
|
// @name UserUtils
|
|
10
10
|
// @description General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more
|
|
11
|
-
// @version 9.
|
|
11
|
+
// @version 9.3.0
|
|
12
12
|
// @license MIT
|
|
13
13
|
// @copyright Sv443 (https://github.com/Sv443)
|
|
14
14
|
|
|
@@ -765,14 +765,15 @@ var UserUtils = (function (exports) {
|
|
|
765
765
|
});
|
|
766
766
|
}
|
|
767
767
|
/**
|
|
768
|
-
* Serializes the data stores into a string.
|
|
768
|
+
* Serializes only a subset of the data stores into a string.
|
|
769
|
+
* @param stores An array of store IDs or functions that take a store ID and return a boolean
|
|
769
770
|
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
770
771
|
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
771
772
|
*/
|
|
772
|
-
|
|
773
|
+
serializePartial(stores, useEncoding = true, stringified = true) {
|
|
773
774
|
return __async(this, null, function* () {
|
|
774
775
|
const serData = [];
|
|
775
|
-
for (const storeInst of this.stores) {
|
|
776
|
+
for (const storeInst of this.stores.filter((s) => typeof stores === "function" ? stores(s.id) : stores.includes(s.id))) {
|
|
776
777
|
const data = useEncoding && storeInst.encodingEnabled() ? yield storeInst.encodeData(JSON.stringify(storeInst.getData())) : JSON.stringify(storeInst.getData());
|
|
777
778
|
serData.push({
|
|
778
779
|
id: storeInst.id,
|
|
@@ -786,15 +787,25 @@ var UserUtils = (function (exports) {
|
|
|
786
787
|
});
|
|
787
788
|
}
|
|
788
789
|
/**
|
|
789
|
-
*
|
|
790
|
+
* Serializes the data stores into a string.
|
|
791
|
+
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
792
|
+
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
793
|
+
*/
|
|
794
|
+
serialize(useEncoding = true, stringified = true) {
|
|
795
|
+
return __async(this, null, function* () {
|
|
796
|
+
return this.serializePartial(this.stores.map((s) => s.id), useEncoding, stringified);
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
/**
|
|
800
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports only a subset into the DataStore instances.
|
|
790
801
|
* Also triggers the migration process if the data format has changed.
|
|
791
802
|
*/
|
|
792
|
-
|
|
803
|
+
deserializePartial(stores, data) {
|
|
793
804
|
return __async(this, null, function* () {
|
|
794
|
-
const deserStores = typeof
|
|
805
|
+
const deserStores = typeof data === "string" ? JSON.parse(data) : data;
|
|
795
806
|
if (!Array.isArray(deserStores) || !deserStores.every(_DataStoreSerializer.isSerializedDataStore))
|
|
796
807
|
throw new TypeError("Invalid serialized data format! Expected an array of SerializedDataStore objects.");
|
|
797
|
-
for (const storeData of deserStores) {
|
|
808
|
+
for (const storeData of deserStores.filter((s) => typeof stores === "function" ? stores(s.id) : stores.includes(s.id))) {
|
|
798
809
|
const storeInst = this.stores.find((s) => s.id === storeData.id);
|
|
799
810
|
if (!storeInst)
|
|
800
811
|
throw new Error(`DataStore instance with ID "${storeData.id}" not found! Make sure to provide it in the DataStoreSerializer constructor.`);
|
|
@@ -813,6 +824,15 @@ Has: ${checksum}`);
|
|
|
813
824
|
}
|
|
814
825
|
});
|
|
815
826
|
}
|
|
827
|
+
/**
|
|
828
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports the data into all matching DataStore instances.
|
|
829
|
+
* Also triggers the migration process if the data format has changed.
|
|
830
|
+
*/
|
|
831
|
+
deserialize(data) {
|
|
832
|
+
return __async(this, null, function* () {
|
|
833
|
+
return this.deserializePartial(this.stores.map((s) => s.id), data);
|
|
834
|
+
});
|
|
835
|
+
}
|
|
816
836
|
/**
|
|
817
837
|
* Loads the persistent data of the DataStore instances into the in-memory cache.
|
|
818
838
|
* Also triggers the migration process if the data format has changed.
|
|
@@ -1510,6 +1530,9 @@ Has: ${checksum}`);
|
|
|
1510
1530
|
function getListLength(obj, zeroOnInvalid = true) {
|
|
1511
1531
|
return "length" in obj ? obj.length : "size" in obj ? obj.size : "count" in obj ? obj.count : zeroOnInvalid ? 0 : NaN;
|
|
1512
1532
|
}
|
|
1533
|
+
function purifyObj(obj) {
|
|
1534
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), obj);
|
|
1535
|
+
}
|
|
1513
1536
|
|
|
1514
1537
|
// lib/SelectorObserver.ts
|
|
1515
1538
|
var SelectorObserver = class {
|
|
@@ -1891,6 +1914,7 @@ Has: ${checksum}`);
|
|
|
1891
1914
|
exports.pauseFor = pauseFor;
|
|
1892
1915
|
exports.preloadImages = preloadImages;
|
|
1893
1916
|
exports.probeElementStyle = probeElementStyle;
|
|
1917
|
+
exports.purifyObj = purifyObj;
|
|
1894
1918
|
exports.randRange = randRange;
|
|
1895
1919
|
exports.randomId = randomId;
|
|
1896
1920
|
exports.randomItem = randomItem;
|
package/dist/index.js
CHANGED
|
@@ -745,14 +745,15 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
745
745
|
});
|
|
746
746
|
}
|
|
747
747
|
/**
|
|
748
|
-
* Serializes the data stores into a string.
|
|
748
|
+
* Serializes only a subset of the data stores into a string.
|
|
749
|
+
* @param stores An array of store IDs or functions that take a store ID and return a boolean
|
|
749
750
|
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
750
751
|
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
751
752
|
*/
|
|
752
|
-
|
|
753
|
+
serializePartial(stores, useEncoding = true, stringified = true) {
|
|
753
754
|
return __async(this, null, function* () {
|
|
754
755
|
const serData = [];
|
|
755
|
-
for (const storeInst of this.stores) {
|
|
756
|
+
for (const storeInst of this.stores.filter((s) => typeof stores === "function" ? stores(s.id) : stores.includes(s.id))) {
|
|
756
757
|
const data = useEncoding && storeInst.encodingEnabled() ? yield storeInst.encodeData(JSON.stringify(storeInst.getData())) : JSON.stringify(storeInst.getData());
|
|
757
758
|
serData.push({
|
|
758
759
|
id: storeInst.id,
|
|
@@ -766,15 +767,25 @@ var DataStoreSerializer = class _DataStoreSerializer {
|
|
|
766
767
|
});
|
|
767
768
|
}
|
|
768
769
|
/**
|
|
769
|
-
*
|
|
770
|
+
* Serializes the data stores into a string.
|
|
771
|
+
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
772
|
+
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
773
|
+
*/
|
|
774
|
+
serialize(useEncoding = true, stringified = true) {
|
|
775
|
+
return __async(this, null, function* () {
|
|
776
|
+
return this.serializePartial(this.stores.map((s) => s.id), useEncoding, stringified);
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports only a subset into the DataStore instances.
|
|
770
781
|
* Also triggers the migration process if the data format has changed.
|
|
771
782
|
*/
|
|
772
|
-
|
|
783
|
+
deserializePartial(stores, data) {
|
|
773
784
|
return __async(this, null, function* () {
|
|
774
|
-
const deserStores = typeof
|
|
785
|
+
const deserStores = typeof data === "string" ? JSON.parse(data) : data;
|
|
775
786
|
if (!Array.isArray(deserStores) || !deserStores.every(_DataStoreSerializer.isSerializedDataStore))
|
|
776
787
|
throw new TypeError("Invalid serialized data format! Expected an array of SerializedDataStore objects.");
|
|
777
|
-
for (const storeData of deserStores) {
|
|
788
|
+
for (const storeData of deserStores.filter((s) => typeof stores === "function" ? stores(s.id) : stores.includes(s.id))) {
|
|
778
789
|
const storeInst = this.stores.find((s) => s.id === storeData.id);
|
|
779
790
|
if (!storeInst)
|
|
780
791
|
throw new Error(`DataStore instance with ID "${storeData.id}" not found! Make sure to provide it in the DataStoreSerializer constructor.`);
|
|
@@ -793,6 +804,15 @@ Has: ${checksum}`);
|
|
|
793
804
|
}
|
|
794
805
|
});
|
|
795
806
|
}
|
|
807
|
+
/**
|
|
808
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports the data into all matching DataStore instances.
|
|
809
|
+
* Also triggers the migration process if the data format has changed.
|
|
810
|
+
*/
|
|
811
|
+
deserialize(data) {
|
|
812
|
+
return __async(this, null, function* () {
|
|
813
|
+
return this.deserializePartial(this.stores.map((s) => s.id), data);
|
|
814
|
+
});
|
|
815
|
+
}
|
|
796
816
|
/**
|
|
797
817
|
* Loads the persistent data of the DataStore instances into the in-memory cache.
|
|
798
818
|
* Also triggers the migration process if the data format has changed.
|
|
@@ -1470,6 +1490,9 @@ function consumeStringGen(strGen) {
|
|
|
1470
1490
|
function getListLength(obj, zeroOnInvalid = true) {
|
|
1471
1491
|
return "length" in obj ? obj.length : "size" in obj ? obj.size : "count" in obj ? obj.count : zeroOnInvalid ? 0 : NaN;
|
|
1472
1492
|
}
|
|
1493
|
+
function purifyObj(obj) {
|
|
1494
|
+
return Object.assign(/* @__PURE__ */ Object.create(null), obj);
|
|
1495
|
+
}
|
|
1473
1496
|
|
|
1474
1497
|
// lib/SelectorObserver.ts
|
|
1475
1498
|
var SelectorObserver = class {
|
|
@@ -1807,4 +1830,4 @@ var tr = {
|
|
|
1807
1830
|
}
|
|
1808
1831
|
};
|
|
1809
1832
|
|
|
1810
|
-
export { ChecksumMismatchError, DataStore, DataStoreSerializer, Debouncer, Dialog, MigrationError, NanoEmitter, PlatformError, SelectorObserver, UUError, addGlobalStyle, addParent, autoPlural, bitSetHas, clamp, compress, computeHash, consumeGen, consumeStringGen, currentDialogId, darkenColor, debounce, decompress, defaultDialogCss, defaultStrings, digitCount, fetchAdvanced, getListLength, getSiblingsFrame, getUnsafeWindow, hexToRgb, insertValues, interceptEvent, interceptWindowEvent, isDomLoaded, isScrollable, lightenColor, mapRange, observeElementProp, onDomLoad, openDialogs, openInNewTab, pauseFor, preloadImages, probeElementStyle, randRange, randomId, randomItem, randomItemIndex, randomizeArray, rgbToHex, roundFixed, setInnerHtmlUnsafe, takeRandomItem, tr };
|
|
1833
|
+
export { ChecksumMismatchError, DataStore, DataStoreSerializer, Debouncer, Dialog, MigrationError, NanoEmitter, PlatformError, SelectorObserver, UUError, addGlobalStyle, addParent, autoPlural, bitSetHas, clamp, compress, computeHash, consumeGen, consumeStringGen, currentDialogId, darkenColor, debounce, decompress, defaultDialogCss, defaultStrings, digitCount, fetchAdvanced, getListLength, getSiblingsFrame, getUnsafeWindow, hexToRgb, insertValues, interceptEvent, interceptWindowEvent, isDomLoaded, isScrollable, lightenColor, mapRange, observeElementProp, onDomLoad, openDialogs, openInNewTab, pauseFor, preloadImages, probeElementStyle, purifyObj, randRange, randomId, randomItem, randomItemIndex, randomizeArray, rgbToHex, roundFixed, setInnerHtmlUnsafe, takeRandomItem, tr };
|
|
@@ -6,7 +6,7 @@ import type { DataStore } from "./DataStore.js";
|
|
|
6
6
|
export type DataStoreSerializerOptions = {
|
|
7
7
|
/** Whether to add a checksum to the exported data */
|
|
8
8
|
addChecksum?: boolean;
|
|
9
|
-
/** Whether to ensure the integrity of the data when importing it (
|
|
9
|
+
/** Whether to ensure the integrity of the data when importing it by throwing an error (doesn't throw when the checksum property doesn't exist) */
|
|
10
10
|
ensureIntegrity?: boolean;
|
|
11
11
|
};
|
|
12
12
|
/** Serialized data of a DataStore instance */
|
|
@@ -19,7 +19,7 @@ export type SerializedDataStore = {
|
|
|
19
19
|
formatVersion: number;
|
|
20
20
|
/** Whether the data is encoded */
|
|
21
21
|
encoded: boolean;
|
|
22
|
-
/** The checksum of the data - key is not present
|
|
22
|
+
/** The checksum of the data - key is not present when `addChecksum` is `false` */
|
|
23
23
|
checksum?: string;
|
|
24
24
|
};
|
|
25
25
|
/** Result of {@linkcode DataStoreSerializer.loadStoresData()} */
|
|
@@ -43,23 +43,49 @@ export declare class DataStoreSerializer {
|
|
|
43
43
|
constructor(stores: DataStore[], options?: DataStoreSerializerOptions);
|
|
44
44
|
/** Calculates the checksum of a string */
|
|
45
45
|
protected calcChecksum(input: string): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Serializes only a subset of the data stores into a string.
|
|
48
|
+
* @param stores An array of store IDs or functions that take a store ID and return a boolean
|
|
49
|
+
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
50
|
+
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
51
|
+
*/
|
|
52
|
+
serializePartial(stores: string[] | ((id: string) => boolean), useEncoding?: boolean, stringified?: true): Promise<string>;
|
|
53
|
+
/**
|
|
54
|
+
* Serializes only a subset of the data stores into a string.
|
|
55
|
+
* @param stores An array of store IDs or functions that take a store ID and return a boolean
|
|
56
|
+
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
57
|
+
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
58
|
+
*/
|
|
59
|
+
serializePartial(stores: string[] | ((id: string) => boolean), useEncoding?: boolean, stringified?: false): Promise<SerializedDataStore[]>;
|
|
60
|
+
/**
|
|
61
|
+
* Serializes only a subset of the data stores into a string.
|
|
62
|
+
* @param stores An array of store IDs or functions that take a store ID and return a boolean
|
|
63
|
+
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
64
|
+
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
65
|
+
*/
|
|
66
|
+
serializePartial(stores: string[] | ((id: string) => boolean), useEncoding?: boolean, stringified?: boolean): Promise<string | SerializedDataStore[]>;
|
|
46
67
|
/**
|
|
47
68
|
* Serializes the data stores into a string.
|
|
48
69
|
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
49
70
|
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
50
71
|
*/
|
|
51
|
-
serialize(useEncoding
|
|
72
|
+
serialize(useEncoding?: boolean, stringified?: true): Promise<string>;
|
|
52
73
|
/**
|
|
53
74
|
* Serializes the data stores into a string.
|
|
54
75
|
* @param useEncoding Whether to encode the data using each DataStore's `encodeData()` method
|
|
55
76
|
* @param stringified Whether to return the result as a string or as an array of `SerializedDataStore` objects
|
|
56
77
|
*/
|
|
57
|
-
serialize(useEncoding
|
|
78
|
+
serialize(useEncoding?: boolean, stringified?: false): Promise<SerializedDataStore[]>;
|
|
79
|
+
/**
|
|
80
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports only a subset into the DataStore instances.
|
|
81
|
+
* Also triggers the migration process if the data format has changed.
|
|
82
|
+
*/
|
|
83
|
+
deserializePartial(stores: string[] | ((id: string) => boolean), data: string | SerializedDataStore[]): Promise<void>;
|
|
58
84
|
/**
|
|
59
|
-
* Deserializes the data exported via {@linkcode serialize()} and imports
|
|
85
|
+
* Deserializes the data exported via {@linkcode serialize()} and imports the data into all matching DataStore instances.
|
|
60
86
|
* Also triggers the migration process if the data format has changed.
|
|
61
87
|
*/
|
|
62
|
-
deserialize(
|
|
88
|
+
deserialize(data: string | SerializedDataStore[]): Promise<void>;
|
|
63
89
|
/**
|
|
64
90
|
* Loads the persistent data of the DataStore instances into the in-memory cache.
|
|
65
91
|
* Also triggers the migration process if the data format has changed.
|
package/dist/lib/misc.d.ts
CHANGED
|
@@ -61,3 +61,9 @@ export declare function consumeStringGen<TStrUnion extends string>(strGen: Strin
|
|
|
61
61
|
* Set {@linkcode zeroOnInvalid} to false to return NaN instead of 0 if the object doesn't have any of the properties.
|
|
62
62
|
*/
|
|
63
63
|
export declare function getListLength(obj: ListWithLength, zeroOnInvalid?: boolean): number;
|
|
64
|
+
/**
|
|
65
|
+
* Turns the passed object into a "pure" object without a prototype chain, meaning it won't have any default properties like `toString`, `__proto__`, `__defineGetter__`, etc.
|
|
66
|
+
* This makes the object immune to prototype pollution attacks and allows for cleaner object literals, at the cost of being harder to work with in some cases.
|
|
67
|
+
* It also effectively transforms a `Stringifiable` value into one that will throw a TypeError when stringified instead of defaulting to `[object Object]`
|
|
68
|
+
*/
|
|
69
|
+
export declare function purifyObj<TObj extends object>(obj: TObj): TObj;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sv443-network/userutils",
|
|
3
3
|
"libName": "UserUtils",
|
|
4
|
-
"version": "9.
|
|
4
|
+
"version": "9.3.0",
|
|
5
5
|
"description": "General purpose DOM/GreaseMonkey library that allows you to register listeners for when CSS selectors exist, intercept events, create persistent & synchronous data stores, modify the DOM more easily and much more",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|