@ztimson/utils 0.24.2 → 0.24.4
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/dist/index.cjs +183 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +181 -11
- package/dist/index.mjs.map +1 -1
- package/dist/search.d.ts +7 -1
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (
|
|
1
|
+
(function(global2, factory) {
|
|
2
|
+
typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global2 = typeof globalThis !== "undefined" ? globalThis : global2 || self, factory(global2.utils = {}));
|
|
3
3
|
})(this, function(exports2) {
|
|
4
4
|
"use strict";var __defProp = Object.defineProperty;
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -1443,7 +1443,7 @@ ${opts.message || this.desc}`;
|
|
|
1443
1443
|
if (str[i]) combined.push(str[i]);
|
|
1444
1444
|
if (args[i]) combined.push(args[i]);
|
|
1445
1445
|
}
|
|
1446
|
-
return new PathEvent(combined.join(""));
|
|
1446
|
+
return new PathEvent(combined.join("/"));
|
|
1447
1447
|
}
|
|
1448
1448
|
function PES(str, ...args) {
|
|
1449
1449
|
let combined = [];
|
|
@@ -1502,28 +1502,28 @@ ${opts.message || this.desc}`;
|
|
|
1502
1502
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("c"));
|
|
1503
1503
|
}
|
|
1504
1504
|
set create(v) {
|
|
1505
|
-
v ? this.methods.delete("n").add("c") : this.methods.delete("c");
|
|
1505
|
+
v ? this.methods.delete("n").delete("*").add("c") : this.methods.delete("c");
|
|
1506
1506
|
}
|
|
1507
1507
|
/** Read method specified */
|
|
1508
1508
|
get read() {
|
|
1509
1509
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("r"));
|
|
1510
1510
|
}
|
|
1511
1511
|
set read(v) {
|
|
1512
|
-
v ? this.methods.delete("n").add("r") : this.methods.delete("r");
|
|
1512
|
+
v ? this.methods.delete("n").delete("*").add("r") : this.methods.delete("r");
|
|
1513
1513
|
}
|
|
1514
1514
|
/** Update method specified */
|
|
1515
1515
|
get update() {
|
|
1516
1516
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("u"));
|
|
1517
1517
|
}
|
|
1518
1518
|
set update(v) {
|
|
1519
|
-
v ? this.methods.delete("n").add("u") : this.methods.delete("u");
|
|
1519
|
+
v ? this.methods.delete("n").delete("*").add("u") : this.methods.delete("u");
|
|
1520
1520
|
}
|
|
1521
1521
|
/** Delete method specified */
|
|
1522
1522
|
get delete() {
|
|
1523
1523
|
return !this.methods.has("n") && (this.methods.has("*") || this.methods.has("d"));
|
|
1524
1524
|
}
|
|
1525
1525
|
set delete(v) {
|
|
1526
|
-
v ? this.methods.delete("n").add("d") : this.methods.delete("d");
|
|
1526
|
+
v ? this.methods.delete("n").delete("*").add("d") : this.methods.delete("d");
|
|
1527
1527
|
}
|
|
1528
1528
|
/**
|
|
1529
1529
|
* Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
|
|
@@ -1681,11 +1681,11 @@ ${opts.message || this.desc}`;
|
|
|
1681
1681
|
}
|
|
1682
1682
|
}).length;
|
|
1683
1683
|
} else {
|
|
1684
|
-
return
|
|
1684
|
+
return logicTest(r, search2);
|
|
1685
1685
|
}
|
|
1686
1686
|
});
|
|
1687
1687
|
}
|
|
1688
|
-
function
|
|
1688
|
+
function logicTest(target, condition) {
|
|
1689
1689
|
const evalBoolean = (a, op, b) => {
|
|
1690
1690
|
switch (op) {
|
|
1691
1691
|
case "=":
|
|
@@ -1711,10 +1711,10 @@ ${opts.message || this.desc}`;
|
|
|
1711
1711
|
return and.filter((p2) => {
|
|
1712
1712
|
const prop = /(\S+)\s*(==?|!=|>=|>|<=|<)\s*(\S+)/g.exec(p2);
|
|
1713
1713
|
if (prop) {
|
|
1714
|
-
const key = Object.keys(
|
|
1715
|
-
return evalBoolean(dotNotation(
|
|
1714
|
+
const key = Object.keys(target).find((k) => k.toLowerCase() == prop[1].toLowerCase());
|
|
1715
|
+
return evalBoolean(dotNotation(target, key || prop[1]), prop[2], JSONAttemptParse(prop[3]));
|
|
1716
1716
|
}
|
|
1717
|
-
const v = Object.values(
|
|
1717
|
+
const v = Object.values(target).map(JSONSerialize).join("");
|
|
1718
1718
|
if (/[A-Z]/g.test(condition)) return v.includes(p2);
|
|
1719
1719
|
return v.toLowerCase().includes(p2);
|
|
1720
1720
|
}).length == and.length;
|
|
@@ -1723,6 +1723,176 @@ ${opts.message || this.desc}`;
|
|
|
1723
1723
|
function typeKeys() {
|
|
1724
1724
|
return Object.keys({});
|
|
1725
1725
|
}
|
|
1726
|
+
var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
|
|
1727
|
+
var dist = {};
|
|
1728
|
+
var persist$1 = {};
|
|
1729
|
+
Object.defineProperty(persist$1, "__esModule", { value: true });
|
|
1730
|
+
persist$1.persist = persist$1.Persist = void 0;
|
|
1731
|
+
class Persist {
|
|
1732
|
+
/**
|
|
1733
|
+
* @param {string} key Primary key value will be stored under
|
|
1734
|
+
* @param {PersistOptions<T>} options Configure using {@link PersistOptions}
|
|
1735
|
+
*/
|
|
1736
|
+
constructor(key, options = {}) {
|
|
1737
|
+
__publicField(this, "key");
|
|
1738
|
+
__publicField(this, "options");
|
|
1739
|
+
/** Backend service to store data, must implement `Storage` interface */
|
|
1740
|
+
__publicField(this, "storage");
|
|
1741
|
+
/** Listeners which should be notified on changes */
|
|
1742
|
+
__publicField(this, "watches", {});
|
|
1743
|
+
/** Private value field */
|
|
1744
|
+
__publicField(this, "_value");
|
|
1745
|
+
this.key = key;
|
|
1746
|
+
this.options = options;
|
|
1747
|
+
this.storage = options.storage || localStorage;
|
|
1748
|
+
this.load();
|
|
1749
|
+
}
|
|
1750
|
+
/** Current value or default if undefined */
|
|
1751
|
+
get value() {
|
|
1752
|
+
var _a;
|
|
1753
|
+
return this._value !== void 0 ? this._value : (_a = this.options) == null ? void 0 : _a.default;
|
|
1754
|
+
}
|
|
1755
|
+
/** Set value with proxy object wrapper to sync future changes */
|
|
1756
|
+
set value(v) {
|
|
1757
|
+
if (v == null || typeof v != "object")
|
|
1758
|
+
this._value = v;
|
|
1759
|
+
else
|
|
1760
|
+
this._value = new Proxy(v, {
|
|
1761
|
+
get: (target, p) => {
|
|
1762
|
+
const f = typeof target[p] == "function";
|
|
1763
|
+
if (!f)
|
|
1764
|
+
return target[p];
|
|
1765
|
+
return (...args) => {
|
|
1766
|
+
const value = target[p](...args);
|
|
1767
|
+
this.save();
|
|
1768
|
+
return value;
|
|
1769
|
+
};
|
|
1770
|
+
},
|
|
1771
|
+
set: (target, p, newValue) => {
|
|
1772
|
+
target[p] = newValue;
|
|
1773
|
+
this.save();
|
|
1774
|
+
return true;
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
this.save();
|
|
1778
|
+
}
|
|
1779
|
+
/** Notify listeners of change */
|
|
1780
|
+
notify(value) {
|
|
1781
|
+
Object.values(this.watches).forEach((watch) => watch(value));
|
|
1782
|
+
}
|
|
1783
|
+
/** Delete value from storage */
|
|
1784
|
+
clear() {
|
|
1785
|
+
this.storage.removeItem(this.key);
|
|
1786
|
+
}
|
|
1787
|
+
/** Save current value to storage */
|
|
1788
|
+
save() {
|
|
1789
|
+
if (this._value === void 0)
|
|
1790
|
+
this.clear();
|
|
1791
|
+
else
|
|
1792
|
+
this.storage.setItem(this.key, JSON.stringify(this._value));
|
|
1793
|
+
this.notify(this.value);
|
|
1794
|
+
}
|
|
1795
|
+
/** Load value from storage */
|
|
1796
|
+
load() {
|
|
1797
|
+
if (this.storage[this.key] != void 0) {
|
|
1798
|
+
let value = JSON.parse(this.storage.getItem(this.key));
|
|
1799
|
+
if (value != null && typeof value == "object" && this.options.type)
|
|
1800
|
+
value.__proto__ = this.options.type.prototype;
|
|
1801
|
+
this.value = value;
|
|
1802
|
+
} else
|
|
1803
|
+
this.value = this.options.default || void 0;
|
|
1804
|
+
}
|
|
1805
|
+
/**
|
|
1806
|
+
* Callback function which is run when there are changes
|
|
1807
|
+
*
|
|
1808
|
+
* @param {(value: T) => any} fn Callback will run on each change; it's passed the next value & it's return is ignored
|
|
1809
|
+
* @returns {() => void} Function which will unsubscribe the watch/callback when called
|
|
1810
|
+
*/
|
|
1811
|
+
watch(fn2) {
|
|
1812
|
+
const index = Object.keys(this.watches).length;
|
|
1813
|
+
this.watches[index] = fn2;
|
|
1814
|
+
return () => {
|
|
1815
|
+
delete this.watches[index];
|
|
1816
|
+
};
|
|
1817
|
+
}
|
|
1818
|
+
/**
|
|
1819
|
+
* Return value as JSON string
|
|
1820
|
+
*
|
|
1821
|
+
* @returns {string} Stringified object as JSON
|
|
1822
|
+
*/
|
|
1823
|
+
toString() {
|
|
1824
|
+
return JSON.stringify(this.value);
|
|
1825
|
+
}
|
|
1826
|
+
/**
|
|
1827
|
+
* Return current value
|
|
1828
|
+
*
|
|
1829
|
+
* @returns {T} Current value
|
|
1830
|
+
*/
|
|
1831
|
+
valueOf() {
|
|
1832
|
+
return this.value;
|
|
1833
|
+
}
|
|
1834
|
+
}
|
|
1835
|
+
persist$1.Persist = Persist;
|
|
1836
|
+
function persist(options) {
|
|
1837
|
+
return (target, prop) => {
|
|
1838
|
+
const key = (options == null ? void 0 : options.key) || `${target.constructor.name}.${prop.toString()}`;
|
|
1839
|
+
const wrapper = new Persist(key, options);
|
|
1840
|
+
Object.defineProperty(target, prop, {
|
|
1841
|
+
get: function() {
|
|
1842
|
+
return wrapper.value;
|
|
1843
|
+
},
|
|
1844
|
+
set: function(v) {
|
|
1845
|
+
wrapper.value = v;
|
|
1846
|
+
}
|
|
1847
|
+
});
|
|
1848
|
+
};
|
|
1849
|
+
}
|
|
1850
|
+
persist$1.persist = persist;
|
|
1851
|
+
var memoryStorage = {};
|
|
1852
|
+
Object.defineProperty(memoryStorage, "__esModule", { value: true });
|
|
1853
|
+
memoryStorage.MemoryStorage = void 0;
|
|
1854
|
+
class MemoryStorage {
|
|
1855
|
+
get length() {
|
|
1856
|
+
return Object.keys(this).length;
|
|
1857
|
+
}
|
|
1858
|
+
clear() {
|
|
1859
|
+
Object.keys(this).forEach((k) => this.removeItem(k));
|
|
1860
|
+
}
|
|
1861
|
+
getItem(key) {
|
|
1862
|
+
return this[key];
|
|
1863
|
+
}
|
|
1864
|
+
key(index) {
|
|
1865
|
+
return Object.keys(this)[index];
|
|
1866
|
+
}
|
|
1867
|
+
removeItem(key) {
|
|
1868
|
+
delete this[key];
|
|
1869
|
+
}
|
|
1870
|
+
setItem(key, value) {
|
|
1871
|
+
this[key] = value;
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
memoryStorage.MemoryStorage = MemoryStorage;
|
|
1875
|
+
(function(exports3) {
|
|
1876
|
+
var __createBinding = commonjsGlobal && commonjsGlobal.__createBinding || (Object.create ? function(o, m, k, k2) {
|
|
1877
|
+
if (k2 === void 0) k2 = k;
|
|
1878
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1879
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
1880
|
+
desc = { enumerable: true, get: function() {
|
|
1881
|
+
return m[k];
|
|
1882
|
+
} };
|
|
1883
|
+
}
|
|
1884
|
+
Object.defineProperty(o, k2, desc);
|
|
1885
|
+
} : function(o, m, k, k2) {
|
|
1886
|
+
if (k2 === void 0) k2 = k;
|
|
1887
|
+
o[k2] = m[k];
|
|
1888
|
+
});
|
|
1889
|
+
var __exportStar = commonjsGlobal && commonjsGlobal.__exportStar || function(m, exports4) {
|
|
1890
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports4, p)) __createBinding(exports4, m, p);
|
|
1891
|
+
};
|
|
1892
|
+
Object.defineProperty(exports3, "__esModule", { value: true });
|
|
1893
|
+
__exportStar(persist$1, exports3);
|
|
1894
|
+
__exportStar(memoryStorage, exports3);
|
|
1895
|
+
})(dist);
|
|
1726
1896
|
exports2.ASet = ASet;
|
|
1727
1897
|
exports2.ArgParser = ArgParser;
|
|
1728
1898
|
exports2.BadGatewayError = BadGatewayError;
|
|
@@ -1794,6 +1964,7 @@ ${opts.message || this.desc}`;
|
|
|
1794
1964
|
exports2.instantInterval = instantInterval;
|
|
1795
1965
|
exports2.isEqual = isEqual;
|
|
1796
1966
|
exports2.kebabCase = kebabCase;
|
|
1967
|
+
exports2.logicTest = logicTest;
|
|
1797
1968
|
exports2.makeArray = makeArray;
|
|
1798
1969
|
exports2.makeUnique = makeUnique;
|
|
1799
1970
|
exports2.matchAll = matchAll;
|
|
@@ -1811,7 +1982,6 @@ ${opts.message || this.desc}`;
|
|
|
1811
1982
|
exports2.snakeCase = snakeCase;
|
|
1812
1983
|
exports2.sortByProp = sortByProp;
|
|
1813
1984
|
exports2.strSplice = strSplice;
|
|
1814
|
-
exports2.testCondition = testCondition;
|
|
1815
1985
|
exports2.timeUntil = timeUntil;
|
|
1816
1986
|
exports2.timestampFilename = timestampFilename;
|
|
1817
1987
|
exports2.toCsv = toCsv;
|