@andrew_l/toolkit 0.3.3 → 0.3.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/dist/index.cjs +436 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +251 -170
- package/dist/index.d.mts +251 -170
- package/dist/index.d.ts +251 -170
- package/dist/index.mjs +434 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -930,7 +930,7 @@ function fn(value, message) {
|
|
|
930
930
|
}
|
|
931
931
|
}
|
|
932
932
|
function greaterThan(value, target, message) {
|
|
933
|
-
if (!isNumber(value) || value
|
|
933
|
+
if (!isNumber(value) || value <= target) {
|
|
934
934
|
throw toError$1(
|
|
935
935
|
greaterThan,
|
|
936
936
|
value,
|
|
@@ -1722,6 +1722,438 @@ function bigIntFromBytes(bytes) {
|
|
|
1722
1722
|
return decoded;
|
|
1723
1723
|
}
|
|
1724
1724
|
|
|
1725
|
+
function toError(value, unknownMessage = "Unknown error") {
|
|
1726
|
+
if (isError(value)) {
|
|
1727
|
+
return value;
|
|
1728
|
+
}
|
|
1729
|
+
const error = new Error(unknownMessage, { cause: value });
|
|
1730
|
+
Error.captureStackTrace(error, toError);
|
|
1731
|
+
return error;
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
function createFunction(fnName, code, ...args) {
|
|
1735
|
+
try {
|
|
1736
|
+
const fn = new Function(...args, code);
|
|
1737
|
+
fn.code = code;
|
|
1738
|
+
return fn;
|
|
1739
|
+
} catch (err) {
|
|
1740
|
+
throw new Error(
|
|
1741
|
+
`failed to create bitPack.${fnName}()
|
|
1742
|
+
Error: ${toError(err).message}
|
|
1743
|
+
-- CODE START --
|
|
1744
|
+
${code}
|
|
1745
|
+
-- CODE END--`
|
|
1746
|
+
);
|
|
1747
|
+
}
|
|
1748
|
+
}
|
|
1749
|
+
|
|
1750
|
+
function bitPack(options) {
|
|
1751
|
+
notEmpty(options.fields, "fields cannot be empty");
|
|
1752
|
+
greaterThan(options.totalBits, 0, "totalBits must be greater than 0");
|
|
1753
|
+
const fields = buildFieldsInfo$1(options.fields, options.totalBits);
|
|
1754
|
+
const plan = buildPlan(fields);
|
|
1755
|
+
const containersCount = Math.ceil(options.totalBits / 32);
|
|
1756
|
+
const buf = new Uint8Array(containersCount * 4);
|
|
1757
|
+
const baseCode = [
|
|
1758
|
+
"\n// Field init",
|
|
1759
|
+
initFields(fields),
|
|
1760
|
+
"\n// Plan",
|
|
1761
|
+
compilePlan(plan, options.optimize)
|
|
1762
|
+
];
|
|
1763
|
+
const fnBufferCode = [
|
|
1764
|
+
...baseCode,
|
|
1765
|
+
"\n// Return result",
|
|
1766
|
+
buildBufferResult(containersCount)
|
|
1767
|
+
].join("\n");
|
|
1768
|
+
const fnBuffer = createFunction(
|
|
1769
|
+
"buffer",
|
|
1770
|
+
fnBufferCode,
|
|
1771
|
+
"data"
|
|
1772
|
+
);
|
|
1773
|
+
const fnBigIntCode = [
|
|
1774
|
+
...baseCode,
|
|
1775
|
+
"\n// Return result",
|
|
1776
|
+
buildBigIntResult(containersCount)
|
|
1777
|
+
].join("\n");
|
|
1778
|
+
const fnBigInt = createFunction(
|
|
1779
|
+
"bigint",
|
|
1780
|
+
fnBigIntCode,
|
|
1781
|
+
"data"
|
|
1782
|
+
);
|
|
1783
|
+
const fnNumberCode = [
|
|
1784
|
+
...baseCode,
|
|
1785
|
+
"\n// Return result",
|
|
1786
|
+
buildNumberResult()
|
|
1787
|
+
].join("\n");
|
|
1788
|
+
const fnNumber = createFunction(
|
|
1789
|
+
"number",
|
|
1790
|
+
fnNumberCode,
|
|
1791
|
+
"data"
|
|
1792
|
+
);
|
|
1793
|
+
const fnBitsCode = [
|
|
1794
|
+
...baseCode,
|
|
1795
|
+
"\n// Return result",
|
|
1796
|
+
buildBitsResult(containersCount, options.totalBits)
|
|
1797
|
+
].join("\n");
|
|
1798
|
+
const fnBits = createFunction("bits", fnBitsCode, "data");
|
|
1799
|
+
if (!options.debug) {
|
|
1800
|
+
def(fnBuffer, "code", void 0);
|
|
1801
|
+
def(fnBigInt, "code", void 0);
|
|
1802
|
+
def(fnNumber, "code", void 0);
|
|
1803
|
+
def(fnBits, "code", void 0);
|
|
1804
|
+
}
|
|
1805
|
+
return {
|
|
1806
|
+
buffer: fnBuffer,
|
|
1807
|
+
bigint: fnBigInt,
|
|
1808
|
+
number: fnNumber,
|
|
1809
|
+
bits: fnBits,
|
|
1810
|
+
plan: options.debug ? plan : void 0,
|
|
1811
|
+
__buf: buf
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
function initFields(fields) {
|
|
1815
|
+
return fields.map((field) => {
|
|
1816
|
+
if (field.bits > 32) {
|
|
1817
|
+
ok(
|
|
1818
|
+
field.take === "low",
|
|
1819
|
+
`Fields more than 32 bits with take 'high' not yet supported`
|
|
1820
|
+
);
|
|
1821
|
+
const highMask = Math.pow(2, field.bits - 32) - 1;
|
|
1822
|
+
return [
|
|
1823
|
+
`var ${field.id}_high = ((data['${field.name}'] / 0x100000000) | 0) & 0x${highMask.toString(16)};`,
|
|
1824
|
+
`var ${field.id}_low = (data['${field.name}'] >>> 0);`
|
|
1825
|
+
].join("\n");
|
|
1826
|
+
}
|
|
1827
|
+
if (field.take === "high") {
|
|
1828
|
+
return `var ${field.id} = (data['${field.name}'] / 0x100000000) | 0;`;
|
|
1829
|
+
}
|
|
1830
|
+
return `var ${field.id} = (data['${field.name}'] & 0x${field.mask.toString(16)}) >>> 0;`;
|
|
1831
|
+
}).join("\n");
|
|
1832
|
+
}
|
|
1833
|
+
function buildBufferResult(containersCount) {
|
|
1834
|
+
const lines = [`var buf = this.__buf;`];
|
|
1835
|
+
for (let i = 0; i < containersCount; i++) {
|
|
1836
|
+
const containerIndex = containersCount - 1 - i;
|
|
1837
|
+
lines.push(
|
|
1838
|
+
`buf[${i * 4}] = c_${containerIndex} >>> 24;`,
|
|
1839
|
+
`buf[${i * 4 + 1}] = c_${containerIndex} >>> 16;`,
|
|
1840
|
+
`buf[${i * 4 + 2}] = c_${containerIndex} >>> 8;`,
|
|
1841
|
+
`buf[${i * 4 + 3}] = c_${containerIndex};`
|
|
1842
|
+
);
|
|
1843
|
+
}
|
|
1844
|
+
lines.push("return buf;");
|
|
1845
|
+
return lines.join("\n");
|
|
1846
|
+
}
|
|
1847
|
+
function buildBigIntResult(containersCount) {
|
|
1848
|
+
const parts = [];
|
|
1849
|
+
for (let i = 0; i < containersCount; i++) {
|
|
1850
|
+
const containerIndex = containersCount - 1 - i;
|
|
1851
|
+
if (containerIndex > 0) {
|
|
1852
|
+
parts.push(
|
|
1853
|
+
`(BigInt(c_${containerIndex} >>> 0) << ${containerIndex * 32}n)`
|
|
1854
|
+
);
|
|
1855
|
+
} else {
|
|
1856
|
+
parts.push(`BigInt(c_${containerIndex} >>> 0)`);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
return `return (
|
|
1860
|
+
${parts.join(" |\n ")}
|
|
1861
|
+
);`;
|
|
1862
|
+
}
|
|
1863
|
+
function buildNumberResult(containersCount) {
|
|
1864
|
+
return `return c_0;`;
|
|
1865
|
+
}
|
|
1866
|
+
function buildBitsResult(containersCount, totalBits) {
|
|
1867
|
+
const parts = [];
|
|
1868
|
+
for (let i = 0; i < containersCount; i++) {
|
|
1869
|
+
const containerIndex = containersCount - 1 - i;
|
|
1870
|
+
if (containerIndex > 0) {
|
|
1871
|
+
parts.push(
|
|
1872
|
+
`(BigInt(c_${containerIndex} >>> 0) << ${containerIndex * 32}n)`
|
|
1873
|
+
);
|
|
1874
|
+
} else {
|
|
1875
|
+
parts.push(`BigInt(c_${containerIndex} >>> 0)`);
|
|
1876
|
+
}
|
|
1877
|
+
}
|
|
1878
|
+
return `return (
|
|
1879
|
+
${parts.join(" |\n ")}
|
|
1880
|
+
).toString(2).padStart(${totalBits}, '0');`;
|
|
1881
|
+
}
|
|
1882
|
+
function compilePlan(plan, optimize) {
|
|
1883
|
+
if (optimize) {
|
|
1884
|
+
plan = optimizePlan(plan);
|
|
1885
|
+
}
|
|
1886
|
+
const assigned = /* @__PURE__ */ new Set();
|
|
1887
|
+
return plan.map((item) => compilePlanItem(item, assigned)).join("\n");
|
|
1888
|
+
}
|
|
1889
|
+
function optimizePlan(plan) {
|
|
1890
|
+
return plan.reduce((result, item) => {
|
|
1891
|
+
const prev = result.at(-1);
|
|
1892
|
+
if (canMergeSetOperations(prev, item)) {
|
|
1893
|
+
result.pop();
|
|
1894
|
+
result.push({
|
|
1895
|
+
object: "set",
|
|
1896
|
+
container: item.container,
|
|
1897
|
+
child: {
|
|
1898
|
+
object: "value",
|
|
1899
|
+
value: [
|
|
1900
|
+
compilePlanItem(prev.child),
|
|
1901
|
+
compilePlanItem(item.child)
|
|
1902
|
+
].join(" |\n ")
|
|
1903
|
+
}
|
|
1904
|
+
});
|
|
1905
|
+
} else {
|
|
1906
|
+
result.push(item);
|
|
1907
|
+
}
|
|
1908
|
+
return result;
|
|
1909
|
+
}, []);
|
|
1910
|
+
}
|
|
1911
|
+
function canMergeSetOperations(prev, current) {
|
|
1912
|
+
return prev?.object === "set" && current.object === "set" && prev.container === current.container;
|
|
1913
|
+
}
|
|
1914
|
+
function compilePlanItem(plan, assigned) {
|
|
1915
|
+
switch (plan.object) {
|
|
1916
|
+
case "set":
|
|
1917
|
+
if (assigned && !assigned.has(plan.container)) {
|
|
1918
|
+
assigned.add(plan.container);
|
|
1919
|
+
return `var c_${plan.container} = ${compilePlanItem(plan.child)};`;
|
|
1920
|
+
}
|
|
1921
|
+
return `c_${plan.container} |= ${compilePlanItem(plan.child)};`;
|
|
1922
|
+
case "value":
|
|
1923
|
+
const offset = plan.offset ?? 0;
|
|
1924
|
+
return offset > 0 ? `(${plan.value}) << ${offset}` : `(${plan.value})`;
|
|
1925
|
+
default:
|
|
1926
|
+
throw new Error(`Unknown plan object: ${plan.object}`);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
function buildPlan(fields) {
|
|
1930
|
+
const result = [];
|
|
1931
|
+
for (const field of fields) {
|
|
1932
|
+
const startContainer = Math.floor(field.startBit / 32);
|
|
1933
|
+
const endContainer = Math.floor(field.endBit / 32);
|
|
1934
|
+
if (startContainer === endContainer) {
|
|
1935
|
+
addSingleContainerField(field, result);
|
|
1936
|
+
} else if (field.bits <= 32) {
|
|
1937
|
+
addSpanningField(field, result);
|
|
1938
|
+
} else {
|
|
1939
|
+
addLargeField(field, result);
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
return result;
|
|
1943
|
+
}
|
|
1944
|
+
function addSingleContainerField(field, result) {
|
|
1945
|
+
result.push({
|
|
1946
|
+
object: "set",
|
|
1947
|
+
container: Math.floor(field.startBit / 32),
|
|
1948
|
+
child: {
|
|
1949
|
+
object: "value",
|
|
1950
|
+
offset: field.startBit % 32,
|
|
1951
|
+
value: field.id
|
|
1952
|
+
}
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
function addSpanningField(field, result) {
|
|
1956
|
+
const startContainer = Math.floor(field.startBit / 32);
|
|
1957
|
+
const endContainer = Math.floor(field.endBit / 32);
|
|
1958
|
+
const firstContainerBits = 32 - field.startBit % 32;
|
|
1959
|
+
result.push({
|
|
1960
|
+
object: "set",
|
|
1961
|
+
container: startContainer,
|
|
1962
|
+
child: {
|
|
1963
|
+
object: "value",
|
|
1964
|
+
offset: field.startBit % 32,
|
|
1965
|
+
value: `(${field.id}) & ${(1 << firstContainerBits) - 1}`
|
|
1966
|
+
}
|
|
1967
|
+
});
|
|
1968
|
+
result.push({
|
|
1969
|
+
object: "set",
|
|
1970
|
+
container: endContainer,
|
|
1971
|
+
child: {
|
|
1972
|
+
object: "value",
|
|
1973
|
+
value: `(${field.id}) >>> ${firstContainerBits}`
|
|
1974
|
+
}
|
|
1975
|
+
});
|
|
1976
|
+
}
|
|
1977
|
+
function addLargeField(field, result) {
|
|
1978
|
+
const startContainer = Math.floor(field.startBit / 32);
|
|
1979
|
+
const endContainer = Math.floor(field.endBit / 32);
|
|
1980
|
+
const startOffset = field.startBit % 32;
|
|
1981
|
+
ok(
|
|
1982
|
+
startContainer !== endContainer,
|
|
1983
|
+
`Large field ${field.name} fits in single container - logic error`
|
|
1984
|
+
);
|
|
1985
|
+
ok(
|
|
1986
|
+
endContainer - startContainer === 1,
|
|
1987
|
+
`Fields spanning more than 2 containers (${field.bits} bits) not yet supported`
|
|
1988
|
+
);
|
|
1989
|
+
const bitsInLowerContainer = 32 - startOffset;
|
|
1990
|
+
result.push({
|
|
1991
|
+
object: "set",
|
|
1992
|
+
container: endContainer,
|
|
1993
|
+
child: {
|
|
1994
|
+
object: "value",
|
|
1995
|
+
offset: startOffset,
|
|
1996
|
+
value: `${field.id}_high`
|
|
1997
|
+
}
|
|
1998
|
+
});
|
|
1999
|
+
if (bitsInLowerContainer < 32) {
|
|
2000
|
+
result.push({
|
|
2001
|
+
object: "set",
|
|
2002
|
+
container: endContainer,
|
|
2003
|
+
child: {
|
|
2004
|
+
object: "value",
|
|
2005
|
+
value: `${field.id}_low >>> ${bitsInLowerContainer}`
|
|
2006
|
+
}
|
|
2007
|
+
});
|
|
2008
|
+
}
|
|
2009
|
+
if (field.bits > 32) {
|
|
2010
|
+
result.push({
|
|
2011
|
+
object: "set",
|
|
2012
|
+
container: startContainer,
|
|
2013
|
+
child: {
|
|
2014
|
+
object: "value",
|
|
2015
|
+
offset: startOffset,
|
|
2016
|
+
value: `${field.id}_low`
|
|
2017
|
+
}
|
|
2018
|
+
});
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
function buildFieldsInfo$1(fields, totalBits) {
|
|
2022
|
+
const result = [];
|
|
2023
|
+
let currentBitPosition = totalBits;
|
|
2024
|
+
fields.forEach((field, idx) => {
|
|
2025
|
+
const startBit = currentBitPosition - field.bits;
|
|
2026
|
+
const endBit = currentBitPosition - 1;
|
|
2027
|
+
result.push({
|
|
2028
|
+
id: `f_${idx}`,
|
|
2029
|
+
...field,
|
|
2030
|
+
startBit,
|
|
2031
|
+
endBit,
|
|
2032
|
+
mask: Math.pow(2, field.bits) - 1
|
|
2033
|
+
});
|
|
2034
|
+
currentBitPosition -= field.bits;
|
|
2035
|
+
});
|
|
2036
|
+
return result;
|
|
2037
|
+
}
|
|
2038
|
+
|
|
2039
|
+
function bitUnpack(options) {
|
|
2040
|
+
notEmpty(options.fields, "fields cannot be empty");
|
|
2041
|
+
greaterThan(options.totalBits, 0, "totalBits must be greater than 0");
|
|
2042
|
+
const fields = buildFieldsInfo(options.fields, options.totalBits);
|
|
2043
|
+
const fnBigIntCode = [`return ${compileFields(fields)};`].join("\n");
|
|
2044
|
+
const fnBigInt = createFunction(
|
|
2045
|
+
"bigint",
|
|
2046
|
+
fnBigIntCode,
|
|
2047
|
+
"data"
|
|
2048
|
+
);
|
|
2049
|
+
const fnNumberCode = [
|
|
2050
|
+
"\n// Extract container from number",
|
|
2051
|
+
"data = BigInt(data);",
|
|
2052
|
+
"\n// Return result",
|
|
2053
|
+
`return ${compileFields(fields)};`
|
|
2054
|
+
].join("\n");
|
|
2055
|
+
const fnNumber = createFunction(
|
|
2056
|
+
"number",
|
|
2057
|
+
fnNumberCode,
|
|
2058
|
+
"data"
|
|
2059
|
+
);
|
|
2060
|
+
const fnBufferCode = [
|
|
2061
|
+
"\n// Extract bytes from buffer (big-endian)",
|
|
2062
|
+
extractBigIntFromBuffer(options.totalBits),
|
|
2063
|
+
"\n// Return result",
|
|
2064
|
+
`return ${compileFields(fields)};`
|
|
2065
|
+
].join("\n");
|
|
2066
|
+
const fnBuffer = createFunction(
|
|
2067
|
+
"buffer",
|
|
2068
|
+
fnBufferCode,
|
|
2069
|
+
"data"
|
|
2070
|
+
);
|
|
2071
|
+
const fnBitsCode = [
|
|
2072
|
+
"\n// Convert bits string to bigint",
|
|
2073
|
+
'var data = BigInt("0b" + bits);',
|
|
2074
|
+
"\n// Return result",
|
|
2075
|
+
`return ${compileFields(fields)};`
|
|
2076
|
+
].join("\n");
|
|
2077
|
+
const fnBits = createFunction("bits", fnBitsCode, "bits");
|
|
2078
|
+
if (!options.debug) {
|
|
2079
|
+
def(fnBuffer, "code", void 0);
|
|
2080
|
+
def(fnBigInt, "code", void 0);
|
|
2081
|
+
def(fnNumber, "code", void 0);
|
|
2082
|
+
def(fnBits, "code", void 0);
|
|
2083
|
+
}
|
|
2084
|
+
return {
|
|
2085
|
+
buffer: fnBuffer,
|
|
2086
|
+
bigint: fnBigInt,
|
|
2087
|
+
number: fnNumber,
|
|
2088
|
+
bits: fnBits
|
|
2089
|
+
};
|
|
2090
|
+
}
|
|
2091
|
+
function compileFields(fields) {
|
|
2092
|
+
const lines = ["{"];
|
|
2093
|
+
for (const field of fields) {
|
|
2094
|
+
if (field.startBit === 0) {
|
|
2095
|
+
lines.push(
|
|
2096
|
+
` ['${field.name}']: Number(data & 0x${field.mask.toString(16)}n),`
|
|
2097
|
+
);
|
|
2098
|
+
} else {
|
|
2099
|
+
lines.push(
|
|
2100
|
+
` ['${field.name}']: Number((data >> ${field.startBit}n) & 0x${field.mask.toString(16)}n),`
|
|
2101
|
+
);
|
|
2102
|
+
}
|
|
2103
|
+
}
|
|
2104
|
+
lines.push("}");
|
|
2105
|
+
return lines.join("\n");
|
|
2106
|
+
}
|
|
2107
|
+
function extractBigIntFromBuffer(totalBits) {
|
|
2108
|
+
const totalBytes = Math.ceil(totalBits / 8);
|
|
2109
|
+
const chunks = [];
|
|
2110
|
+
let byteIndex = 0;
|
|
2111
|
+
let remainingBytes = totalBytes;
|
|
2112
|
+
while (remainingBytes > 0) {
|
|
2113
|
+
if (remainingBytes >= 4) {
|
|
2114
|
+
const shift = (remainingBytes - 4) * 8;
|
|
2115
|
+
const chunk = `((data[${byteIndex}] << 24) | (data[${byteIndex + 1}] << 16) | (data[${byteIndex + 2}] << 8) | data[${byteIndex + 3}]) >>> 0`;
|
|
2116
|
+
if (shift === 0) {
|
|
2117
|
+
chunks.push(`BigInt(${chunk})`);
|
|
2118
|
+
} else {
|
|
2119
|
+
chunks.push(`(BigInt(${chunk}) << ${shift}n)`);
|
|
2120
|
+
}
|
|
2121
|
+
byteIndex += 4;
|
|
2122
|
+
remainingBytes -= 4;
|
|
2123
|
+
} else {
|
|
2124
|
+
let chunk;
|
|
2125
|
+
if (remainingBytes === 3) {
|
|
2126
|
+
chunk = `(data[${byteIndex}] << 16) | (data[${byteIndex + 1}] << 8) | data[${byteIndex + 2}]`;
|
|
2127
|
+
} else if (remainingBytes === 2) {
|
|
2128
|
+
chunk = `(data[${byteIndex}] << 8) | data[${byteIndex + 1}]`;
|
|
2129
|
+
} else {
|
|
2130
|
+
chunk = `data[${byteIndex}]`;
|
|
2131
|
+
}
|
|
2132
|
+
chunks.push(`BigInt(${chunk})`);
|
|
2133
|
+
remainingBytes = 0;
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
return `data =
|
|
2137
|
+
${chunks.join("\n | ")};`;
|
|
2138
|
+
}
|
|
2139
|
+
function buildFieldsInfo(fields, totalBits) {
|
|
2140
|
+
const result = [];
|
|
2141
|
+
let currentBitPosition = totalBits;
|
|
2142
|
+
fields.forEach((field, idx) => {
|
|
2143
|
+
const startBit = currentBitPosition - field.bits;
|
|
2144
|
+
const endBit = currentBitPosition - 1;
|
|
2145
|
+
result.push({
|
|
2146
|
+
id: `f_${idx}`,
|
|
2147
|
+
...field,
|
|
2148
|
+
mask: (1n << BigInt(field.bits)) - 1n,
|
|
2149
|
+
startBit,
|
|
2150
|
+
endBit
|
|
2151
|
+
});
|
|
2152
|
+
currentBitPosition -= field.bits;
|
|
2153
|
+
});
|
|
2154
|
+
return result;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
1725
2157
|
function bytesToBase64(data, { encoding = "base64", padding } = {}) {
|
|
1726
2158
|
if (encoding === "base64") {
|
|
1727
2159
|
return base64.encode(data, { includePadding: padding ?? true });
|
|
@@ -2854,15 +3286,6 @@ function captureStackTrace(till) {
|
|
|
2854
3286
|
return (err.stack || "").slice(6);
|
|
2855
3287
|
}
|
|
2856
3288
|
|
|
2857
|
-
function toError(value, unknownMessage = "Unknown error") {
|
|
2858
|
-
if (isError(value)) {
|
|
2859
|
-
return value;
|
|
2860
|
-
}
|
|
2861
|
-
const error = new Error(unknownMessage, { cause: value });
|
|
2862
|
-
Error.captureStackTrace(error, toError);
|
|
2863
|
-
return error;
|
|
2864
|
-
}
|
|
2865
|
-
|
|
2866
3289
|
function catchError(fn) {
|
|
2867
3290
|
try {
|
|
2868
3291
|
const res = fn();
|
|
@@ -5576,5 +5999,5 @@ function withResolve(fn, getCacheKey) {
|
|
|
5576
5999
|
}
|
|
5577
6000
|
}
|
|
5578
6001
|
|
|
5579
|
-
export { AppError, AsyncIterableQueue, BrowserAssertionError, CancellablePromise, ColorParser, instance as EJSON, EJSON as EJSONInstance, EJSONStream, FindMean, FixedMap, FixedWeakMap, LruCache, Queue, ResourcePool, SimpleEventEmitter, SortedArray, TWEMOJI_REGEX, TimeBucket, TimeSpan, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, avgCircular, base62, base62Fast, base64, base64ToBytes, base64url, basex, bigIntBytes, bigIntFromBytes, blendColors, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createRandomizer, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dateInDays, dateInSeconds, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getMostSpecificPaths, getRandomInt, getRandomTime, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, interpolateColor, intersection, intersectionBy, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDef, isEmpty, isEqual, isError, isFunction, isInfinity, isMap, isNode, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, loggerSetLevel, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, secondsToHm, set, shuffle, snakeCase, sprintf, startCase, strAssign, sum, textDecoder, textEncoder, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, uint16ToUint8, uint32ToUint8, uint8ToUint16, uint8ToUint32, unflatten, union, uniq, uniqBy, unset, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, withResolve, wrapText };
|
|
6002
|
+
export { AppError, AsyncIterableQueue, BrowserAssertionError, CancellablePromise, ColorParser, instance as EJSON, EJSON as EJSONInstance, EJSONStream, FindMean, FixedMap, FixedWeakMap, LruCache, Queue, ResourcePool, SimpleEventEmitter, SortedArray, TWEMOJI_REGEX, TimeBucket, TimeSpan, alpha, arrayable, assert, asyncFilter, asyncFind, asyncForEach, asyncMap, avg, avgCircular, base62, base62Fast, base64, base64ToBytes, base64url, basex, bigIntBytes, bigIntFromBytes, bitPack, bitUnpack, blendColors, buildCssColor, bytesToBase64, cache, cacheBucket, cacheFixed, cacheLRU, camelCase, capitalize, captureStackTrace, catchError, channelsToHSL, channelsToHex, channelsToRGB, checkBitmask, chunk, chunkSeries, clamp, cleanEmpty, cleanObject, colorToChannels, compareBytes, concatenateBytes, contrastRatio, convertToUnit, crc32, createCustomizer, createCustomizerFactory, createDateObject, createDeepCloneWith, createEJSON, createEJSONStream, createEnvParser, createFunction, createRandomizer, createSecureCustomizer, createTimeObject, createTimeSpan, createWithCache, cssVariable, dateInDays, dateInSeconds, debounce, deepAssign, deepClone, deepCloneWith, deepDefaults, deepFreeze, def, defer, delay, difference, dropCache, env, escapeHtml, escapeNumeric, escapeRegExp, fastIdle, fastIdlePromise, fastRaf, findMean, flagsToMap, flatten, formatMoney, formatNumber, get, getFileExtension, getFileName, getInitials, getMostSpecificPaths, getRandomInt, getRandomTime, getWords, groupBy, has, hasOwn, hasProtocol, hex, hexToChannels, hmToSeconds, hslToChannels, humanFileSize, humanize, interpolateColor, intersection, intersectionBy, isBigInt, isBoolean, isCached, isClient, isColorChannels, isCustomizerFactory, isDate, isDateObject, isDef, isEmpty, isEqual, isError, isFunction, isInfinity, isMap, isNode, isNullOrUndefined, isNumber, isObject, isOneEmoji, isPlainObject, isPrimitive, isPromise, isRegExp, isSet, isSkip, isString, isSuccess, isSymbol, isTimeObject, isTimeString, isTimeValue, isValidWeekDay, isWeakMap, isWeakSet, isWithCache, isoToFlagEmoji, kebabCase, keyBy, logger, loggerSetLevel, lowerCase, luminance, maskingEmail, maskingPhone, maskingWords, nextTickIteration, noop, objectId, omit, omitPrefixed, orderBy, parseAllNumbers, parseAlpha, parsePercentage, percentOf, pick, pickPrefixed, qs, rafPromise, randomString, removeVS16s, retryOnError, rgbToChannels, round2digits, secondsToHm, set, shuffle, snakeCase, sprintf, startCase, strAssign, sum, textDecoder, textEncoder, throttle, timeFromMinutes, timeStringify, timeToMinutes, timeout, timestamp, timestampMs, timestampToDate, tintedTextColor, toError, toMap, truncate, typeOf, uint16ToUint8, uint32ToUint8, uint8ToUint16, uint8ToUint32, unflatten, union, uniq, uniqBy, unset, weeksInYear, weightedRoundRobin, withCache, withCacheBucket, withCacheBucketBatch, withCacheFixed, withCacheLRU, withDeepClone, withPointerCache, withResolve, wrapText };
|
|
5580
6003
|
//# sourceMappingURL=index.mjs.map
|