@stryke/helpers 0.3.1 → 0.4.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/dist/deep-clone.cjs +2 -2
- package/dist/deep-clone.d.ts +1 -1
- package/dist/deep-clone.mjs +1 -1
- package/dist/deep-copy.cjs +5 -5
- package/dist/deep-copy.d.ts +2 -2
- package/dist/deep-copy.mjs +1 -1
- package/dist/deep-merge.cjs +8 -6
- package/dist/deep-merge.mjs +1 -1
- package/dist/delay.cjs +2 -2
- package/dist/delay.mjs +1 -1
- package/dist/filter-empty.cjs +9 -0
- package/dist/filter-empty.d.ts +1 -0
- package/dist/filter-empty.mjs +1 -0
- package/dist/flatten-object.cjs +8 -8
- package/dist/flatten-object.d.ts +1 -1
- package/dist/flatten-object.mjs +1 -1
- package/dist/get-field.cjs +5 -3
- package/dist/get-field.mjs +1 -1
- package/dist/identity.d.ts +0 -1
- package/dist/index.cjs +11 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.mjs +1 -1
- package/dist/is-equal.cjs +29 -28
- package/dist/is-equal.mjs +1 -1
- package/dist/match-sorter.d.ts +2 -2
- package/dist/set-field.cjs +12 -11
- package/dist/set-field.d.ts +1 -1
- package/dist/set-field.mjs +1 -1
- package/dist/to-deep-key.cjs +3 -2
- package/dist/to-deep-key.d.ts +7 -4
- package/dist/to-deep-key.mjs +1 -1
- package/dist/to-path.cjs +1 -1
- package/dist/to-path.d.ts +7 -5
- package/dist/to-path.mjs +1 -1
- package/dist/unflatten-object.d.ts +1 -1
- package/package.json +20 -3
package/dist/deep-clone.cjs
CHANGED
|
@@ -4,8 +4,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deepClone = deepClone;
|
|
7
|
-
var _isPrimitive = require("@stryke/
|
|
8
|
-
var _isTypedArray = require("@stryke/
|
|
7
|
+
var _isPrimitive = require("@stryke/type-checks/is-primitive");
|
|
8
|
+
var _isTypedArray = require("@stryke/type-checks/is-typed-array");
|
|
9
9
|
function deepClone(e) {
|
|
10
10
|
if ((0, _isPrimitive.isPrimitive)(e)) return e;
|
|
11
11
|
if (Array.isArray(e)) return e.map(n => deepClone(n));
|
package/dist/deep-clone.d.ts
CHANGED
|
@@ -13,7 +13,7 @@ type IsTuple<T extends readonly any[] | {
|
|
|
13
13
|
type ValueOf<Instance> = IsValueOf<Instance, boolean> extends true ? boolean : IsValueOf<Instance, number> extends true ? number : IsValueOf<Instance, string> extends true ? string : Instance;
|
|
14
14
|
type IsValueOf<Instance, O extends IValueOf<any>> = Instance extends O ? O extends IValueOf<infer Primitive> ? Instance extends Primitive ? false : true : false : false;
|
|
15
15
|
interface IValueOf<T> {
|
|
16
|
-
valueOf()
|
|
16
|
+
valueOf: () => T;
|
|
17
17
|
}
|
|
18
18
|
/**
|
|
19
19
|
* Creates a deep clone of the given object.
|
package/dist/deep-clone.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isPrimitive as l}from"@stryke/
|
|
1
|
+
import{isPrimitive as l}from"@stryke/type-checks/is-primitive";import{isTypedArray as i}from"@stryke/type-checks/is-typed-array";export function deepClone(e){if(l(e))return e;if(Array.isArray(e))return e.map(n=>deepClone(n));if(e instanceof Date)return new Date(e.getTime());if(e instanceof RegExp)return new RegExp(e.source,e.flags);if(e instanceof Map){const n=new Map;for(const[t,s]of e.entries())n.set(t,deepClone(s));return n}if(e instanceof Set){const n=new Set;for(const t of e.values())n.add(deepClone(t));return n}if(i(e)){const n=new(Object.getPrototypeOf(e)).constructor(e.length);for(const[t,s]of e.entries())n[t]=deepClone(s);return n}if(e instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&e instanceof SharedArrayBuffer)return[...e];if(e instanceof DataView){const n=new DataView([...e.buffer]);return r(e,n),n}if(typeof File<"u"&&e instanceof File){const n=new File([e],e.name,{type:e.type});return r(e,n),n}if(e instanceof Blob){const n=new Blob([e],{type:e.type});return r(e,n),n}if(e instanceof Error){const n=new e.constructor;return n.message=e.message,n.name=e.name,n.stack=e.stack,n.cause=e.cause,r(e,n),n}if(typeof e=="object"&&e!==null){const n={};return r(e,n),n}return e}function r(e,n){const t=Object.keys(e);for(const s of t){const a=Object.getOwnPropertyDescriptor(e,s);(a?.writable||a?.set)&&(n[s]=deepClone(e[s]))}}
|
package/dist/deep-copy.cjs
CHANGED
|
@@ -58,17 +58,17 @@ function e(r) {
|
|
|
58
58
|
if (!n) throw new Error("Unsupported typed array type in `cloneTypedArray`.");
|
|
59
59
|
return new n(t).subarray(r.byteOffset, r.byteOffset + r.length);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function f(r, t, n, o, y) {
|
|
62
62
|
const a = detectType(r),
|
|
63
63
|
i = copy(r, a);
|
|
64
64
|
if (!isCollection(a)) return i;
|
|
65
|
-
const
|
|
66
|
-
for (const s of
|
|
65
|
+
const b = getKeys(r, a);
|
|
66
|
+
for (const s of b) {
|
|
67
67
|
const c = getValue(r, s, a);
|
|
68
68
|
if (o.has(c)) setValue(t, s, n.get(c), a);else {
|
|
69
69
|
const p = detectType(c),
|
|
70
70
|
l = copy(c, p);
|
|
71
|
-
isCollection(p) && (n.set(c, l), o.add(c)), setValue(t, s,
|
|
71
|
+
isCollection(p) && (n.set(c, l), o.add(c)), setValue(t, s, f(c, l, n, o, y), a);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
return t;
|
|
@@ -82,5 +82,5 @@ function deepCopy(r, t) {
|
|
|
82
82
|
const y = copy(r, o, n),
|
|
83
83
|
a = new WeakMap([[r, y]]),
|
|
84
84
|
i = new WeakSet([r]);
|
|
85
|
-
return
|
|
85
|
+
return f(r, y, a, i, n);
|
|
86
86
|
}
|
package/dist/deep-copy.d.ts
CHANGED
package/dist/deep-copy.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function A(r){const t=new ArrayBuffer(r.byteLength);return new Uint8Array(t).set(new Uint8Array(r)),t}function C(r){const t=A(r.buffer);return new DataView(t,r.byteOffset,r.byteLength)}function g(r){return new Date(r.getTime())}function d(r){const t=new Map;for(const[n,o]of r.entries())t.set(deepCopy(n),deepCopy(o));return t}const u={"[object Float32Array]":Float32Array,"[object Float64Array]":Float64Array,"[object Int8Array]":Int8Array,"[object Int16Array]":Int16Array,"[object Int32Array]":Int32Array,"[object Uint8Array]":Uint8Array,"[object Uint16Array]":Uint16Array,"[object Uint32Array]":Uint32Array,"[object Uint8ClampedArray]":Uint8ClampedArray},j={"[object Date]":g,"[object ArrayBuffer]":A,"[object DataView]":C,"[object Float32Array]":e,"[object Float64Array]":e,"[object Int8Array]":e,"[object Int16Array]":e,"[object Int32Array]":e,"[object Uint8Array]":e,"[object Uint8ClampedArray]":e,"[object Uint16Array]":e,"[object Uint32Array]":e,"[object BigInt64Array]":e,"[object BigUint64Array]":e,"[object RegExp]":cloneRegExp,"[object Map]":d};function e(r){try{u["[object BigInt64Array]"]=BigInt64Array,u["[object BigUint64Array]"]=BigUint64Array}catch{}const t=A(r.buffer),n=u[Object.prototype.toString.call(r)];if(!n)throw new Error("Unsupported typed array type in `cloneTypedArray`.");return new n(t).subarray(r.byteOffset,r.byteOffset+r.length)}function
|
|
1
|
+
function A(r){const t=new ArrayBuffer(r.byteLength);return new Uint8Array(t).set(new Uint8Array(r)),t}function C(r){const t=A(r.buffer);return new DataView(t,r.byteOffset,r.byteLength)}function g(r){return new Date(r.getTime())}function d(r){const t=new Map;for(const[n,o]of r.entries())t.set(deepCopy(n),deepCopy(o));return t}const u={"[object Float32Array]":Float32Array,"[object Float64Array]":Float64Array,"[object Int8Array]":Int8Array,"[object Int16Array]":Int16Array,"[object Int32Array]":Int32Array,"[object Uint8Array]":Uint8Array,"[object Uint16Array]":Uint16Array,"[object Uint32Array]":Uint32Array,"[object Uint8ClampedArray]":Uint8ClampedArray},j={"[object Date]":g,"[object ArrayBuffer]":A,"[object DataView]":C,"[object Float32Array]":e,"[object Float64Array]":e,"[object Int8Array]":e,"[object Int16Array]":e,"[object Int32Array]":e,"[object Uint8Array]":e,"[object Uint8ClampedArray]":e,"[object Uint16Array]":e,"[object Uint32Array]":e,"[object BigInt64Array]":e,"[object BigUint64Array]":e,"[object RegExp]":cloneRegExp,"[object Map]":d};function e(r){try{u["[object BigInt64Array]"]=BigInt64Array,u["[object BigUint64Array]"]=BigUint64Array}catch{}const t=A(r.buffer),n=u[Object.prototype.toString.call(r)];if(!n)throw new Error("Unsupported typed array type in `cloneTypedArray`.");return new n(t).subarray(r.byteOffset,r.byteOffset+r.length)}function f(r,t,n,o,y){const a=detectType(r),i=copy(r,a);if(!isCollection(a))return i;const b=getKeys(r,a);for(const s of b){const c=getValue(r,s,a);if(o.has(c))setValue(t,s,n.get(c),a);else{const p=detectType(c),l=copy(c,p);isCollection(p)&&(n.set(c,l),o.add(c)),setValue(t,s,f(c,l,n,o,y),a)}}return t}export function deepCopy(r,t){const{customizer:n=null}=t??{},o=detectType(r);if(!isCollection(o))return copy(r,o,n);const y=copy(r,o,n),a=new WeakMap([[r,y]]),i=new WeakSet([r]);return f(r,y,a,i,n)}
|
package/dist/deep-merge.cjs
CHANGED
|
@@ -4,26 +4,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deepMerge = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _isFunction = require("@stryke/type-checks/is-function");
|
|
8
|
+
var _isMergeableObject = require("@stryke/type-checks/is-mergeable-object");
|
|
9
|
+
var _propertyExists = require("@stryke/type-checks/property-exists");
|
|
8
10
|
const b = e => Array.isArray(e) ? [] : {},
|
|
9
11
|
s = (e, r) => r.clone !== !1 && r.isMergeableObject(e) ? deepMerge(b(e), e, r) : e,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
f = (e, r, n) => [...e, ...r].map(t => s(t, n)),
|
|
13
|
+
l = (e, r) => {
|
|
12
14
|
if (!r.customMerge) return deepMerge;
|
|
13
15
|
const n = r.customMerge(e);
|
|
14
|
-
return (0,
|
|
16
|
+
return (0, _isFunction.isFunction)(n) ? n : deepMerge;
|
|
15
17
|
},
|
|
16
18
|
y = e => [...Object.keys(e), ...(Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(e).filter(r => Object.propertyIsEnumerable.call(e, r)) : [])],
|
|
17
19
|
u = (e, r, n) => {
|
|
18
20
|
const t = {};
|
|
19
21
|
if (n.isMergeableObject(e)) for (const a of y(e)) t[a] = s(e[a], n);
|
|
20
|
-
for (const a of y(r)) t[a] = (0,
|
|
22
|
+
for (const a of y(r)) t[a] = (0, _propertyExists.propertyUnsafe)(e, a) && n.isMergeableObject(r[a]) ? l(a, n)(e[a], r[a], n) : s(r[a], n);
|
|
21
23
|
return t;
|
|
22
24
|
};
|
|
23
25
|
const deepMerge = (e, r, n = {}) => {
|
|
24
26
|
if (!e || !r) return e || r;
|
|
25
27
|
const t = n || {};
|
|
26
|
-
t.arrayMerge = n.arrayMerge ||
|
|
28
|
+
t.arrayMerge = n.arrayMerge || f, t.isMergeableObject = t.isMergeableObject || _isMergeableObject.isMergeableObject, t.cloneUnlessOtherwiseSpecified = s;
|
|
27
29
|
const a = Array.isArray(r),
|
|
28
30
|
c = Array.isArray(e);
|
|
29
31
|
return a === c ? a ? t.arrayMerge(e, r, t) : u(e, r, t) : s(r, t);
|
package/dist/deep-merge.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isFunction as i
|
|
1
|
+
import{isFunction as i}from"@stryke/type-checks/is-function";import{isMergeableObject as o}from"@stryke/type-checks/is-mergeable-object";import{propertyUnsafe as g}from"@stryke/type-checks/property-exists";const b=e=>Array.isArray(e)?[]:{},s=(e,r)=>r.clone!==!1&&r.isMergeableObject(e)?deepMerge(b(e),e,r):e,f=(e,r,n)=>[...e,...r].map(t=>s(t,n)),l=(e,r)=>{if(!r.customMerge)return deepMerge;const n=r.customMerge(e);return i(n)?n:deepMerge},y=e=>[...Object.keys(e),...Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(r=>Object.propertyIsEnumerable.call(e,r)):[]],u=(e,r,n)=>{const t={};if(n.isMergeableObject(e))for(const a of y(e))t[a]=s(e[a],n);for(const a of y(r))t[a]=g(e,a)&&n.isMergeableObject(r[a])?l(a,n)(e[a],r[a],n):s(r[a],n);return t};export const deepMerge=(e,r,n={})=>{if(!e||!r)return e||r;const t=n||{};t.arrayMerge=n.arrayMerge||f,t.isMergeableObject=t.isMergeableObject||o,t.cloneUnlessOtherwiseSpecified=s;const a=Array.isArray(r),c=Array.isArray(e);return a===c?a?t.arrayMerge(e,r,t):u(e,r,t):s(r,t)};deepMerge.all=function(r,n){if(!Array.isArray(r))throw new TypeError("first argument should be an array");return r.reduce((t,a)=>deepMerge(t,a,n),{})};
|
package/dist/delay.cjs
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.delay = delay;
|
|
7
7
|
exports.sleep = sleep;
|
|
8
8
|
var _errors = require("./errors.cjs");
|
|
9
|
-
function delay(r, {
|
|
9
|
+
async function delay(r, {
|
|
10
10
|
signal: e
|
|
11
11
|
} = {}) {
|
|
12
12
|
return new Promise((t, n) => {
|
|
@@ -23,6 +23,6 @@ function delay(r, {
|
|
|
23
23
|
});
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
-
function sleep(r, e) {
|
|
26
|
+
async function sleep(r, e) {
|
|
27
27
|
return delay(r, e);
|
|
28
28
|
}
|
package/dist/delay.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AbortError as s}from"./errors";export function delay(r,{signal:e}={}){return new Promise((t,n)=>{const o=()=>{n(new s)},i=()=>{clearTimeout(a),o()};if(e?.aborted)return o();const a=setTimeout(t,r);e?.addEventListener("abort",i,{once:!0})})}export function sleep(r,e){return delay(r,e)}
|
|
1
|
+
import{AbortError as s}from"./errors";export async function delay(r,{signal:e}={}){return new Promise((t,n)=>{const o=()=>{n(new s)},i=()=>{clearTimeout(a),o()};if(e?.aborted)return o();const a=setTimeout(t,r);e?.addEventListener("abort",i,{once:!0})})}export async function sleep(r,e){return delay(r,e)}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.filterEmpty = void 0;
|
|
7
|
+
var _isEmpty = require("@stryke/type-checks/is-empty");
|
|
8
|
+
const filterEmpty = (t = []) => t.filter(e => !(0, _isEmpty.isEmpty)(e));
|
|
9
|
+
exports.filterEmpty = filterEmpty;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const filterEmpty: <T>(values?: (T | null | undefined)[]) => T[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{isEmpty as i}from"@stryke/type-checks/is-empty";export const filterEmpty=(t=[])=>t.filter(e=>!i(e));
|
package/dist/flatten-object.cjs
CHANGED
|
@@ -4,17 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.flattenObject = flattenObject;
|
|
7
|
-
var
|
|
7
|
+
var _isPlainObject = require("@stryke/type-checks/is-plain-object");
|
|
8
8
|
function flattenObject(t) {
|
|
9
9
|
return T(t);
|
|
10
10
|
}
|
|
11
11
|
function T(t, s = "") {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
for (const
|
|
15
|
-
const e = t[
|
|
16
|
-
y = s ? `${s}.${
|
|
17
|
-
if ((0,
|
|
12
|
+
const c = {},
|
|
13
|
+
b = Object.keys(t);
|
|
14
|
+
for (const n of b) {
|
|
15
|
+
const e = t[n],
|
|
16
|
+
y = s ? `${s}.${n}` : n;
|
|
17
|
+
if ((0, _isPlainObject.isPlainObject)(e) && Object.keys(e).length > 0) Object.assign(c, T(e, y));else if (Array.isArray(e)) for (const [j, O] of e.entries()) c[`${y}.${j}`] = O;else c[y] = e;
|
|
18
18
|
}
|
|
19
|
-
return
|
|
19
|
+
return c;
|
|
20
20
|
}
|
package/dist/flatten-object.d.ts
CHANGED
package/dist/flatten-object.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isPlainObject as
|
|
1
|
+
import{isPlainObject as a}from"@stryke/type-checks/is-plain-object";export function flattenObject(t){return T(t)}function T(t,s=""){const c={},b=Object.keys(t);for(const n of b){const e=t[n],y=s?`${s}.${n}`:n;if(a(e)&&Object.keys(e).length>0)Object.assign(c,T(e,y));else if(Array.isArray(e))for(const[j,O]of e.entries())c[`${y}.${j}`]=O;else c[y]=e}return c}
|
package/dist/get-field.cjs
CHANGED
|
@@ -4,7 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getField = getField;
|
|
7
|
-
var
|
|
7
|
+
var _toStringKey = require("@stryke/convert/to-string-key");
|
|
8
|
+
var _isDeepKey = require("@stryke/type-checks/is-deep-key");
|
|
9
|
+
var _isNumber = require("@stryke/type-checks/is-number");
|
|
8
10
|
var _toPath = require("./to-path.cjs");
|
|
9
11
|
function getField(t, e, d) {
|
|
10
12
|
if (t === null) return d;
|
|
@@ -12,12 +14,12 @@ function getField(t, e, d) {
|
|
|
12
14
|
case "string":
|
|
13
15
|
{
|
|
14
16
|
const n = t[e];
|
|
15
|
-
return n === void 0 ? (0,
|
|
17
|
+
return n === void 0 ? (0, _isDeepKey.isDeepKey)(e) ? getField(t, (0, _toPath.toPath)(e), d) : d : n;
|
|
16
18
|
}
|
|
17
19
|
case "number":
|
|
18
20
|
case "symbol":
|
|
19
21
|
{
|
|
20
|
-
(0,
|
|
22
|
+
(0, _isNumber.isNumber)(e) && (e = (0, _toStringKey.toStringKey)(e));
|
|
21
23
|
const n = Array.isArray(e) ? void 0 : t[e];
|
|
22
24
|
return n === void 0 ? d : n;
|
|
23
25
|
}
|
package/dist/get-field.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{toStringKey as o}from"@stryke/convert/to-string-key";import{isDeepKey as K}from"@stryke/type-checks/is-deep-key";import{isNumber as f}from"@stryke/type-checks/is-number";import{toPath as r}from"./to-path";export function getField(t,e,d){if(t===null)return d;switch(typeof e){case"string":{const n=t[e];return n===void 0?K(e)?getField(t,r(e),d):d:n}case"number":case"symbol":{f(e)&&(e=o(e));const n=Array.isArray(e)?void 0:t[e];return n===void 0?d:n}default:{if(Array.isArray(e))return u(t,e,d);e=Object.is(e?.valueOf(),-0)?"-0":String(e);const n=t[e];return n===void 0?d:n}}}function u(t,e,d){if(e.length===0)return d;let n=t;for(const i of e){if(n===null)return d;n=n[i]}return n===void 0?d:n}
|
package/dist/identity.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -69,6 +69,17 @@ Object.keys(_delay).forEach(function (key) {
|
|
|
69
69
|
}
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
|
+
var _filterEmpty = require("./filter-empty.cjs");
|
|
73
|
+
Object.keys(_filterEmpty).forEach(function (key) {
|
|
74
|
+
if (key === "default" || key === "__esModule") return;
|
|
75
|
+
if (key in exports && exports[key] === _filterEmpty[key]) return;
|
|
76
|
+
Object.defineProperty(exports, key, {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
get: function () {
|
|
79
|
+
return _filterEmpty[key];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
|
72
83
|
var _flattenObject = require("./flatten-object.cjs");
|
|
73
84
|
Object.keys(_flattenObject).forEach(function (key) {
|
|
74
85
|
if (key === "default" || key === "__esModule") return;
|
package/dist/index.d.ts
CHANGED
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./arg-identity";export*from"./debounce";export*from"./deep-clone";export*from"./deep-copy";export*from"./deep-merge";export*from"./delay";export*from"./flatten-object";export*from"./get-field";export*from"./get-ordered-by";export*from"./get-unique";export*from"./identity";export*from"./is-equal";export*from"./match-sorter";export*from"./noop";export*from"./remove-accents";export*from"./remove-empty-items";export*from"./set-field";export*from"./throttle";export*from"./timeout";export*from"./to-deep-key";export*from"./to-path";export*from"./unflatten-object";export*from"./union";export*from"./with-timeout";
|
|
1
|
+
export*from"./arg-identity";export*from"./debounce";export*from"./deep-clone";export*from"./deep-copy";export*from"./deep-merge";export*from"./delay";export*from"./filter-empty";export*from"./flatten-object";export*from"./get-field";export*from"./get-ordered-by";export*from"./get-unique";export*from"./identity";export*from"./is-equal";export*from"./match-sorter";export*from"./noop";export*from"./remove-accents";export*from"./remove-empty-items";export*from"./set-field";export*from"./throttle";export*from"./timeout";export*from"./to-deep-key";export*from"./to-path";export*from"./unflatten-object";export*from"./union";export*from"./with-timeout";
|
package/dist/is-equal.cjs
CHANGED
|
@@ -4,55 +4,56 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isEqual = isEqual;
|
|
7
|
-
var
|
|
7
|
+
var _isSet = require("@stryke/type-checks/is-set");
|
|
8
|
+
var _isSetString = require("@stryke/type-checks/is-set-string");
|
|
8
9
|
const l = typeof Map == "function",
|
|
9
10
|
a = typeof Set == "function",
|
|
10
11
|
c = typeof ArrayBuffer == "function" && !!ArrayBuffer.isView;
|
|
11
|
-
function o(e,
|
|
12
|
-
if (e ===
|
|
13
|
-
if (e &&
|
|
14
|
-
if (e.constructor !==
|
|
12
|
+
function o(e, r) {
|
|
13
|
+
if (e === r) return !0;
|
|
14
|
+
if (e && r && typeof e == "object" && typeof r == "object") {
|
|
15
|
+
if (e.constructor !== r.constructor) return !1;
|
|
15
16
|
let n;
|
|
16
17
|
if (Array.isArray(e)) {
|
|
17
|
-
if (n = e.length, n !=
|
|
18
|
-
for (let
|
|
18
|
+
if (n = e.length, n != r.length) return !1;
|
|
19
|
+
for (let t = n; t-- !== 0;) if (!o(e[t], r[t])) return !1;
|
|
19
20
|
return !0;
|
|
20
21
|
}
|
|
21
22
|
let i;
|
|
22
|
-
if (l && e instanceof Map &&
|
|
23
|
-
if (e.size !==
|
|
23
|
+
if (l && e instanceof Map && r instanceof Map) {
|
|
24
|
+
if (e.size !== r.size) return !1;
|
|
24
25
|
i = e.entries();
|
|
25
|
-
let
|
|
26
|
-
for (; !(
|
|
27
|
-
for (i = e.entries(); !(
|
|
26
|
+
let t;
|
|
27
|
+
for (; !(t = i.next()).done;) if (!r.has(t.value[0])) return !1;
|
|
28
|
+
for (i = e.entries(); !(t = i.next()).done;) if (!o(t.value[1], r.get(t.value[0]))) return !1;
|
|
28
29
|
return !0;
|
|
29
30
|
}
|
|
30
|
-
if (a && e instanceof Set &&
|
|
31
|
-
if (e.size !==
|
|
31
|
+
if (a && e instanceof Set && r instanceof Set) {
|
|
32
|
+
if (e.size !== r.size) return !1;
|
|
32
33
|
i = e.entries();
|
|
33
|
-
let
|
|
34
|
-
for (; !(
|
|
34
|
+
let t;
|
|
35
|
+
for (; !(t = i.next()).done;) if (!r.has(t.value[0])) return !1;
|
|
35
36
|
return !0;
|
|
36
37
|
}
|
|
37
|
-
if (Array.isArray(e) && Array.isArray(
|
|
38
|
-
if (n = e.length, n !=
|
|
39
|
-
for (let
|
|
38
|
+
if (Array.isArray(e) && Array.isArray(r) && c && ArrayBuffer.isView(e) && ArrayBuffer.isView(r)) {
|
|
39
|
+
if (n = e.length, n != r.length) return !1;
|
|
40
|
+
for (let t = n; t-- !== 0;) if (e[t] !== r[t]) return !1;
|
|
40
41
|
return !0;
|
|
41
42
|
}
|
|
42
|
-
if (e.constructor === RegExp) return e.source ===
|
|
43
|
-
if (e.valueOf !== Object.prototype.valueOf && typeof e.valueOf == "function" && typeof
|
|
44
|
-
if (e.toString !== Object.prototype.toString && typeof e.toString == "function" && typeof
|
|
43
|
+
if (e.constructor === RegExp) return e.source === r.source && e.flags === r.flags;
|
|
44
|
+
if (e.valueOf !== Object.prototype.valueOf && typeof e.valueOf == "function" && typeof r.valueOf == "function") return e.valueOf() === r.valueOf();
|
|
45
|
+
if (e.toString !== Object.prototype.toString && typeof e.toString == "function" && typeof r.toString == "function") return e.toString() === r.toString();
|
|
45
46
|
const f = Object.keys(e);
|
|
46
|
-
if (n = f.length, n !== Object.keys(
|
|
47
|
-
for (let
|
|
48
|
-
for (let
|
|
47
|
+
if (n = f.length, n !== Object.keys(r).length) return !1;
|
|
48
|
+
for (let t = n; t-- !== 0;) if (!(0, _isSet.isSet)(t) || !(0, _isSetString.isSetString)(f[t]) || !Object.prototype.hasOwnProperty.call(r, f[t])) return !1;
|
|
49
|
+
for (let t = n; t-- !== 0;) if (!(Array.isArray(f) && (f[t] === "_owner" || f[t] === "__v" || f[t] === "__o") && e.$$typeof) && (!(0, _isSet.isSet)(t) || !(0, _isSetString.isSetString)(f[t]) || !o(e[f[t]], r[f[t]]))) return !1;
|
|
49
50
|
return !0;
|
|
50
51
|
}
|
|
51
|
-
return e !== e &&
|
|
52
|
+
return e !== e && r !== r;
|
|
52
53
|
}
|
|
53
|
-
function isEqual(e,
|
|
54
|
+
function isEqual(e, r) {
|
|
54
55
|
try {
|
|
55
|
-
return o(e,
|
|
56
|
+
return o(e, r);
|
|
56
57
|
} catch (n) {
|
|
57
58
|
if (/stack|recursion/i.test(n?.message || "")) return console.warn("isEqual cannot handle circular refs"), !1;
|
|
58
59
|
throw n;
|
package/dist/is-equal.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isSet as s
|
|
1
|
+
import{isSet as s}from"@stryke/type-checks/is-set";import{isSetString as u}from"@stryke/type-checks/is-set-string";const l=typeof Map=="function",a=typeof Set=="function",c=typeof ArrayBuffer=="function"&&!!ArrayBuffer.isView;function o(e,r){if(e===r)return!0;if(e&&r&&typeof e=="object"&&typeof r=="object"){if(e.constructor!==r.constructor)return!1;let n;if(Array.isArray(e)){if(n=e.length,n!=r.length)return!1;for(let t=n;t--!==0;)if(!o(e[t],r[t]))return!1;return!0}let i;if(l&&e instanceof Map&&r instanceof Map){if(e.size!==r.size)return!1;i=e.entries();let t;for(;!(t=i.next()).done;)if(!r.has(t.value[0]))return!1;for(i=e.entries();!(t=i.next()).done;)if(!o(t.value[1],r.get(t.value[0])))return!1;return!0}if(a&&e instanceof Set&&r instanceof Set){if(e.size!==r.size)return!1;i=e.entries();let t;for(;!(t=i.next()).done;)if(!r.has(t.value[0]))return!1;return!0}if(Array.isArray(e)&&Array.isArray(r)&&c&&ArrayBuffer.isView(e)&&ArrayBuffer.isView(r)){if(n=e.length,n!=r.length)return!1;for(let t=n;t--!==0;)if(e[t]!==r[t])return!1;return!0}if(e.constructor===RegExp)return e.source===r.source&&e.flags===r.flags;if(e.valueOf!==Object.prototype.valueOf&&typeof e.valueOf=="function"&&typeof r.valueOf=="function")return e.valueOf()===r.valueOf();if(e.toString!==Object.prototype.toString&&typeof e.toString=="function"&&typeof r.toString=="function")return e.toString()===r.toString();const f=Object.keys(e);if(n=f.length,n!==Object.keys(r).length)return!1;for(let t=n;t--!==0;)if(!s(t)||!u(f[t])||!Object.prototype.hasOwnProperty.call(r,f[t]))return!1;for(let t=n;t--!==0;)if(!(Array.isArray(f)&&(f[t]==="_owner"||f[t]==="__v"||f[t]==="__o")&&e.$$typeof)&&(!s(t)||!u(f[t])||!o(e[f[t]],r[f[t]])))return!1;return!0}return e!==e&&r!==r}export function isEqual(e,r){try{return o(e,r)}catch(n){if(/stack|recursion/i.test(n?.message||""))return console.warn("isEqual cannot handle circular refs"),!1;throw n}}
|
package/dist/match-sorter.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Forked from match-sorter by Kent C. Dodds
|
|
3
3
|
*/
|
|
4
|
-
|
|
4
|
+
interface KeyAttributes {
|
|
5
5
|
threshold?: Ranking;
|
|
6
6
|
maxRanking: Ranking;
|
|
7
7
|
minRanking: Ranking;
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
interface RankingInfo {
|
|
10
10
|
rankedValue: string;
|
|
11
11
|
rank: Ranking;
|
package/dist/set-field.cjs
CHANGED
|
@@ -4,17 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.setField = setField;
|
|
7
|
-
var
|
|
7
|
+
var _isObjectIndex = require("@stryke/type-checks/is-object-index");
|
|
8
|
+
var _isString = require("@stryke/type-checks/is-string");
|
|
8
9
|
var _toPath = require("./to-path.cjs");
|
|
9
|
-
function setField(i,
|
|
10
|
-
const r = Array.isArray(
|
|
11
|
-
for (const
|
|
12
|
-
let
|
|
13
|
-
for (let
|
|
14
|
-
const
|
|
15
|
-
y = r[
|
|
16
|
-
n
|
|
10
|
+
function setField(i, e, c) {
|
|
11
|
+
const r = Array.isArray(e) ? e : (0, _isString.isString)(e) ? (0, _toPath.toPath)(e) : [e];
|
|
12
|
+
for (const t of r) if (t === "__proto__" || t === "constructor" || t === "prototype") throw new Error(`Invalid key in path: ${t}`);
|
|
13
|
+
let o = i;
|
|
14
|
+
for (let t = 0; t < r.length - 1; t++) {
|
|
15
|
+
const n = r[t],
|
|
16
|
+
y = r[t + 1];
|
|
17
|
+
o[n] === null && (o[n] = (0, _isObjectIndex.isObjectIndex)(y) ? [] : {}), o = o[n];
|
|
17
18
|
}
|
|
18
|
-
const
|
|
19
|
-
return
|
|
19
|
+
const s = r.at(-1);
|
|
20
|
+
return s && (o[s] = c), i;
|
|
20
21
|
}
|
package/dist/set-field.d.ts
CHANGED
package/dist/set-field.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isObjectIndex as f
|
|
1
|
+
import{isObjectIndex as f}from"@stryke/type-checks/is-object-index";import{isString as l}from"@stryke/type-checks/is-string";import{toPath as p}from"./to-path";export function setField(i,e,c){const r=Array.isArray(e)?e:l(e)?p(e):[e];for(const t of r)if(t==="__proto__"||t==="constructor"||t==="prototype")throw new Error(`Invalid key in path: ${t}`);let o=i;for(let t=0;t<r.length-1;t++){const n=r[t],y=r[t+1];o[n]===null&&(o[n]=f(y)?[]:{}),o=o[n]}const s=r.at(-1);return s&&(o[s]=c),i}
|
package/dist/to-deep-key.cjs
CHANGED
|
@@ -5,10 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.addPathToDeepKey = addPathToDeepKey;
|
|
7
7
|
exports.toDeepKey = toDeepKey;
|
|
8
|
-
var
|
|
8
|
+
var _isNumber = require("@stryke/type-checks/is-number");
|
|
9
|
+
var _isSetString = require("@stryke/type-checks/is-set-string");
|
|
9
10
|
function toDeepKey(n) {
|
|
10
11
|
return n.reduce((r, t) => addPathToDeepKey(r, t));
|
|
11
12
|
}
|
|
12
13
|
function addPathToDeepKey(n, r) {
|
|
13
|
-
return (0,
|
|
14
|
+
return (0, _isNumber.isNumber)(r) || Number.isInteger(r) ? `${n}[${r}]` : (0, _isSetString.isSetString)(r) ? `${n}.${r}` : n;
|
|
14
15
|
}
|
package/dist/to-deep-key.d.ts
CHANGED
|
@@ -18,18 +18,21 @@ export declare function toDeepKey(path: string[]): string;
|
|
|
18
18
|
/**
|
|
19
19
|
* Adds a path segment to a deep key string.
|
|
20
20
|
*
|
|
21
|
+
* @remarks
|
|
21
22
|
* This function takes a deep key string and a path segment and combines them into a new deep key string.
|
|
22
23
|
*
|
|
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
24
|
* @example
|
|
25
|
+
* ```ts
|
|
28
26
|
* addPathToDeepKey('a.b', 'c') // Returns 'a.b.c'
|
|
29
27
|
* addPathToDeepKey('a[0]', 'c') // Returns 'a[0].c'
|
|
30
28
|
* addPathToDeepKey('.a.b', 'c') // Returns '.a.b.c'
|
|
31
29
|
* addPathToDeepKey('a.b', 'b.c') // Returns 'a.b.b.c'
|
|
32
30
|
* addPathToDeepKey('', 'a') // Returns 'a'
|
|
33
31
|
* addPathToDeepKey('.a.b', 'c.d') // Returns '.a.b.c.d'
|
|
32
|
+
* ```
|
|
33
|
+
*
|
|
34
|
+
* @param deepKey - The deep key string to add the path segment to.
|
|
35
|
+
* @param path - The path segment to add to the deep key string.
|
|
36
|
+
* @returns A new deep key string.
|
|
34
37
|
*/
|
|
35
38
|
export declare function addPathToDeepKey(deepKey: string, path: string | number): string;
|
package/dist/to-deep-key.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isNumber as e
|
|
1
|
+
import{isNumber as e}from"@stryke/type-checks/is-number";import{isSetString as i}from"@stryke/type-checks/is-set-string";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
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.toPath = toPath;
|
|
7
7
|
const a = /^[\w.]+$/g,
|
|
8
8
|
E = /\\(?<temp1>\\)?/g,
|
|
9
|
-
e = new RegExp(String.raw`[^.[\]]+`
|
|
9
|
+
e = new RegExp(`${String.raw`[^.[\]]+`}|${String.raw`\[(?:`}([^"'][^[]*)|${String.raw`(["'])((?:(?!\2)[^\\]|\\.)*?)\2`}${String.raw`)\]`}|${String.raw`(?=(?:\.|\[\])(?:\.|\[\]|$))`}`, "g");
|
|
10
10
|
function toPath(t) {
|
|
11
11
|
if (a.test(t)) return t.split(".");
|
|
12
12
|
const n = [];
|
package/dist/to-path.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Converts a deep key string into an array of path segments.
|
|
3
3
|
*
|
|
4
|
+
* @remarks
|
|
4
5
|
* 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
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* Examples:
|
|
10
|
-
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
11
9
|
* toPath('a.b.c') // Returns ['a', 'b', 'c']
|
|
12
10
|
* toPath('a[b][c]') // Returns ['a', 'b', 'c']
|
|
13
11
|
* toPath('.a.b.c') // Returns ['', 'a', 'b', 'c']
|
|
14
12
|
* toPath('a["b.c"].d') // Returns ['a', 'b.c', 'd']
|
|
15
13
|
* toPath('') // Returns []
|
|
16
14
|
* toPath('.a[b].c.d[e]["f.g"].h') // Returns ['', 'a', 'b', 'c', 'd', 'e', 'f.g', 'h']
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param deepKey - The deep key string to convert.
|
|
18
|
+
* @returns An array of strings, each representing a segment of the path.
|
|
17
19
|
*/
|
|
18
20
|
export declare function toPath(deepKey: string): string[];
|
package/dist/to-path.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const a=/^[\w.]+$/g,E=/\\(?<temp1>\\)?/g,e=new RegExp(String.raw`[^.[\]]
|
|
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}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stryke/helpers",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A package containing miscellaneous helper functions that are used across many different Storm Software projects.",
|
|
6
6
|
"repository": {
|
|
@@ -10,7 +10,11 @@
|
|
|
10
10
|
},
|
|
11
11
|
"private": false,
|
|
12
12
|
"publishConfig": { "access": "public" },
|
|
13
|
-
"dependencies": {
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@stryke/convert": ">=0.1.0",
|
|
15
|
+
"@stryke/type-checks": ">=0.1.0",
|
|
16
|
+
"@stryke/types": ">=0.6.0"
|
|
17
|
+
},
|
|
14
18
|
"devDependencies": {},
|
|
15
19
|
"sideEffects": false,
|
|
16
20
|
"files": ["dist/**/*"],
|
|
@@ -24,7 +28,6 @@
|
|
|
24
28
|
"stryke",
|
|
25
29
|
"typescript",
|
|
26
30
|
"utilities",
|
|
27
|
-
"storm-stack",
|
|
28
31
|
"storm-software",
|
|
29
32
|
"storm",
|
|
30
33
|
"storm-ops",
|
|
@@ -301,6 +304,20 @@
|
|
|
301
304
|
"default": "./dist/flatten-object.mjs"
|
|
302
305
|
}
|
|
303
306
|
},
|
|
307
|
+
"./filter-empty": {
|
|
308
|
+
"import": {
|
|
309
|
+
"types": "./dist/filter-empty.d.ts",
|
|
310
|
+
"default": "./dist/filter-empty.mjs"
|
|
311
|
+
},
|
|
312
|
+
"require": {
|
|
313
|
+
"types": "./dist/filter-empty.d.ts",
|
|
314
|
+
"default": "./dist/filter-empty.cjs"
|
|
315
|
+
},
|
|
316
|
+
"default": {
|
|
317
|
+
"types": "./dist/filter-empty.d.ts",
|
|
318
|
+
"default": "./dist/filter-empty.mjs"
|
|
319
|
+
}
|
|
320
|
+
},
|
|
304
321
|
"./errors": {
|
|
305
322
|
"import": {
|
|
306
323
|
"types": "./dist/errors.d.ts",
|