@stryke/helpers 0.1.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/LICENSE +201 -0
- package/README.md +295 -0
- package/dist/arg-identity.cjs +9 -0
- package/dist/arg-identity.d.ts +10 -0
- package/dist/arg-identity.mjs +1 -0
- package/dist/debounce.cjs +24 -0
- package/dist/debounce.d.ts +41 -0
- package/dist/debounce.mjs +1 -0
- package/dist/deep-clone.cjs +61 -0
- package/dist/deep-clone.d.ts +63 -0
- package/dist/deep-clone.mjs +1 -0
- package/dist/deep-merge.cjs +35 -0
- package/dist/deep-merge.d.ts +12 -0
- package/dist/deep-merge.mjs +1 -0
- package/dist/delay.cjs +28 -0
- package/dist/delay.d.ts +72 -0
- package/dist/delay.mjs +1 -0
- package/dist/errors.cjs +18 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.mjs +1 -0
- package/dist/flatten-object.cjs +20 -0
- package/dist/flatten-object.d.ts +33 -0
- package/dist/flatten-object.mjs +1 -0
- package/dist/get-field.cjs +41 -0
- package/dist/get-field.d.ts +251 -0
- package/dist/get-field.mjs +1 -0
- package/dist/get-ordered-by.cjs +18 -0
- package/dist/get-ordered-by.d.ts +36 -0
- package/dist/get-ordered-by.mjs +1 -0
- package/dist/get-unique.cjs +17 -0
- package/dist/get-unique.d.ts +22 -0
- package/dist/get-unique.mjs +1 -0
- package/dist/identity.cjs +9 -0
- package/dist/identity.d.ts +15 -0
- package/dist/identity.mjs +1 -0
- package/dist/index.cjs +280 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.mjs +1 -0
- package/dist/is-equal.cjs +60 -0
- package/dist/is-equal.d.ts +18 -0
- package/dist/is-equal.mjs +1 -0
- package/dist/is-production.cjs +12 -0
- package/dist/is-production.d.ts +30 -0
- package/dist/is-production.mjs +1 -0
- package/dist/is-runtime-server.cjs +10 -0
- package/dist/is-runtime-server.d.ts +11 -0
- package/dist/is-runtime-server.mjs +1 -0
- package/dist/match-sorter.cjs +184 -0
- package/dist/match-sorter.d.ts +77 -0
- package/dist/match-sorter.mjs +1 -0
- package/dist/noop.cjs +10 -0
- package/dist/noop.d.ts +18 -0
- package/dist/noop.mjs +1 -0
- package/dist/remove-accents.cjs +411 -0
- package/dist/remove-accents.d.ts +8 -0
- package/dist/remove-accents.mjs +1 -0
- package/dist/remove-empty-items.cjs +8 -0
- package/dist/remove-empty-items.d.ts +7 -0
- package/dist/remove-empty-items.mjs +1 -0
- package/dist/set-field.cjs +20 -0
- package/dist/set-field.d.ts +10 -0
- package/dist/set-field.mjs +1 -0
- package/dist/throttle.cjs +13 -0
- package/dist/throttle.d.ts +28 -0
- package/dist/throttle.mjs +1 -0
- package/dist/timeout.cjs +11 -0
- package/dist/timeout.d.ts +8 -0
- package/dist/timeout.mjs +1 -0
- package/dist/to-deep-key.cjs +14 -0
- package/dist/to-deep-key.d.ts +35 -0
- package/dist/to-deep-key.mjs +1 -0
- package/dist/to-path.cjs +23 -0
- package/dist/to-path.d.ts +18 -0
- package/dist/to-path.mjs +1 -0
- package/dist/unflatten-object.cjs +10 -0
- package/dist/unflatten-object.d.ts +33 -0
- package/dist/unflatten-object.mjs +1 -0
- package/dist/union.cjs +10 -0
- package/dist/union.d.ts +20 -0
- package/dist/union.mjs +1 -0
- package/dist/with-timeout.cjs +10 -0
- package/dist/with-timeout.d.ts +20 -0
- package/dist/with-timeout.mjs +1 -0
- package/package.json +423 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const characterMap={\u00C0:"A",\u00C1:"A",\u00C2:"A",\u00C3:"A",\u00C4:"A",\u00C5:"A",\u1EA4:"A",\u1EAE:"A",\u1EB2:"A",\u1EB4:"A",\u1EB6:"A",\u00C6:"AE",\u1EA6:"A",\u1EB0:"A",\u0202:"A",\u00C7:"C",\u1E08:"C",\u00C8:"E",\u00C9:"E",\u00CA:"E",\u00CB:"E",\u1EBE:"E",\u1E16:"E",\u1EC0:"E",\u1E14:"E",\u1E1C:"E",\u0206:"E",\u00CC:"I",\u00CD:"I",\u00CE:"I",\u00CF:"I",\u1E2E:"I",\u020A:"I",\u00D0:"D",\u00D1:"N",\u00D2:"O",\u00D3:"O",\u00D4:"O",\u00D5:"O",\u00D6:"O",\u00D8:"O",\u1ED0:"O",\u1E4C:"O",\u1E52:"O",\u020E:"O",\u00D9:"U",\u00DA:"U",\u00DB:"U",\u00DC:"U",\u00DD:"Y",\u00E0:"a",\u00E1:"a",\u00E2:"a",\u00E3:"a",\u00E4:"a",\u00E5:"a",\u1EA5:"a",\u1EAF:"a",\u1EB3:"a",\u1EB5:"a",\u1EB7:"a",\u00E6:"ae",\u1EA7:"a",\u1EB1:"a",\u0203:"a",\u00E7:"c",\u1E09:"c",\u00E8:"e",\u00E9:"e",\u00EA:"e",\u00EB:"e",\u1EBF:"e",\u1E17:"e",\u1EC1:"e",\u1E15:"e",\u1E1D:"e",\u0207:"e",\u00EC:"i",\u00ED:"i",\u00EE:"i",\u00EF:"i",\u1E2F:"i",\u020B:"i",\u00F0:"d",\u00F1:"n",\u00F2:"o",\u00F3:"o",\u00F4:"o",\u00F5:"o",\u00F6:"o",\u00F8:"o",\u1ED1:"o",\u1E4D:"o",\u1E53:"o",\u020F:"o",\u00F9:"u",\u00FA:"u",\u00FB:"u",\u00FC:"u",\u00FD:"y",\u00FF:"y",\u0100:"A",\u0101:"a",\u0102:"A",\u0103:"a",\u0104:"A",\u0105:"a",\u0106:"C",\u0107:"c",\u0108:"C",\u0109:"c",\u010A:"C",\u010B:"c",\u010C:"C",\u010D:"c",C\u0306:"C",c\u0306:"c",\u010E:"D",\u010F:"d",\u0110:"D",\u0111:"d",\u0112:"E",\u0113:"e",\u0114:"E",\u0115:"e",\u0116:"E",\u0117:"e",\u0118:"E",\u0119:"e",\u011A:"E",\u011B:"e",\u011C:"G",\u01F4:"G",\u011D:"g",\u01F5:"g",\u011E:"G",\u011F:"g",\u0120:"G",\u0121:"g",\u0122:"G",\u0123:"g",\u0124:"H",\u0125:"h",\u0126:"H",\u0127:"h",\u1E2A:"H",\u1E2B:"h",\u0128:"I",\u0129:"i",\u012A:"I",\u012B:"i",\u012C:"I",\u012D:"i",\u012E:"I",\u012F:"i",\u0130:"I",\u0131:"i",\u0132:"IJ",\u0133:"ij",\u0134:"J",\u0135:"j",\u0136:"K",\u0137:"k",\u1E30:"K",\u1E31:"k",K\u0306:"K",k\u0306:"k",\u0139:"L",\u013A:"l",\u013B:"L",\u013C:"l",\u013D:"L",\u013E:"l",\u013F:"L",\u0140:"l",\u0141:"l",\u0142:"l",\u1E3E:"M",\u1E3F:"m",M\u0306:"M",m\u0306:"m",\u0143:"N",\u0144:"n",\u0145:"N",\u0146:"n",\u0147:"N",\u0148:"n",\u0149:"n",N\u0306:"N",n\u0306:"n",\u014C:"O",\u014D:"o",\u014E:"O",\u014F:"o",\u0150:"O",\u0151:"o",\u0152:"OE",\u0153:"oe",P\u0306:"P",p\u0306:"p",\u0154:"R",\u0155:"r",\u0156:"R",\u0157:"r",\u0158:"R",\u0159:"r",R\u0306:"R",r\u0306:"r",\u0212:"R",\u0213:"r",\u015A:"S",\u015B:"s",\u015C:"S",\u015D:"s",\u015E:"S",\u0218:"S",\u0219:"s",\u015F:"s",\u0160:"S",\u0161:"s",\u0162:"T",\u0163:"t",\u021B:"t",\u021A:"T",\u0164:"T",\u0165:"t",\u0166:"T",\u0167:"t",T\u0306:"T",t\u0306:"t",\u0168:"U",\u0169:"u",\u016A:"U",\u016B:"u",\u016C:"U",\u016D:"u",\u016E:"U",\u016F:"u",\u0170:"U",\u0171:"u",\u0172:"U",\u0173:"u",\u0216:"U",\u0217:"u",V\u0306:"V",v\u0306:"v",\u0174:"W",\u0175:"w",\u1E82:"W",\u1E83:"w",X\u0306:"X",x\u0306:"x",\u0176:"Y",\u0177:"y",\u0178:"Y",Y\u0306:"Y",y\u0306:"y",\u0179:"Z",\u017A:"z",\u017B:"Z",\u017C:"z",\u017D:"Z",\u017E:"z",\u017F:"s",\u0192:"f",\u01A0:"O",\u01A1:"o",\u01AF:"U",\u01B0:"u",\u01CD:"A",\u01CE:"a",\u01CF:"I",\u01D0:"i",\u01D1:"O",\u01D2:"o",\u01D3:"U",\u01D4:"u",\u01D5:"U",\u01D6:"u",\u01D7:"U",\u01D8:"u",\u01D9:"U",\u01DA:"u",\u01DB:"U",\u01DC:"u",\u1EE8:"U",\u1EE9:"u",\u1E78:"U",\u1E79:"u",\u01FA:"A",\u01FB:"a",\u01FC:"AE",\u01FD:"ae",\u01FE:"O",\u01FF:"o",\u00DE:"TH",\u00FE:"th",\u1E54:"P",\u1E55:"p",\u1E64:"S",\u1E65:"s",X\u0301:"X",x\u0301:"x",\u0403:"\u0413",\u0453:"\u0433",\u040C:"\u041A",\u045C:"\u043A",A\u030B:"A",a\u030B:"a",E\u030B:"E",e\u030B:"e",I\u030B:"I",i\u030B:"i",\u01F8:"N",\u01F9:"n",\u1ED2:"O",\u1ED3:"o",\u1E50:"O",\u1E51:"o",\u1EEA:"U",\u1EEB:"u",\u1E80:"W",\u1E81:"w",\u1EF2:"Y",\u1EF3:"y",\u0200:"A",\u0201:"a",\u0204:"E",\u0205:"e",\u0208:"I",\u0209:"i",\u020C:"O",\u020D:"o",\u0210:"R",\u0211:"r",\u0214:"U",\u0215:"u",B\u030C:"B",b\u030C:"b",\u010C\u0323:"C",\u010D\u0323:"c",\u00CA\u030C:"E",\u00EA\u030C:"e",F\u030C:"F",f\u030C:"f",\u01E6:"G",\u01E7:"g",\u021E:"H",\u021F:"h",J\u030C:"J",\u01F0:"j",\u01E8:"K",\u01E9:"k",M\u030C:"M",m\u030C:"m",P\u030C:"P",p\u030C:"p",Q\u030C:"Q",q\u030C:"q",\u0158\u0329:"R",\u0159\u0329:"r",\u1E66:"S",\u1E67:"s",V\u030C:"V",v\u030C:"v",W\u030C:"W",w\u030C:"w",X\u030C:"X",x\u030C:"x",Y\u030C:"Y",y\u030C:"y",A\u0327:"A",a\u0327:"a",B\u0327:"B",b\u0327:"b",\u1E10:"D",\u1E11:"d",\u0228:"E",\u0229:"e",\u0190\u0327:"E",\u025B\u0327:"e",\u1E28:"H",\u1E29:"h",I\u0327:"I",i\u0327:"i",\u0197\u0327:"I",\u0268\u0327:"i",M\u0327:"M",m\u0327:"m",O\u0327:"O",o\u0327:"o",Q\u0327:"Q",q\u0327:"q",U\u0327:"U",u\u0327:"u",X\u0327:"X",x\u0327:"x",Z\u0327:"Z",z\u0327:"z"};const o=Object.keys(characterMap).join("|"),A=new RegExp(o,"g");export const removeAccents=e=>e.replace(A,a=>characterMap[a]);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const removeEmptyItems=e=>e.filter(Boolean);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.setField = setField;
|
|
7
|
+
var _types = require("@stryke/types");
|
|
8
|
+
var _toPath = require("./to-path.cjs");
|
|
9
|
+
function setField(i, t, s) {
|
|
10
|
+
const r = Array.isArray(t) ? t : (0, _types.isString)(t) ? (0, _toPath.toPath)(t) : [t];
|
|
11
|
+
for (const e of r) if (e === "__proto__" || e === "constructor" || e === "prototype") throw new Error("Invalid key in path: " + e);
|
|
12
|
+
let n = i;
|
|
13
|
+
for (let e = 0; e < r.length - 1; e++) {
|
|
14
|
+
const o = r[e],
|
|
15
|
+
y = r[e + 1];
|
|
16
|
+
n[o] === null && (n[o] = (0, _types.isObjectIndex)(y) ? [] : {}), n = n[o];
|
|
17
|
+
}
|
|
18
|
+
const c = r.at(-1);
|
|
19
|
+
return c && (n[c] = s), i;
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type DeepKey } from "@stryke/types";
|
|
2
|
+
/**
|
|
3
|
+
* Sets a value at a given deep path in an object.
|
|
4
|
+
*
|
|
5
|
+
* @param object - The object to set the value in.
|
|
6
|
+
* @param path - The deep path to set the value at.
|
|
7
|
+
* @param value - The value to set.
|
|
8
|
+
* @returns The object with the value set at the given deep path.
|
|
9
|
+
*/
|
|
10
|
+
export declare function setField<TObject extends Record<string, any> = Record<string, any>>(object: TObject, path: DeepKey<TObject>, value: unknown): TObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isObjectIndex as f,isString as l}from"@stryke/types";import{toPath as a}from"./to-path";export function setField(i,t,s){const r=Array.isArray(t)?t:l(t)?a(t):[t];for(const e of r)if(e==="__proto__"||e==="constructor"||e==="prototype")throw new Error("Invalid key in path: "+e);let n=i;for(let e=0;e<r.length-1;e++){const o=r[e],y=r[e+1];n[o]===null&&(n[o]=f(y)?[]:{}),n=n[o]}const c=r.at(-1);return c&&(n[c]=s),i}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.throttle = throttle;
|
|
7
|
+
function throttle(e, o) {
|
|
8
|
+
let t;
|
|
9
|
+
return (...l) => {
|
|
10
|
+
const n = Date.now();
|
|
11
|
+
(t == null || n - t >= o) && (t = n, e(...l));
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a throttled function that only invokes the provided function at most once
|
|
3
|
+
* per every `throttleMs` milliseconds. Subsequent calls to the throttled function
|
|
4
|
+
* within the wait time will not trigger the execution of the original function.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* const throttledFunction = throttle(() => {
|
|
9
|
+
* console.log('Function executed');
|
|
10
|
+
* }, 1000);
|
|
11
|
+
*
|
|
12
|
+
* // Will log 'Function executed' immediately
|
|
13
|
+
* throttledFunction();
|
|
14
|
+
*
|
|
15
|
+
* // Will not log anything as it is within the throttle time
|
|
16
|
+
* throttledFunction();
|
|
17
|
+
*
|
|
18
|
+
* // After 1 second
|
|
19
|
+
* setTimeout(() => {
|
|
20
|
+
* throttledFunction(); // Will log 'Function executed'
|
|
21
|
+
* }, 1000);
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param func - The function to throttle.
|
|
25
|
+
* @param throttleMs - The number of milliseconds to throttle executions to.
|
|
26
|
+
* @returns A new throttled function that accepts the same parameters as the original function.
|
|
27
|
+
*/
|
|
28
|
+
export declare function throttle<F extends (...args: any[]) => void>(func: F, throttleMs: number): F;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function throttle(e,o){let t;return(...l)=>{const n=Date.now();(t==null||n-t>=o)&&(t=n,e(...l))}}
|
package/dist/timeout.cjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.timeout = timeout;
|
|
7
|
+
var _delay = require("./delay.cjs");
|
|
8
|
+
var _errors = require("./errors.cjs");
|
|
9
|
+
async function timeout(r) {
|
|
10
|
+
throw await (0, _delay.delay)(r), new _errors.TimeoutError();
|
|
11
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a promise that rejects with a `TimeoutError` after a specified delay.
|
|
3
|
+
*
|
|
4
|
+
* @param ms - The delay duration in milliseconds.
|
|
5
|
+
* @returns A promise that rejects with a `TimeoutError` after the specified delay.
|
|
6
|
+
* @throws Throws a `TimeoutError` after the specified delay.
|
|
7
|
+
*/
|
|
8
|
+
export declare function timeout(ms: number): Promise<never>;
|
package/dist/timeout.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{delay as o}from"./delay";import{TimeoutError as e}from"./errors";export async function timeout(r){throw await o(r),new e}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.addPathToDeepKey = addPathToDeepKey;
|
|
7
|
+
exports.toDeepKey = toDeepKey;
|
|
8
|
+
var _types = require("@stryke/types");
|
|
9
|
+
function toDeepKey(n) {
|
|
10
|
+
return n.reduce((r, t) => addPathToDeepKey(r, t));
|
|
11
|
+
}
|
|
12
|
+
function addPathToDeepKey(n, r) {
|
|
13
|
+
return (0, _types.isNumber)(r) || Number.isInteger(r) ? n + `[${r}]` : (0, _types.isSetString)(r) ? n + `.${r}` : n;
|
|
14
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts an array of path segments into a deep key string.
|
|
3
|
+
*
|
|
4
|
+
* This function takes an array of strings and numbers representing path segments and combines them into a deep key string.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* toDeepKey(['a', 'b', 'c']) // Returns 'a.b.c'
|
|
8
|
+
* toDeepKey(['a', 0, 'c']) // Returns 'a[0].c'
|
|
9
|
+
* toDeepKey(['', 'a', 'b', 'c']) // Returns '.a.b.c'
|
|
10
|
+
* toDeepKey(['a', 'b.c', 'd']) // Returns 'a.b.c.d'
|
|
11
|
+
* toDeepKey([]) // Returns ''
|
|
12
|
+
* toDeepKey(['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']) // Returns '.a.b.c.d.e.f.g.h'
|
|
13
|
+
*
|
|
14
|
+
* @param path - An array of strings and numbers representing path segments.
|
|
15
|
+
* @returns A deep key string.
|
|
16
|
+
*/
|
|
17
|
+
export declare function toDeepKey(path: string[]): string;
|
|
18
|
+
/**
|
|
19
|
+
* Adds a path segment to a deep key string.
|
|
20
|
+
*
|
|
21
|
+
* This function takes a deep key string and a path segment and combines them into a new deep key string.
|
|
22
|
+
*
|
|
23
|
+
* @param deepKey - The deep key string to add the path segment to.
|
|
24
|
+
* @param path - The path segment to add to the deep key string.
|
|
25
|
+
* @returns A new deep key string.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* addPathToDeepKey('a.b', 'c') // Returns 'a.b.c'
|
|
29
|
+
* addPathToDeepKey('a[0]', 'c') // Returns 'a[0].c'
|
|
30
|
+
* addPathToDeepKey('.a.b', 'c') // Returns '.a.b.c'
|
|
31
|
+
* addPathToDeepKey('a.b', 'b.c') // Returns 'a.b.b.c'
|
|
32
|
+
* addPathToDeepKey('', 'a') // Returns 'a'
|
|
33
|
+
* addPathToDeepKey('.a.b', 'c.d') // Returns '.a.b.c.d'
|
|
34
|
+
*/
|
|
35
|
+
export declare function addPathToDeepKey(deepKey: string, path: string | number): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isNumber as e,isSetString as i}from"@stryke/types";export function toDeepKey(n){return n.reduce((r,t)=>addPathToDeepKey(r,t))}export function addPathToDeepKey(n,r){return e(r)||Number.isInteger(r)?n+`[${r}]`:i(r)?n+`.${r}`:n}
|
package/dist/to-path.cjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.toPath = toPath;
|
|
7
|
+
const a = /^[\w.]+$/g,
|
|
8
|
+
E = /\\(?<temp1>\\)?/g,
|
|
9
|
+
e = new RegExp(String.raw`[^.[\]]+` + "|" + String.raw`\[(?:` + `([^"'][^[]*)|` + String.raw`(["'])((?:(?!\2)[^\\]|\\.)*?)\2` + String.raw`)\]` + "|" + String.raw`(?=(?:\.|\[\])(?:\.|\[\]|$))`, "g");
|
|
10
|
+
function toPath(t) {
|
|
11
|
+
if (a.test(t)) return t.split(".");
|
|
12
|
+
const n = [];
|
|
13
|
+
t[0] === "." && n.push("");
|
|
14
|
+
const i = t.matchAll(e);
|
|
15
|
+
for (const r of i) {
|
|
16
|
+
let s = r[0];
|
|
17
|
+
const o = r[1],
|
|
18
|
+
g = r[2],
|
|
19
|
+
c = r[3];
|
|
20
|
+
g && c ? s = c.replace(E, "$1") : o && (s = o), n.push(s);
|
|
21
|
+
}
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts a deep key string into an array of path segments.
|
|
3
|
+
*
|
|
4
|
+
* This function takes a string representing a deep key (e.g., 'a.b.c' or 'a[b][c]') and breaks it down into an array of strings, each representing a segment of the path.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} deepKey - The deep key string to convert.
|
|
7
|
+
* @returns {string[]} An array of strings, each representing a segment of the path.
|
|
8
|
+
*
|
|
9
|
+
* Examples:
|
|
10
|
+
*
|
|
11
|
+
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
|
12
|
+
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
|
13
|
+
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
|
14
|
+
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
|
15
|
+
* toPath('') // Returns []
|
|
16
|
+
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
|
17
|
+
*/
|
|
18
|
+
export declare function toPath(deepKey: string): string[];
|
package/dist/to-path.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const a=/^[\w.]+$/g,E=/\\(?<temp1>\\)?/g,e=new RegExp(String.raw`[^.[\]]+`+"|"+String.raw`\[(?:`+`([^"'][^[]*)|`+String.raw`(["'])((?:(?!\2)[^\\]|\\.)*?)\2`+String.raw`)\]`+"|"+String.raw`(?=(?:\.|\[\])(?:\.|\[\]|$))`,"g");export function toPath(t){if(a.test(t))return t.split(".");const n=[];t[0]==="."&&n.push("");const i=t.matchAll(e);for(const r of i){let s=r[0];const o=r[1],g=r[2],c=r[3];g&&c?s=c.replace(E,"$1"):o&&(s=o),n.push(s)}return n}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.unflattenObject = unflattenObject;
|
|
7
|
+
var _setField = require("./set-field.cjs");
|
|
8
|
+
function unflattenObject(e) {
|
|
9
|
+
return Object.entries(e).reduce((t, [c, n]) => (0, _setField.setField)(t, c, n), {});
|
|
10
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { DeepKey, DeepValue } from "@stryke/types";
|
|
2
|
+
/**
|
|
3
|
+
* Flattens a nested object into a single level object with dot-separated keys.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* const nestedObject = {
|
|
8
|
+
* a: {
|
|
9
|
+
* b: {
|
|
10
|
+
* c: 1
|
|
11
|
+
* }
|
|
12
|
+
* },
|
|
13
|
+
* d: [2, 3]
|
|
14
|
+
* };
|
|
15
|
+
*
|
|
16
|
+
* const flattened = flattenObject(nestedObject);
|
|
17
|
+
* console.log(flattened);
|
|
18
|
+
* // Output:
|
|
19
|
+
* // {
|
|
20
|
+
* // 'a.b.c': 1,
|
|
21
|
+
* // 'd.0': 2,
|
|
22
|
+
* // 'd.1': 3
|
|
23
|
+
* // }
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param object - The object to flatten.
|
|
27
|
+
* @returns - The flattened object.
|
|
28
|
+
*/
|
|
29
|
+
export declare function unflattenObject<TObject extends Record<string, any> = Record<string, any>, TDeepKeyObject extends {
|
|
30
|
+
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
|
|
31
|
+
} = {
|
|
32
|
+
[TKey in DeepKey<TObject>]: DeepValue<TObject, TKey>;
|
|
33
|
+
}>(deepKeyObject: TDeepKeyObject): TObject;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{setField as r}from"./set-field";export function unflattenObject(e){return Object.entries(e).reduce((t,[c,n])=>r(t,c,n),{})}
|
package/dist/union.cjs
ADDED
package/dist/union.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates an array of unique values from all given arrays.
|
|
3
|
+
*
|
|
4
|
+
* @remarks
|
|
5
|
+
* This function takes two arrays, merges them into a single array, and returns a new array
|
|
6
|
+
* containing only the unique values from the merged array.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const array1 = [1, 2, 3];
|
|
11
|
+
* const array2 = [3, 4, 5];
|
|
12
|
+
* const result = union(array1, array2);
|
|
13
|
+
* // result will be [1, 2, 3, 4, 5]
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param arr1 - The first array to merge and filter for unique values.
|
|
17
|
+
* @param arr2 - The second array to merge and filter for unique values.
|
|
18
|
+
* @returns A new array of unique values.
|
|
19
|
+
*/
|
|
20
|
+
export declare function union<T>(arr1: readonly T[], arr2: readonly T[]): T[];
|
package/dist/union.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{getUnique as r}from"./get-unique";export function union(n,o){return r([...n,...o])}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.withTimeout = withTimeout;
|
|
7
|
+
var _timeout = require("./timeout.cjs");
|
|
8
|
+
async function withTimeout(r, e) {
|
|
9
|
+
return Promise.race([r(), (0, _timeout.timeout)(e)]);
|
|
10
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Executes an async function and enforces a timeout.
|
|
3
|
+
*
|
|
4
|
+
* If the promise does not resolve within the specified time,
|
|
5
|
+
* the timeout will trigger and the returned promise will be rejected.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* try {
|
|
10
|
+
* await withTimeout(() => {}, 1000); // Timeout exception after 1 second
|
|
11
|
+
* } catch (error) {
|
|
12
|
+
* console.error(error); // Will log 'TimeoutError'
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @param run - A function that returns a promise to be executed.
|
|
17
|
+
* @param ms - The timeout duration in milliseconds.
|
|
18
|
+
* @returns A promise that resolves with the result of the `run` function or rejects if the timeout is reached.
|
|
19
|
+
*/
|
|
20
|
+
export declare function withTimeout<T>(run: () => Promise<T>, ms: number): Promise<T>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{timeout as o}from"./timeout";export async function withTimeout(r,e){return Promise.race([r(),o(e)])}
|