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