tinkit 1.0.0 → 1.0.1
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/README.md +5 -5
- package/dist/arrays/index.d.ts +3 -3
- package/dist/arrays/index.js +1 -1
- package/dist/objects/index.d.ts +38 -39
- package/dist/objects/index.js +1 -1
- package/dist/utils/types.d.ts +0 -18
- package/dist/validate/index.d.ts +2 -2
- package/llms-full.txt +9 -9
- package/llms.txt +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-

|
|
2
2
|
|
|
3
3
|
[](https://github.com/emiliodominguez/js-helpers/actions/workflows/tests.yml)
|
|
4
4
|
[](./tsconfig.json)
|
|
@@ -64,11 +64,11 @@ const schema = toStandardSchema(isUser); // for your form or RPC library
|
|
|
64
64
|
## Hostile input is a non-event
|
|
65
65
|
|
|
66
66
|
```ts
|
|
67
|
-
import { deepMerge,
|
|
67
|
+
import { deepMerge, getPath } from 'tinkit/objects';
|
|
68
68
|
import { isAbsoluteUrl, sanitizeUrl } from 'tinkit/url';
|
|
69
69
|
|
|
70
70
|
deepMerge(defaults, JSON.parse('{"__proto__": {"isAdmin": true}}')); // key dropped, Object.prototype untouched
|
|
71
|
-
|
|
71
|
+
getPath(permissions, 'viewer.constructor', false); // false: inherited Object members never resolve
|
|
72
72
|
sanitizeUrl(' JAVASCRIPT:alert(1)'); // 'about:blank': parsed the way a browser parses it
|
|
73
73
|
isAbsoluteUrl('/\\evil.com'); // true: browsers send it to evil.com, so it is not a safe relative redirect
|
|
74
74
|
```
|
|
@@ -96,7 +96,7 @@ More examples, including dates, text and decorators, are in [Recipes](./docs/REC
|
|
|
96
96
|
| Module | Highlights |
|
|
97
97
|
| ---------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
98
98
|
| [`arrays`](./docs/API.md#arrays) | `orderBy`, `groupBy`, `partition`, `chunk`, top-N `takeFirstBy`, `sampleSize`, combinatorics, Myers `diffSequences`, set algebra (`…By`/`…With`) |
|
|
99
|
-
| [`objects`](./docs/API.md#objects) | `deepClone`, `deepMerge`/`defaults`, `isEqual`/`isMatch`, immutable `
|
|
99
|
+
| [`objects`](./docs/API.md#objects) | `deepClone`, `deepMerge`/`defaults`, `isEqual`/`isMatch`, immutable `updatePath`, `toCamelCaseKeys`, `stableStringify`/`hash`, `diff` |
|
|
100
100
|
| [`guards`](./docs/API.md#guards) | 50+ predicates, `isShape`/`isUnion`/`isLazy`/`refine` schemas, `isMatching`, `explain`/`ensure`, `toStandardSchema`, `assertNever` |
|
|
101
101
|
| [`strings`](./docs/API.md#strings) | every case style, grapheme-aware `padStart`/`trimChars`/`truncate`, `toSlug`, `dedent`, `wordWrap`, `levenshtein`, `mask`, `escapeHtml` |
|
|
102
102
|
| [`math`](./docs/API.md#math) | precise `sum`/`round`/`ceil`/`floor`, `quantile`, `variance`, `clamp`/`lerp`, `formatBytes`/`parseBytes`, Miller–Rabin `isPrime` |
|
|
@@ -123,7 +123,7 @@ More examples, including dates, text and decorators, are in [Recipes](./docs/REC
|
|
|
123
123
|
|
|
124
124
|
## How it's tested
|
|
125
125
|
|
|
126
|
-
3,
|
|
126
|
+
3,600+ tests, run in four time zones before every push, with 100% statement and branch coverage. They include [fast-check](https://fast-check.dev) property tests for the laws behind each helper, every JSDoc example (1,400+ assertions) run against the build, and [mutation testing](./docs/mutation/README.md).
|
|
127
127
|
|
|
128
128
|
## Docs
|
|
129
129
|
|
package/dist/arrays/index.d.ts
CHANGED
|
@@ -85,9 +85,9 @@ export declare function flattenDeep<T>(array: ReadonlyArray<T>): Array<FlatDeep<
|
|
|
85
85
|
* @param {Iterable<T>} iterable - The iterable to be processed
|
|
86
86
|
* @returns {T[]} A new array with duplicates removed, in first-appearance order
|
|
87
87
|
* @example
|
|
88
|
-
*
|
|
88
|
+
* unique([1, 2, 2, 3, 1]); // => [1, 2, 3]
|
|
89
89
|
*/
|
|
90
|
-
export declare function
|
|
90
|
+
export declare function unique<T>(iterable: Iterable<T>): T[];
|
|
91
91
|
/**
|
|
92
92
|
* Get the union of two iterables: every distinct value from `a`, then every distinct value of `b` not already in `a`.
|
|
93
93
|
* Uses SameValueZero equality.
|
|
@@ -726,7 +726,7 @@ export declare function unionBy<T, U = T>(a: Iterable<T>, b: Iterable<U>, keyFn:
|
|
|
726
726
|
*/
|
|
727
727
|
export declare function symmetricDifferenceBy<T, U = T>(a: Iterable<T>, b: Iterable<U>, keyFn: (item: T | U) => unknown): Array<T | U>;
|
|
728
728
|
/**
|
|
729
|
-
* Remove the items `equals` to an earlier item, keeping the first occurrence: {@link
|
|
729
|
+
* Remove the items `equals` to an earlier item, keeping the first occurrence: {@link unique} with a custom equality, for
|
|
730
730
|
* values that have no identity key (e.g. points within a tolerance). It compares every pair, in O(n²): when a key exists, prefer
|
|
731
731
|
* {@link uniqueBy}, which is O(n).
|
|
732
732
|
* @template T
|
package/dist/arrays/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isIterable as me}from"../guards/index.js";import{median as ye}from"../math/index.js";import{assertFunction as f,assertInteger as R,assertNumber as O,describe as X,draw as W}from"../utils/assert.js";const N=2**32-1,he=64;function ke(e,n){return e.includes(n)}function Ie(e){return e[0]}function Be(e){return e[e.length-1]}function Ke(e){const n=[];for(let t=0;t<e.length;t++){if(!(t in e))continue;const r=e[t];if(Array.isArray(r))for(let o=0;o<r.length;o++)o in r&&n.push(r[o]);else n.push(r)}return n}function ve(e){const n=[],t=[],r=[];let o,u=e,i=0;for(;;)if(i===u.length){if(t.length===0)return n;u=t.pop(),i=r.pop(),o?.delete(u)}else if(i++in u){const l=u[i-1];if(!Array.isArray(l)){n.push(l);continue}if(t.push(u),r.push(i),o!==void 0?o.add(u):t.length===he&&(o=new Set(t)),o===void 0?t.includes(l):o.has(l))throw new TypeError("flattenDeep: cannot flatten a circular array");u=l,i=0}}function pe(e){const n=Array.isArray(e)?e:Array.from(e);if(n.length<=32){const u=[];for(const i of n)u.includes(i)||u.push(i);return u}const t=new Set(n),r=Array.from(t),o=0;return t.has(o)&&Object.is(n[n.indexOf(o)],-0)&&(r[r.indexOf(o)]=-0),r}function C(e,n){return Array.isArray(e)&&Array.isArray(n)&&e.length+n.length<=32}function Ue(e,n){return pe(Array.isArray(e)&&Array.isArray(n)?e.concat(n):[...e,...n])}function Me(e,n){const t=[];if(C(e,n)){for(const o of e)n.includes(o)&&!t.includes(o)&&t.push(o);return t}const r=new Set(n);for(const o of e)r.delete(o)&&t.push(o);return t}function ne(e,n){const t=[];if(C(e,n)){for(const o of e)!n.includes(o)&&!t.includes(o)&&t.push(o);return t}const r=new Set(n);for(const o of e)r.has(o)||(r.add(o),t.push(o));return t}function Ne(e,n){const t=Array.from(e),r=Array.from(n);return ne(t,r).concat(ne(r,t))}function Oe(e,n){if(C(e,n)){for(const r of e)if(!n.includes(r))return!1;return!0}const t=new Set(n);for(const r of e)if(!t.has(r))return!1;return!0}function S(e,n,t){if(t-n>32||e.constructor!==Array)return e.slice(n,t);const r=new Array(t-n);for(let o=0;n<t;o++,n++)n in e&&(r[o]=e[n]);return r}function Ee(e,n){R("chunk","size",n,1);const t=new Array(Math.ceil(e.length/n));for(let r=0;r<t.length;r++)t[r]=S(e,r*n,Math.min((r+1)*n,e.length));return t}function $e(e){const n=[];for(let t=0;t<e.length;t++){const r=e[t];r&&n.push(r)}return n}function be(e,n,t=1){const r=n===void 0?0:e,o=n===void 0?e:n;O("range","start",e,Number.isFinite(e),"a finite number"),n!==void 0&&O("range","end",n,Number.isFinite(n),"a finite number"),O("range","step",t,Number.isFinite(t)&&t!==0,"a finite number other than 0");const u=ge(r,o,t),i=new Array(u);for(let l=0;l<u;l++)i[l]=r+l*t;return i}function ge(e,n,t){const r=(n-e)/t,o=Math.round(r);let u=Math.max(0,r===o||Math.abs(r-o)<=4*Number.EPSILON*((Math.abs(e)+Math.abs(n))/Math.abs(t)+Math.abs(r))?o:Math.ceil(r));if(u>N)throw new RangeError(`range: the range would contain ${u} items, more than an array can hold`);for(;u>0&&(e+(u-1)*t-n)*t>=0;)u--;return u}function De(...e){return Ae(e)}function P(){return Object.setPrototypeOf({},null)}function je(e,n){f("groupBy","keyFn",n);const t=P();for(let r=0;r<e.length;r++){const o=e[r],u=n(o,r),i=t[u];i===void 0?t[u]=[o]:i.push(o)}return t}function We(e,n){f("keyBy","keyFn",n);const t=P();for(let r=0;r<e.length;r++)t[n(e[r],r)]=e[r];return t}function Ce(e,n){f("countBy","keyFn",n);const t=P();for(let r=0;r<e.length;r++){const o=n(e[r],r);t[o]=(t[o]??0)+1}return t}function Pe(e,n){f("partition","predicate",n);const t=[],r=[];for(let o=0;o<e.length;o++)n(e[o],o)?t.push(e[o]):r.push(e[o]);return[t,r]}function Fe(e,n){f("uniqueBy","keyFn",n);const t=new Set,r=[];for(let o=0;o<e.length;o++){const u=n(e[o],o);t.has(u)||(t.add(u),r.push(e[o]))}return r}function Y(e){return e instanceof Date?e.getTime():e??NaN}function D(e){return typeof e=="number"?e:Y(e)}function F(e,n){const t=typeof e=="string";return t!==(typeof n=="string")?t?1:-1:e<n?-1:e>n?1:0}function j(e,n,t){return e!==e?n!==n?0:1:n!==n?-1:t*F(e,n)}function E(e,n,t,r){if(t==="asc"||t==="desc")return t==="asc"?1:-1;throw new RangeError(`${e}: \`${r===void 0?n:`${n}[${r}]`}\` must be 'asc' or 'desc', got ${String(t)}`)}function _(e,n){if(e.length>12){e.sort(n);return}for(let t=1;t<e.length;t++){const r=e[t];let o=t;for(;o>0&&n(e[o-1],r)>0;o--)e[o]=e[o-1];e[o]=r}}function te(e,n,t="asc"){f("sortBy","selector",n),E("sortBy","order",t);const r=e.length,o=[],u=[],i=[];for(let s=0;s<r;s++){const a=n(e[s],s),g=typeof a=="number"?a:Y(a);o.push(g),(g!==g?i:u).push(s)}_(u,t==="asc"?function(s,a){return F(o[s],o[a])}:function(s,a){return F(o[a],o[s])});const l=new Array(r);for(let s=0;s<u.length;s++)l[s]=e[u[s]];for(let s=0;s<i.length;s++)l[u.length+s]=e[i[s]];return l}function Ze(e,n=Math.random){const t=Array.from(e);for(let r=t.length-1;r>0;r--){const o=Math.floor(W("shuffle",n)*(r+1)),u=t[r];t[r]=t[o],t[o]=u}return t}function qe(e,n=Math.random){if(e.length!==0)return e[Math.floor(W("sample",n)*e.length)]}function Ge(e,n){return R("take","n",n,0),S(e,0,Math.min(n,e.length))}function Ve(e,n){return R("drop","n",n,0),S(e,Math.min(n,e.length),e.length)}function Ae(e){if(e.length===0)return[];let n=e[0].length;for(let r=1;r<e.length;r++)n=Math.min(n,e[r].length);const t=new Array(n);for(let r=0;r<n;r++){const o=new Array(e.length);for(let u=0;u<e.length;u++)o[u]=e[u][r];t[r]=o}return t}function ze(e,n,t=1){R("windowed","size",n,1),R("windowed","step",t,1);const r=e.length<n?0:Math.floor((e.length-n)/t)+1;if(r*n>N)throw new RangeError(`windowed: the result would contain ${r} windows of ${n} items, more than 2 ** 32 - 1 items in all`);const o=[];for(let u=0;u+n<=e.length;u+=t)o.push(S(e,u,u+n));return o}function Xe(e){const n=[];for(let t=1;t<e.length;t++)n.push([e[t-1],e[t]]);return n}function re(e,n,t){let r,o=NaN,u=NaN,i=0;for(;i<e.length&&(u=n(e[i],i),typeof u=="number");i++)if(u===u){r=e[i++],o=u;break}if(o===o)for(;i<e.length&&(u=n(e[i],i),typeof u=="number");i++)(t<0?u<o:u>o)&&(r=e[i],o=u);let l=o===o;for(;i<e.length;i++){const s=Y(u);s===s&&(!l||F(s,o)===t)&&(l=!0,r=e[i],o=s),i+1<e.length&&(u=n(e[i+1],i+1))}return r}function Ye(e,n){return f("minBy","selector",n),re(e,n,-1)}function _e(e,n){return f("maxBy","selector",n),re(e,n,1)}function Je(e,n){return f("sumBy","selector",n),oe(e,n,1)}function oe(e,n,t){let r=0,o=0;for(let u=0;u<e.length;u++){const i=+n(e[u],u),l=r+i;o+=Math.abs(r)>=Math.abs(i)?r-l+i:i-l+r,r=l}return Number.isFinite(r)?r/t+o/t:r/t}function $(e,n,t,r,o){const u=t<0?r+t:t,i=o?r:r-1;return O(e,n,t,Number.isInteger(t)&&u>=0&&u<=i,i<0?"a valid index, but the array is empty":`an integer in [${-r}, ${i}]`),u}function Qe(e,n,t){const r=$("move","from",n,e.length,!1),o=$("move","to",t,e.length,!1),u=Array.from(e),[i]=u.splice(r,1);return u.splice(o,0,i),u}function Le(e,n,...t){const r=$("insertAt","index",n,e.length,!0),o=Array.from(e);return o.splice(r,0,...t),o}function He(e,n,t=1){const r=$("removeAt","index",n,e.length,!1);R("removeAt","count",t,0);const o=Array.from(e);return o.splice(r,t),o}function xe(e,n){return e<n?-1:e>n?1:0}function J(e,n,t,r,o=!1){if(r===void 0){if(Number.isNaN(t))throw new RangeError(`${e}: \`value\` must not be NaN when no comparator is given, got NaN`)}else f(e,"compare",r);const u=r??xe;let i=0,l=n.length;for(;i<l;){const s=i+l>>>1,a=u(n[s],t);a<0||o&&a===0?i=s+1:l=s}return[i,u]}function en(e,n,t){return J("sortedIndex",e,n,t)[0]}function nn(e,n,t){const[r,o]=J("binarySearch",e,n,t);return r<e.length&&o(e[r],n)===0?r:-1}function tn(...e){let n=1;for(const o of e)n*=o.length;if(n*e.length>N)throw new RangeError(`cartesianProduct: the product would contain ${n} tuples of ${e.length} items, more than 2 ** 32 - 1 items in all`);const t=[],r=new Array(e.length).fill(0);for(let o=0;o<n;o++){const u=[];for(let i=0;i<e.length;i++)u.push(e[i][r[i]]);t.push(u);for(let i=e.length-1;i>=0&&(r[i]++,!(r[i]<e[i].length));i--)r[i]=0}return t}function rn(e,n){const t=[];for(let r=0;r<e.length;r++)r>0&&t.push(n),t.push(e[r]);return t}function Z(e,n){const t=new Array;for(const r of e)t.push(n(r));return t}function on(e,n,t){f("differenceBy","keyFn",t);const r=Z(n,t),o=[];if(C(e,r)){for(const i of e){const l=t(i);r.includes(l)||(r.push(l),o.push(i))}return o}const u=new Set(r);for(const i of e){const l=t(i);u.has(l)||(u.add(l),o.push(i))}return o}function un(e,n,t){f("intersectionBy","keyFn",t);const r=new Set(Z(n,t)),o=[];for(const u of e)r.delete(t(u))&&o.push(u);return o}function Q(e,n){return e===n||Number.isNaN(e)&&Number.isNaN(n)}function ue(e,n,t){if(!me(t))throw new TypeError(`${e}: \`${n}\` must be an iterable, got ${X(t)}`);return Array.from(t)}function ie(e,n,t,r,o){const u=ue(e,"a",n),i=ue(e,"b",t);f(e,"equals",r);const{maxEdits:l=1/0}=o;R(e,"maxEdits",l,0,!0);const s=Math.ceil(l/2);let a=0;function g(d){if(a+=d,a>l)throw new RangeError(`${e}: the sequences differ by more than \`maxEdits\` (${l}) insertions and deletions`)}const c=[],I=[],B=[],h=Math.ceil((u.length+i.length)/2)+1,v=new Int32Array(2*h),U=new Int32Array(2*h);function ee(){for(const d of I)c.push({type:"delete",value:u[d],indexA:d});for(const d of B)c.push({type:"insert",value:i[d],indexB:d});I.length=0,B.length=0}function q(d,k){ee(),c.push({type:"equal",value:u[d],indexA:d,indexB:k})}function de(d,k,A,M){const p=k-d,w=M-A,y=p-w,K=y%2!==0;v[h+1]=0,U[h+1]=0;for(let b=0;;b++){b>s&&g(1/0);for(let T=-b;T<=b;T+=2){let m=T===-b||T!==b&&v[h+T-1]<v[h+T+1]?v[h+T+1]:v[h+T-1]+1,x=m-T;const V=m,z=x;for(;m<p&&x<w&&r(u[d+m],i[A+x]);)m++,x++;if(v[h+T]=m,K&&Math.abs(y-T)<=b-1&&m+U[h+y-T]>=p)return[d+V,A+z,d+m,A+x]}for(let T=-b;T<=b;T+=2){let m=T===-b||T!==b&&U[h+T-1]<U[h+T+1]?U[h+T+1]:U[h+T-1]+1,x=m-T;const V=m,z=x;for(;m<p&&x<w&&r(u[k-1-m],i[M-1-x]);)m++,x++;if(U[h+T]=m,!K&&Math.abs(y-T)<=b&&m+v[h+y-T]>=p)return[k-m,M-x,k-V,M-z]}}}function G(d,k,A,M){for(;d<k&&A<M&&r(u[d],i[A]);)q(d++,A++);let p=k,w=M;for(;p>d&&w>A&&r(u[p-1],i[w-1]);)p--,w--;if(d===p){g(w-A);for(let y=A;y<w;y++)B.push(y)}else if(A===w){g(p-d);for(let y=d;y<p;y++)I.push(y)}else{const[y,K,b,T]=de(d,p,A,w);G(d,y,A,K);for(let m=y,x=K;m<b;m++,x++)q(m,x);G(b,p,T,w)}for(let y=p,K=w;y<k;y++,K++)q(y,K)}return G(0,u.length,0,i.length),ee(),c}function ln(e,n,t=Q,r={}){return ie("diffSequences",e,n,t,r)}function sn(e,n,t=Q,r={}){const o=[];for(const u of ie("longestCommonSubsequence",e,n,t,r))u.type==="equal"&&o.push(u.value);return o}function an(e,n,t){f("unionBy","keyFn",t);const r=new Set,o=[];for(const u of[e,n])for(const i of u){const l=t(i);r.has(l)||(r.add(l),o.push(i))}return o}function le(e,n,t,r){for(let o=0;o<e.length;o++)t.has(n[o])||(t.add(n[o]),r.push(e[o]));return r}function fn(e,n,t){f("symmetricDifferenceBy","keyFn",t);const r=Array.from(e),o=Array.from(n),u=Z(r,t),i=Z(o,t),l=le(r,u,new Set(i),[]);return le(o,i,new Set(u),l)}function L(e,n,t){for(const r of e){let o=0;for(;o<t.length&&!n(r,t[o]);)o++;o===t.length&&t.push(r)}return t}function cn(e,n){return f("uniqueWith","equals",n),L(e,n,[])}function Tn(e,n,t){return f("unionWith","equals",t),L(n,t,L(e,t,[]))}function dn(e,n,t){f("differenceWith","equals",t);const r=Array.isArray(n)?n.slice():Array.from(n),o=[];for(const u of e){let i=0;for(;i<r.length&&!t(u,r[i]);)i++;i===r.length&&(r.push(u),o.push(u))}return o}function mn(e,n,t){f("intersectionWith","equals",t);const r=Array.isArray(n)?n:Array.from(n),o=[];for(const u of e){let i=0;for(;i<r.length&&!t(u,r[i]);)i++;if(i===r.length)continue;let l=0;for(;l<o.length&&!t(u,o[l]);)l++;l===o.length&&o.push(u)}return o}function yn(e,n,t="asc"){if(!Array.isArray(n))throw new TypeError(`orderBy: \`selectors\` must be an array of functions, got ${X(n)}`);const r=typeof t=="string";if(!r&&!Array.isArray(t))throw new TypeError(`orderBy: \`orders\` must be 'asc', 'desc' or an array of them, got ${X(t)}`);const o=n.length;if(!r&&t.length>o)throw new RangeError(`orderBy: \`orders\` must not be longer than \`selectors\` (${o}), got ${t.length} directions`);const u=r?E("orderBy","orders",t):0,i=[];for(let c=0;c<o;c++)typeof n[c]!="function"&&f("orderBy",`selectors[${c}]`,n[c]),i.push(r?u:E("orderBy","orders",t[c]??"asc",c));if(o===1)return te(e,n[0],i[0]===1?"asc":"desc");const l=e.length,s=[],a=[];for(let c=0;c<l;c++){for(let I=0;I<o;I++)s.push(D(n[I](e[c],c)));a.push(c)}_(a,function(c,I){for(let B=0;B<o;B++){const h=j(s[c*o+B],s[I*o+B],i[B]);if(h!==0)return h}return 0});const g=new Array(l);for(let c=0;c<l;c++)g[c]=e[a[c]];return g}function se(e,n,t,r,o){for(;;){let u=r;for(let s=2*r+1;s<=2*r+2&&s<t;s++){const a=j(n[s],n[u],o);(a>0||a===0&&e[s]>e[u])&&(u=s)}if(u===r)return;const i=e[r],l=n[r];e[r]=e[u],n[r]=n[u],e[u]=i,n[u]=l,r=u}}function ae(e,n,t,r,o){f(e,"selector",r);const u=E(e,"order",o),i=[],l=[];if(t===0)return[i,l,u];for(let s=0;s<t;s++)i.push(s),l.push(D(r(n[s],s)));for(let s=(t>>1)-1;s>=0;s--)se(i,l,t,s,u);for(let s=t;s<n.length;s++){const a=D(r(n[s],s));j(a,l[0],u)<0&&(i[0]=s,l[0]=a,se(i,l,t,0,u))}return[i,l,u]}function hn(e,n,t,r="asc"){if(R("takeFirstBy","n",n,0),n>=e.length)return f("takeFirstBy","selector",t),E("takeFirstBy","order",r),te(e,t,r);const[o,u,i]=ae("takeFirstBy",e,n,t,r),l=be(o.length);return _(l,function(s,a){return j(u[s],u[a],i)||o[s]-o[a]}),l.map(function(s){return e[o[s]]})}function pn(e,n,t,r="asc"){O("nthBy","index",n,Number.isInteger(n),"an integer");const o=n<0?e.length+n:n,[u]=ae("nthBy",e,o>=0&&o<e.length?o+1:0,t,r);return u.length===0?void 0:e[u[0]]}function fe(e,n,t,r,o,u){f(e,"selector",r);const i=E(e,"order",o),l=D(r(t));let s=0,a=n.length;for(;s<a;){const g=s+a>>>1,c=j(D(r(n[g])),l,i);c<0||u&&c===0?s=g+1:a=g}return s}function bn(e,n,t,r="asc"){return fe("sortedIndexBy",e,n,t,r,!1)}function gn(e,n,t,r="asc"){return fe("sortedLastIndexBy",e,n,t,r,!0)}function An(e,n,t){return J("sortedLastIndex",e,n,t,!0)[0]}function xn(e,n){return R("takeLast","n",n,0),S(e,Math.max(e.length-n,0),e.length)}function wn(e,n){return R("dropLast","n",n,0),S(e,0,Math.max(e.length-n,0))}function ce(e,n,t){f(e,"predicate",t);let r=n.length;for(;r>0&&t(n[r-1],r-1);)r--;return r}function Rn(e,n){return S(e,ce("takeLastWhile",e,n),e.length)}function Sn(e,n){return S(e,0,ce("dropLastWhile",e,n))}function kn(e,n){f("chunkBy","keyFn",n);const t=[];let r=[],o;for(let u=0;u<e.length;u++){const i=n(e[u],u);u>0&&(i===o||i!==i&&o!==o)?r.push(e[u]):(r=[e[u]],t.push(r)),o=i}return t}function In(e,n){f("splitWhen","predicate",n);let t=0;for(;t<e.length&&!n(e[t],t);)t++;return[S(e,0,t),S(e,t,e.length)]}function Bn(e,n,t){const r=$("swap","i",n,e.length,!1),o=$("swap","j",t,e.length,!1),u=Array.from(e);return u[r]=e[o],u[o]=e[r],u}function Kn(e,n){O("rotate","k",n,Number.isInteger(n),"an integer");const t=e.length,r=new Array(t),o=(n%t+t)%t;for(let u=0;u<t;u++)r[u]=e[u<o?u-o+t:u-o];return r}function vn(e,n,t){t!==void 0&&f("toggle","keyFn",t);const r=t===void 0?n:t(n),o=[];for(let u=0;u<e.length;u++){const i=e[u];Q(t===void 0?i:t(i),r)||o.push(i)}return o.length===e.length&&o.push(n),o}function Un(e){return e==null?[]:Array.isArray(e)?S(e,0,e.length):[e]}function Mn(e,n){if(e.length!==n.length)throw new RangeError(`zipObject: \`values\` must have as many items as \`keys\` (${e.length}), got ${n.length}`);const t=P();for(let r=0;r<e.length;r++)t[e[r]]=n[r];return Object.setPrototypeOf(t,Object.prototype)}function Nn(e,...n){f("zipWith","fn",e);const t=e;let r=n.length===0?0:n[0].length;for(let i=1;i<n.length;i++)r=Math.min(r,n[i].length);const o=new Array(r);if(n.length===2){const[i,l]=n;for(let s=0;s<r;s++)o[s]=t(i[s],l[s]);return o}const u=new Array(n.length);for(let i=0;i<r;i++){for(let l=0;l<n.length;l++)u[l]=n[l][i];o[i]=t(...u)}return o}function On(e,n,t=Math.random){R("sampleSize","n",n,0);const r=e.length,o=Math.min(n,r),u=new Array(o);if(r<=64*o){const l=S(e,0,r);for(let s=0;s<o;s++){const a=s+Math.floor(W("sampleSize",t)*(r-s));u[s]=l[a],l[a]=l[s]}return u}const i=new Map;for(let l=0;l<o;l++){const s=l+Math.floor(W("sampleSize",t)*(r-l));u[l]=e[i.get(s)??s],i.set(s,i.get(l)??l)}return u}function En(e,n){return f("averageBy","selector",n),oe(e,n,e.length)}function $n(e,n){f("medianBy","selector",n);const t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=n(e[r],r);return ye(t)}function H(e,n,t){if(n>N||t>N)throw new RangeError(`${e}: the result would contain ${n} tuples holding ${t} items, more than 2 ** 32 - 1`)}function Te(e,n){const t=new Array(n.length);for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t}function Dn(e,n){R("combinations","k",n,0);const t=e.length;if(n>t)return[];let r=1;for(let i=0;i<n&&r<=N;i++)r=r*(t-i)/(i+1);H("combinations",r,r*n);const o=[],u=[];for(let i=0;i<n;i++)u.push(i);for(;;){o.push(Te(e,u));let i=n-1;for(;i>=0&&u[i]===t-n+i;)i--;if(i<0)return o;u[i]++;for(let l=i+1;l<n;l++)u[l]=u[l-1]+1}}function jn(e,n=e.length){R("permutations","k",n,0);const t=e.length;if(n>t)return[];let r=1;for(let s=0;s<n&&r<=N;s++)r*=t-s;H("permutations",r,r*n);const o=[],u=[],i=new Array(t).fill(!1);let l=0;for(;;){for(u.length===n&&(o.push(Te(e,u)),l=t);l<t&&i[l];)l++;if(l<t)i[l]=!0,u.push(l),l=0;else{if(u.length===0)return o;const s=u.pop();i[s]=!1,l=s+1}}}function Wn(e){const n=e.length;H("powerSet",2**n,n*2**(n-1));const t=[[]];for(let r=0;r<n;r++){const o=t.length;for(let u=0;u<o;u++){const i=t[u].slice();i.push(e[r]),t.push(i)}}return t}export{En as averageBy,nn as binarySearch,tn as cartesianProduct,Ee as chunk,kn as chunkBy,Dn as combinations,$e as compact,ke as contains,Ce as countBy,ln as diffSequences,ne as difference,on as differenceBy,dn as differenceWith,Ve as drop,wn as dropLast,Sn as dropLastWhile,Ie as first,Ke as flatten,ve as flattenDeep,je as groupBy,Le as insertAt,Me as intersection,un as intersectionBy,mn as intersectionWith,rn as intersperse,Oe as isSubset,We as keyBy,Be as last,sn as longestCommonSubsequence,_e as maxBy,$n as medianBy,Ye as minBy,Qe as move,pn as nthBy,yn as orderBy,Xe as pairwise,Pe as partition,jn as permutations,Wn as powerSet,be as range,He as removeAt,pe as removeDuplicates,Kn as rotate,qe as sample,On as sampleSize,Ze as shuffle,te as sortBy,en as sortedIndex,bn as sortedIndexBy,An as sortedLastIndex,gn as sortedLastIndexBy,In as splitWhen,Je as sumBy,Bn as swap,Ne as symmetricDifference,fn as symmetricDifferenceBy,Ge as take,hn as takeFirstBy,xn as takeLast,Rn as takeLastWhile,Un as toArray,vn as toggle,Ue as union,an as unionBy,Tn as unionWith,Fe as uniqueBy,cn as uniqueWith,Ae as unzip,ze as windowed,De as zip,Mn as zipObject,Nn as zipWith};
|
|
1
|
+
import{isIterable as me}from"../guards/index.js";import{median as ye}from"../math/index.js";import{assertFunction as f,assertInteger as R,assertNumber as O,describe as X,draw as W}from"../utils/assert.js";const N=2**32-1,he=64;function ke(e,n){return e.includes(n)}function Ie(e){return e[0]}function Be(e){return e[e.length-1]}function Ke(e){const n=[];for(let t=0;t<e.length;t++){if(!(t in e))continue;const r=e[t];if(Array.isArray(r))for(let o=0;o<r.length;o++)o in r&&n.push(r[o]);else n.push(r)}return n}function ve(e){const n=[],t=[],r=[];let o,u=e,i=0;for(;;)if(i===u.length){if(t.length===0)return n;u=t.pop(),i=r.pop(),o?.delete(u)}else if(i++in u){const l=u[i-1];if(!Array.isArray(l)){n.push(l);continue}if(t.push(u),r.push(i),o!==void 0?o.add(u):t.length===he&&(o=new Set(t)),o===void 0?t.includes(l):o.has(l))throw new TypeError("flattenDeep: cannot flatten a circular array");u=l,i=0}}function pe(e){const n=Array.isArray(e)?e:Array.from(e);if(n.length<=32){const u=[];for(const i of n)u.includes(i)||u.push(i);return u}const t=new Set(n),r=Array.from(t),o=0;return t.has(o)&&Object.is(n[n.indexOf(o)],-0)&&(r[r.indexOf(o)]=-0),r}function C(e,n){return Array.isArray(e)&&Array.isArray(n)&&e.length+n.length<=32}function Ue(e,n){return pe(Array.isArray(e)&&Array.isArray(n)?e.concat(n):[...e,...n])}function Me(e,n){const t=[];if(C(e,n)){for(const o of e)n.includes(o)&&!t.includes(o)&&t.push(o);return t}const r=new Set(n);for(const o of e)r.delete(o)&&t.push(o);return t}function ne(e,n){const t=[];if(C(e,n)){for(const o of e)!n.includes(o)&&!t.includes(o)&&t.push(o);return t}const r=new Set(n);for(const o of e)r.has(o)||(r.add(o),t.push(o));return t}function Ne(e,n){const t=Array.from(e),r=Array.from(n);return ne(t,r).concat(ne(r,t))}function Oe(e,n){if(C(e,n)){for(const r of e)if(!n.includes(r))return!1;return!0}const t=new Set(n);for(const r of e)if(!t.has(r))return!1;return!0}function S(e,n,t){if(t-n>32||e.constructor!==Array)return e.slice(n,t);const r=new Array(t-n);for(let o=0;n<t;o++,n++)n in e&&(r[o]=e[n]);return r}function Ee(e,n){R("chunk","size",n,1);const t=new Array(Math.ceil(e.length/n));for(let r=0;r<t.length;r++)t[r]=S(e,r*n,Math.min((r+1)*n,e.length));return t}function $e(e){const n=[];for(let t=0;t<e.length;t++){const r=e[t];r&&n.push(r)}return n}function be(e,n,t=1){const r=n===void 0?0:e,o=n===void 0?e:n;O("range","start",e,Number.isFinite(e),"a finite number"),n!==void 0&&O("range","end",n,Number.isFinite(n),"a finite number"),O("range","step",t,Number.isFinite(t)&&t!==0,"a finite number other than 0");const u=ge(r,o,t),i=new Array(u);for(let l=0;l<u;l++)i[l]=r+l*t;return i}function ge(e,n,t){const r=(n-e)/t,o=Math.round(r);let u=Math.max(0,r===o||Math.abs(r-o)<=4*Number.EPSILON*((Math.abs(e)+Math.abs(n))/Math.abs(t)+Math.abs(r))?o:Math.ceil(r));if(u>N)throw new RangeError(`range: the range would contain ${u} items, more than an array can hold`);for(;u>0&&(e+(u-1)*t-n)*t>=0;)u--;return u}function De(...e){return Ae(e)}function P(){return Object.setPrototypeOf({},null)}function je(e,n){f("groupBy","keyFn",n);const t=P();for(let r=0;r<e.length;r++){const o=e[r],u=n(o,r),i=t[u];i===void 0?t[u]=[o]:i.push(o)}return t}function We(e,n){f("keyBy","keyFn",n);const t=P();for(let r=0;r<e.length;r++)t[n(e[r],r)]=e[r];return t}function Ce(e,n){f("countBy","keyFn",n);const t=P();for(let r=0;r<e.length;r++){const o=n(e[r],r);t[o]=(t[o]??0)+1}return t}function Pe(e,n){f("partition","predicate",n);const t=[],r=[];for(let o=0;o<e.length;o++)n(e[o],o)?t.push(e[o]):r.push(e[o]);return[t,r]}function Fe(e,n){f("uniqueBy","keyFn",n);const t=new Set,r=[];for(let o=0;o<e.length;o++){const u=n(e[o],o);t.has(u)||(t.add(u),r.push(e[o]))}return r}function Y(e){return e instanceof Date?e.getTime():e??NaN}function D(e){return typeof e=="number"?e:Y(e)}function F(e,n){const t=typeof e=="string";return t!==(typeof n=="string")?t?1:-1:e<n?-1:e>n?1:0}function j(e,n,t){return e!==e?n!==n?0:1:n!==n?-1:t*F(e,n)}function E(e,n,t,r){if(t==="asc"||t==="desc")return t==="asc"?1:-1;throw new RangeError(`${e}: \`${r===void 0?n:`${n}[${r}]`}\` must be 'asc' or 'desc', got ${String(t)}`)}function _(e,n){if(e.length>12){e.sort(n);return}for(let t=1;t<e.length;t++){const r=e[t];let o=t;for(;o>0&&n(e[o-1],r)>0;o--)e[o]=e[o-1];e[o]=r}}function te(e,n,t="asc"){f("sortBy","selector",n),E("sortBy","order",t);const r=e.length,o=[],u=[],i=[];for(let s=0;s<r;s++){const a=n(e[s],s),g=typeof a=="number"?a:Y(a);o.push(g),(g!==g?i:u).push(s)}_(u,t==="asc"?function(s,a){return F(o[s],o[a])}:function(s,a){return F(o[a],o[s])});const l=new Array(r);for(let s=0;s<u.length;s++)l[s]=e[u[s]];for(let s=0;s<i.length;s++)l[u.length+s]=e[i[s]];return l}function qe(e,n=Math.random){const t=Array.from(e);for(let r=t.length-1;r>0;r--){const o=Math.floor(W("shuffle",n)*(r+1)),u=t[r];t[r]=t[o],t[o]=u}return t}function Ze(e,n=Math.random){if(e.length!==0)return e[Math.floor(W("sample",n)*e.length)]}function Ge(e,n){return R("take","n",n,0),S(e,0,Math.min(n,e.length))}function Ve(e,n){return R("drop","n",n,0),S(e,Math.min(n,e.length),e.length)}function Ae(e){if(e.length===0)return[];let n=e[0].length;for(let r=1;r<e.length;r++)n=Math.min(n,e[r].length);const t=new Array(n);for(let r=0;r<n;r++){const o=new Array(e.length);for(let u=0;u<e.length;u++)o[u]=e[u][r];t[r]=o}return t}function ze(e,n,t=1){R("windowed","size",n,1),R("windowed","step",t,1);const r=e.length<n?0:Math.floor((e.length-n)/t)+1;if(r*n>N)throw new RangeError(`windowed: the result would contain ${r} windows of ${n} items, more than 2 ** 32 - 1 items in all`);const o=[];for(let u=0;u+n<=e.length;u+=t)o.push(S(e,u,u+n));return o}function Xe(e){const n=[];for(let t=1;t<e.length;t++)n.push([e[t-1],e[t]]);return n}function re(e,n,t){let r,o=NaN,u=NaN,i=0;for(;i<e.length&&(u=n(e[i],i),typeof u=="number");i++)if(u===u){r=e[i++],o=u;break}if(o===o)for(;i<e.length&&(u=n(e[i],i),typeof u=="number");i++)(t<0?u<o:u>o)&&(r=e[i],o=u);let l=o===o;for(;i<e.length;i++){const s=Y(u);s===s&&(!l||F(s,o)===t)&&(l=!0,r=e[i],o=s),i+1<e.length&&(u=n(e[i+1],i+1))}return r}function Ye(e,n){return f("minBy","selector",n),re(e,n,-1)}function _e(e,n){return f("maxBy","selector",n),re(e,n,1)}function Je(e,n){return f("sumBy","selector",n),oe(e,n,1)}function oe(e,n,t){let r=0,o=0;for(let u=0;u<e.length;u++){const i=+n(e[u],u),l=r+i;o+=Math.abs(r)>=Math.abs(i)?r-l+i:i-l+r,r=l}return Number.isFinite(r)?r/t+o/t:r/t}function $(e,n,t,r,o){const u=t<0?r+t:t,i=o?r:r-1;return O(e,n,t,Number.isInteger(t)&&u>=0&&u<=i,i<0?"a valid index, but the array is empty":`an integer in [${-r}, ${i}]`),u}function Qe(e,n,t){const r=$("move","from",n,e.length,!1),o=$("move","to",t,e.length,!1),u=Array.from(e),[i]=u.splice(r,1);return u.splice(o,0,i),u}function Le(e,n,...t){const r=$("insertAt","index",n,e.length,!0),o=Array.from(e);return o.splice(r,0,...t),o}function He(e,n,t=1){const r=$("removeAt","index",n,e.length,!1);R("removeAt","count",t,0);const o=Array.from(e);return o.splice(r,t),o}function xe(e,n){return e<n?-1:e>n?1:0}function J(e,n,t,r,o=!1){if(r===void 0){if(Number.isNaN(t))throw new RangeError(`${e}: \`value\` must not be NaN when no comparator is given, got NaN`)}else f(e,"compare",r);const u=r??xe;let i=0,l=n.length;for(;i<l;){const s=i+l>>>1,a=u(n[s],t);a<0||o&&a===0?i=s+1:l=s}return[i,u]}function en(e,n,t){return J("sortedIndex",e,n,t)[0]}function nn(e,n,t){const[r,o]=J("binarySearch",e,n,t);return r<e.length&&o(e[r],n)===0?r:-1}function tn(...e){let n=1;for(const o of e)n*=o.length;if(n*e.length>N)throw new RangeError(`cartesianProduct: the product would contain ${n} tuples of ${e.length} items, more than 2 ** 32 - 1 items in all`);const t=[],r=new Array(e.length).fill(0);for(let o=0;o<n;o++){const u=[];for(let i=0;i<e.length;i++)u.push(e[i][r[i]]);t.push(u);for(let i=e.length-1;i>=0&&(r[i]++,!(r[i]<e[i].length));i--)r[i]=0}return t}function rn(e,n){const t=[];for(let r=0;r<e.length;r++)r>0&&t.push(n),t.push(e[r]);return t}function q(e,n){const t=new Array;for(const r of e)t.push(n(r));return t}function on(e,n,t){f("differenceBy","keyFn",t);const r=q(n,t),o=[];if(C(e,r)){for(const i of e){const l=t(i);r.includes(l)||(r.push(l),o.push(i))}return o}const u=new Set(r);for(const i of e){const l=t(i);u.has(l)||(u.add(l),o.push(i))}return o}function un(e,n,t){f("intersectionBy","keyFn",t);const r=new Set(q(n,t)),o=[];for(const u of e)r.delete(t(u))&&o.push(u);return o}function Q(e,n){return e===n||Number.isNaN(e)&&Number.isNaN(n)}function ue(e,n,t){if(!me(t))throw new TypeError(`${e}: \`${n}\` must be an iterable, got ${X(t)}`);return Array.from(t)}function ie(e,n,t,r,o){const u=ue(e,"a",n),i=ue(e,"b",t);f(e,"equals",r);const{maxEdits:l=1/0}=o;R(e,"maxEdits",l,0,!0);const s=Math.ceil(l/2);let a=0;function g(d){if(a+=d,a>l)throw new RangeError(`${e}: the sequences differ by more than \`maxEdits\` (${l}) insertions and deletions`)}const c=[],I=[],B=[],h=Math.ceil((u.length+i.length)/2)+1,v=new Int32Array(2*h),U=new Int32Array(2*h);function ee(){for(const d of I)c.push({type:"delete",value:u[d],indexA:d});for(const d of B)c.push({type:"insert",value:i[d],indexB:d});I.length=0,B.length=0}function Z(d,k){ee(),c.push({type:"equal",value:u[d],indexA:d,indexB:k})}function de(d,k,A,M){const p=k-d,w=M-A,y=p-w,K=y%2!==0;v[h+1]=0,U[h+1]=0;for(let b=0;;b++){b>s&&g(1/0);for(let T=-b;T<=b;T+=2){let m=T===-b||T!==b&&v[h+T-1]<v[h+T+1]?v[h+T+1]:v[h+T-1]+1,x=m-T;const V=m,z=x;for(;m<p&&x<w&&r(u[d+m],i[A+x]);)m++,x++;if(v[h+T]=m,K&&Math.abs(y-T)<=b-1&&m+U[h+y-T]>=p)return[d+V,A+z,d+m,A+x]}for(let T=-b;T<=b;T+=2){let m=T===-b||T!==b&&U[h+T-1]<U[h+T+1]?U[h+T+1]:U[h+T-1]+1,x=m-T;const V=m,z=x;for(;m<p&&x<w&&r(u[k-1-m],i[M-1-x]);)m++,x++;if(U[h+T]=m,!K&&Math.abs(y-T)<=b&&m+v[h+y-T]>=p)return[k-m,M-x,k-V,M-z]}}}function G(d,k,A,M){for(;d<k&&A<M&&r(u[d],i[A]);)Z(d++,A++);let p=k,w=M;for(;p>d&&w>A&&r(u[p-1],i[w-1]);)p--,w--;if(d===p){g(w-A);for(let y=A;y<w;y++)B.push(y)}else if(A===w){g(p-d);for(let y=d;y<p;y++)I.push(y)}else{const[y,K,b,T]=de(d,p,A,w);G(d,y,A,K);for(let m=y,x=K;m<b;m++,x++)Z(m,x);G(b,p,T,w)}for(let y=p,K=w;y<k;y++,K++)Z(y,K)}return G(0,u.length,0,i.length),ee(),c}function ln(e,n,t=Q,r={}){return ie("diffSequences",e,n,t,r)}function sn(e,n,t=Q,r={}){const o=[];for(const u of ie("longestCommonSubsequence",e,n,t,r))u.type==="equal"&&o.push(u.value);return o}function an(e,n,t){f("unionBy","keyFn",t);const r=new Set,o=[];for(const u of[e,n])for(const i of u){const l=t(i);r.has(l)||(r.add(l),o.push(i))}return o}function le(e,n,t,r){for(let o=0;o<e.length;o++)t.has(n[o])||(t.add(n[o]),r.push(e[o]));return r}function fn(e,n,t){f("symmetricDifferenceBy","keyFn",t);const r=Array.from(e),o=Array.from(n),u=q(r,t),i=q(o,t),l=le(r,u,new Set(i),[]);return le(o,i,new Set(u),l)}function L(e,n,t){for(const r of e){let o=0;for(;o<t.length&&!n(r,t[o]);)o++;o===t.length&&t.push(r)}return t}function cn(e,n){return f("uniqueWith","equals",n),L(e,n,[])}function Tn(e,n,t){return f("unionWith","equals",t),L(n,t,L(e,t,[]))}function dn(e,n,t){f("differenceWith","equals",t);const r=Array.isArray(n)?n.slice():Array.from(n),o=[];for(const u of e){let i=0;for(;i<r.length&&!t(u,r[i]);)i++;i===r.length&&(r.push(u),o.push(u))}return o}function mn(e,n,t){f("intersectionWith","equals",t);const r=Array.isArray(n)?n:Array.from(n),o=[];for(const u of e){let i=0;for(;i<r.length&&!t(u,r[i]);)i++;if(i===r.length)continue;let l=0;for(;l<o.length&&!t(u,o[l]);)l++;l===o.length&&o.push(u)}return o}function yn(e,n,t="asc"){if(!Array.isArray(n))throw new TypeError(`orderBy: \`selectors\` must be an array of functions, got ${X(n)}`);const r=typeof t=="string";if(!r&&!Array.isArray(t))throw new TypeError(`orderBy: \`orders\` must be 'asc', 'desc' or an array of them, got ${X(t)}`);const o=n.length;if(!r&&t.length>o)throw new RangeError(`orderBy: \`orders\` must not be longer than \`selectors\` (${o}), got ${t.length} directions`);const u=r?E("orderBy","orders",t):0,i=[];for(let c=0;c<o;c++)typeof n[c]!="function"&&f("orderBy",`selectors[${c}]`,n[c]),i.push(r?u:E("orderBy","orders",t[c]??"asc",c));if(o===1)return te(e,n[0],i[0]===1?"asc":"desc");const l=e.length,s=[],a=[];for(let c=0;c<l;c++){for(let I=0;I<o;I++)s.push(D(n[I](e[c],c)));a.push(c)}_(a,function(c,I){for(let B=0;B<o;B++){const h=j(s[c*o+B],s[I*o+B],i[B]);if(h!==0)return h}return 0});const g=new Array(l);for(let c=0;c<l;c++)g[c]=e[a[c]];return g}function se(e,n,t,r,o){for(;;){let u=r;for(let s=2*r+1;s<=2*r+2&&s<t;s++){const a=j(n[s],n[u],o);(a>0||a===0&&e[s]>e[u])&&(u=s)}if(u===r)return;const i=e[r],l=n[r];e[r]=e[u],n[r]=n[u],e[u]=i,n[u]=l,r=u}}function ae(e,n,t,r,o){f(e,"selector",r);const u=E(e,"order",o),i=[],l=[];if(t===0)return[i,l,u];for(let s=0;s<t;s++)i.push(s),l.push(D(r(n[s],s)));for(let s=(t>>1)-1;s>=0;s--)se(i,l,t,s,u);for(let s=t;s<n.length;s++){const a=D(r(n[s],s));j(a,l[0],u)<0&&(i[0]=s,l[0]=a,se(i,l,t,0,u))}return[i,l,u]}function hn(e,n,t,r="asc"){if(R("takeFirstBy","n",n,0),n>=e.length)return f("takeFirstBy","selector",t),E("takeFirstBy","order",r),te(e,t,r);const[o,u,i]=ae("takeFirstBy",e,n,t,r),l=be(o.length);return _(l,function(s,a){return j(u[s],u[a],i)||o[s]-o[a]}),l.map(function(s){return e[o[s]]})}function pn(e,n,t,r="asc"){O("nthBy","index",n,Number.isInteger(n),"an integer");const o=n<0?e.length+n:n,[u]=ae("nthBy",e,o>=0&&o<e.length?o+1:0,t,r);return u.length===0?void 0:e[u[0]]}function fe(e,n,t,r,o,u){f(e,"selector",r);const i=E(e,"order",o),l=D(r(t));let s=0,a=n.length;for(;s<a;){const g=s+a>>>1,c=j(D(r(n[g])),l,i);c<0||u&&c===0?s=g+1:a=g}return s}function bn(e,n,t,r="asc"){return fe("sortedIndexBy",e,n,t,r,!1)}function gn(e,n,t,r="asc"){return fe("sortedLastIndexBy",e,n,t,r,!0)}function An(e,n,t){return J("sortedLastIndex",e,n,t,!0)[0]}function xn(e,n){return R("takeLast","n",n,0),S(e,Math.max(e.length-n,0),e.length)}function wn(e,n){return R("dropLast","n",n,0),S(e,0,Math.max(e.length-n,0))}function ce(e,n,t){f(e,"predicate",t);let r=n.length;for(;r>0&&t(n[r-1],r-1);)r--;return r}function Rn(e,n){return S(e,ce("takeLastWhile",e,n),e.length)}function Sn(e,n){return S(e,0,ce("dropLastWhile",e,n))}function kn(e,n){f("chunkBy","keyFn",n);const t=[];let r=[],o;for(let u=0;u<e.length;u++){const i=n(e[u],u);u>0&&(i===o||i!==i&&o!==o)?r.push(e[u]):(r=[e[u]],t.push(r)),o=i}return t}function In(e,n){f("splitWhen","predicate",n);let t=0;for(;t<e.length&&!n(e[t],t);)t++;return[S(e,0,t),S(e,t,e.length)]}function Bn(e,n,t){const r=$("swap","i",n,e.length,!1),o=$("swap","j",t,e.length,!1),u=Array.from(e);return u[r]=e[o],u[o]=e[r],u}function Kn(e,n){O("rotate","k",n,Number.isInteger(n),"an integer");const t=e.length,r=new Array(t),o=(n%t+t)%t;for(let u=0;u<t;u++)r[u]=e[u<o?u-o+t:u-o];return r}function vn(e,n,t){t!==void 0&&f("toggle","keyFn",t);const r=t===void 0?n:t(n),o=[];for(let u=0;u<e.length;u++){const i=e[u];Q(t===void 0?i:t(i),r)||o.push(i)}return o.length===e.length&&o.push(n),o}function Un(e){return e==null?[]:Array.isArray(e)?S(e,0,e.length):[e]}function Mn(e,n){if(e.length!==n.length)throw new RangeError(`zipObject: \`values\` must have as many items as \`keys\` (${e.length}), got ${n.length}`);const t=P();for(let r=0;r<e.length;r++)t[e[r]]=n[r];return Object.setPrototypeOf(t,Object.prototype)}function Nn(e,...n){f("zipWith","fn",e);const t=e;let r=n.length===0?0:n[0].length;for(let i=1;i<n.length;i++)r=Math.min(r,n[i].length);const o=new Array(r);if(n.length===2){const[i,l]=n;for(let s=0;s<r;s++)o[s]=t(i[s],l[s]);return o}const u=new Array(n.length);for(let i=0;i<r;i++){for(let l=0;l<n.length;l++)u[l]=n[l][i];o[i]=t(...u)}return o}function On(e,n,t=Math.random){R("sampleSize","n",n,0);const r=e.length,o=Math.min(n,r),u=new Array(o);if(r<=64*o){const l=S(e,0,r);for(let s=0;s<o;s++){const a=s+Math.floor(W("sampleSize",t)*(r-s));u[s]=l[a],l[a]=l[s]}return u}const i=new Map;for(let l=0;l<o;l++){const s=l+Math.floor(W("sampleSize",t)*(r-l));u[l]=e[i.get(s)??s],i.set(s,i.get(l)??l)}return u}function En(e,n){return f("averageBy","selector",n),oe(e,n,e.length)}function $n(e,n){f("medianBy","selector",n);const t=new Array(e.length);for(let r=0;r<e.length;r++)t[r]=n(e[r],r);return ye(t)}function H(e,n,t){if(n>N||t>N)throw new RangeError(`${e}: the result would contain ${n} tuples holding ${t} items, more than 2 ** 32 - 1`)}function Te(e,n){const t=new Array(n.length);for(let r=0;r<n.length;r++)t[r]=e[n[r]];return t}function Dn(e,n){R("combinations","k",n,0);const t=e.length;if(n>t)return[];let r=1;for(let i=0;i<n&&r<=N;i++)r=r*(t-i)/(i+1);H("combinations",r,r*n);const o=[],u=[];for(let i=0;i<n;i++)u.push(i);for(;;){o.push(Te(e,u));let i=n-1;for(;i>=0&&u[i]===t-n+i;)i--;if(i<0)return o;u[i]++;for(let l=i+1;l<n;l++)u[l]=u[l-1]+1}}function jn(e,n=e.length){R("permutations","k",n,0);const t=e.length;if(n>t)return[];let r=1;for(let s=0;s<n&&r<=N;s++)r*=t-s;H("permutations",r,r*n);const o=[],u=[],i=new Array(t).fill(!1);let l=0;for(;;){for(u.length===n&&(o.push(Te(e,u)),l=t);l<t&&i[l];)l++;if(l<t)i[l]=!0,u.push(l),l=0;else{if(u.length===0)return o;const s=u.pop();i[s]=!1,l=s+1}}}function Wn(e){const n=e.length;H("powerSet",2**n,n*2**(n-1));const t=[[]];for(let r=0;r<n;r++){const o=t.length;for(let u=0;u<o;u++){const i=t[u].slice();i.push(e[r]),t.push(i)}}return t}export{En as averageBy,nn as binarySearch,tn as cartesianProduct,Ee as chunk,kn as chunkBy,Dn as combinations,$e as compact,ke as contains,Ce as countBy,ln as diffSequences,ne as difference,on as differenceBy,dn as differenceWith,Ve as drop,wn as dropLast,Sn as dropLastWhile,Ie as first,Ke as flatten,ve as flattenDeep,je as groupBy,Le as insertAt,Me as intersection,un as intersectionBy,mn as intersectionWith,rn as intersperse,Oe as isSubset,We as keyBy,Be as last,sn as longestCommonSubsequence,_e as maxBy,$n as medianBy,Ye as minBy,Qe as move,pn as nthBy,yn as orderBy,Xe as pairwise,Pe as partition,jn as permutations,Wn as powerSet,be as range,He as removeAt,Kn as rotate,Ze as sample,On as sampleSize,qe as shuffle,te as sortBy,en as sortedIndex,bn as sortedIndexBy,An as sortedLastIndex,gn as sortedLastIndexBy,In as splitWhen,Je as sumBy,Bn as swap,Ne as symmetricDifference,fn as symmetricDifferenceBy,Ge as take,hn as takeFirstBy,xn as takeLast,Rn as takeLastWhile,Un as toArray,vn as toggle,Ue as union,an as unionBy,Tn as unionWith,pe as unique,Fe as uniqueBy,cn as uniqueWith,Ae as unzip,ze as windowed,De as zip,Mn as zipObject,Nn as zipWith};
|
package/dist/objects/index.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { isArray, isBoolean, isError, isFunction, isMap, isNull, isNumber, isObject, isPromise, isRegExp, isSet, isString, isSymbol, isUndefined, isWeakMap, isWeakSet } from '../guards/index.js';
|
|
2
1
|
import type { AnyFunction, DeepReadonly, NestedKeyOf, PathValue, Primitive, UnionToIntersection } from '../utils/index.js';
|
|
3
|
-
export { isObject, isArray, isFunction, isString, isNumber, isBoolean, isUndefined, isNull, isSymbol, isPromise, isRegExp, isError, isMap, isSet, isWeakMap, isWeakSet };
|
|
4
2
|
/**
|
|
5
3
|
* The empty object type `{}` (spelled so that it passes the `ban-types` lint rule).
|
|
6
4
|
*/
|
|
@@ -308,12 +306,12 @@ export declare function invert<T extends Record<PropertyKey, PropertyKey>>(objec
|
|
|
308
306
|
* @param {P} keys - The dot-separated path
|
|
309
307
|
* @returns {PathValue<T, P>} The value found at the path (or `undefined`)
|
|
310
308
|
* @example
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
309
|
+
* getPath({ a: { b: [{ id: 1 }] } }, 'a.b.0.id'); // => 1
|
|
310
|
+
* getPath({ a: {} as { x?: { y: number } } }, 'a.x.y'); // => undefined
|
|
311
|
+
* getPath({ name: 'Ada' }, 'name.length'); // => 3
|
|
312
|
+
* getPath({ viewer: { read: true } } as Record<string, object>, 'viewer.constructor' as never, false); // => false
|
|
315
313
|
*/
|
|
316
|
-
export declare function
|
|
314
|
+
export declare function getPath<T extends object, P extends NestedKeyOf<T>>(target: T, keys: P): PathValue<T, P>;
|
|
317
315
|
/**
|
|
318
316
|
* Safely reads a nested value through a dot-separated path, returning `defaultValue` when the resolved value is `undefined`.
|
|
319
317
|
* @template T - The object type
|
|
@@ -324,9 +322,9 @@ export declare function getFromObjectByKeys<T extends object, P extends NestedKe
|
|
|
324
322
|
* @param {D} defaultValue - The value returned when the path resolves to `undefined`
|
|
325
323
|
* @returns {Exclude<PathValue<T, P>, undefined> | D} The value found at the path, or `defaultValue`
|
|
326
324
|
* @example
|
|
327
|
-
*
|
|
325
|
+
* getPath({ a: {} as { x?: number } }, 'a.x', 0); // => 0
|
|
328
326
|
*/
|
|
329
|
-
export declare function
|
|
327
|
+
export declare function getPath<T extends object, P extends NestedKeyOf<T>, D>(target: T, keys: P, defaultValue: D): Exclude<PathValue<T, P>, undefined> | D;
|
|
330
328
|
/**
|
|
331
329
|
* Sets a nested value through a dot-separated path. MUTATES `target` and returns it.
|
|
332
330
|
* Missing (or `null`/`undefined`) intermediates are created: an array when the next segment is a canonical array index up to 1000
|
|
@@ -343,17 +341,17 @@ export declare function getFromObjectByKeys<T extends object, P extends NestedKe
|
|
|
343
341
|
* @throws {RangeError} when a segment is `__proto__`, `constructor` or `prototype` (prototype pollution guard)
|
|
344
342
|
* @throws {TypeError} when an existing intermediate value is a primitive (it would have to be overwritten)
|
|
345
343
|
* @example
|
|
346
|
-
*
|
|
347
|
-
*
|
|
344
|
+
* setPath({}, 'a.list.0.id', 7); // => { a: { list: [{ id: 7 }] } }
|
|
345
|
+
* setPath({}, 'a.5000', 1); // => { a: { 5000: 1 } }
|
|
348
346
|
*/
|
|
349
|
-
export declare function
|
|
347
|
+
export declare function setPath<T extends object>(target: T, path: string, value: unknown): T;
|
|
350
348
|
/**
|
|
351
349
|
* The value type at `P` in `T` when `P` is one of the known paths of `T` ({@link NestedKeyOf}), `unknown` for any other path (and
|
|
352
350
|
* for a path whose type is only `undefined`, such as a path through an `unknown` value).
|
|
353
351
|
*/
|
|
354
352
|
export type PathUpdateValue<T, P extends string> = [P] extends [NestedKeyOf<T>] ? ([PathValue<T, P>] extends [undefined] ? unknown : PathValue<T, P>) : unknown;
|
|
355
353
|
/**
|
|
356
|
-
* The type produced by {@link
|
|
354
|
+
* The type produced by {@link omitPath}: `T` without the property at the dot-separated path `P` (an array element becomes a
|
|
357
355
|
* hole, so the item type gains `undefined`; a nested path makes the items of an array `Item | ItemWithoutIt`).
|
|
358
356
|
* @example
|
|
359
357
|
* type O = OmitAtPath<{ a: { b: number; c: string } }, 'a.b'>; // { a: { c: string } }
|
|
@@ -364,15 +362,15 @@ export type OmitAtPath<T, P extends string> = T extends ReadonlyArray<infer Item
|
|
|
364
362
|
[K in keyof T as K extends string | number ? (`${K}` extends P ? never : K) : K]: T[K];
|
|
365
363
|
}> : T;
|
|
366
364
|
/**
|
|
367
|
-
* IMMUTABLE counterpart of {@link
|
|
365
|
+
* IMMUTABLE counterpart of {@link setPath}: returns a NEW root in which the value at the dot-separated path is replaced by
|
|
368
366
|
* `valueOrUpdater` (or, when it is a function, by `valueOrUpdater(currentValue)`). Inputs are never mutated: only the plain objects and
|
|
369
367
|
* arrays ON THE PATH are copied (keeping their prototype, arrays stay arrays); everything else is shared with the input (structural
|
|
370
368
|
* sharing). When the new value is `Object.is`-equal to the current own value, `target` itself is returned (handy for memoized UIs).
|
|
371
|
-
* - Same path rules as {@link
|
|
369
|
+
* - Same path rules as {@link setPath}: `__proto__`, `constructor`, `prototype` and empty segments are rejected; only own
|
|
372
370
|
* properties are followed; a missing (or `null`/`undefined`) intermediate is created as an array when the next segment is a canonical
|
|
373
371
|
* index up to 1000, as a plain object otherwise.
|
|
374
372
|
* - Containers that cannot be copied faithfully (class instances, maps, dates...) are not traversed: a `TypeError` is thrown.
|
|
375
|
-
* - To store a function, wrap it: `
|
|
373
|
+
* - To store a function, wrap it: `updatePath(o, 'onClick', function () { return handler; })`.
|
|
376
374
|
* @template T - The object type
|
|
377
375
|
* @template P - The path
|
|
378
376
|
* @param {T} target - The root (a plain object or an array)
|
|
@@ -384,19 +382,19 @@ export type OmitAtPath<T, P extends string> = T extends ReadonlyArray<infer Item
|
|
|
384
382
|
* @throws {TypeError} when an intermediate value is a primitive or an object that is neither a plain object nor an array
|
|
385
383
|
* @example
|
|
386
384
|
* const state = { user: { name: 'Ada', visits: 1 }, todos: [{ done: false }] };
|
|
387
|
-
* const next =
|
|
385
|
+
* const next = updatePath(state, 'user.visits', function (n) { return n + 1; });
|
|
388
386
|
* next; // => { user: { name: 'Ada', visits: 2 }, todos: [{ done: false }] }
|
|
389
387
|
* state.user.visits; // => 1
|
|
390
388
|
* next.todos === state.todos; // => true
|
|
391
|
-
*
|
|
392
|
-
*
|
|
389
|
+
* updatePath(state, 'user.name', 'Ada') === state; // => true
|
|
390
|
+
* updatePath({}, 'a.list.0', 'x' as never); // => { a: { list: ['x'] } }
|
|
393
391
|
*/
|
|
394
|
-
export declare function
|
|
392
|
+
export declare function updatePath<T extends object, P extends string>(target: T, path: P, valueOrUpdater: PathUpdateValue<T, P> | ((current: PathUpdateValue<T, P>) => PathUpdateValue<T, P>)): T;
|
|
395
393
|
/**
|
|
396
|
-
* IMMUTABLE counterpart of {@link
|
|
394
|
+
* IMMUTABLE counterpart of {@link deletePath}: returns a NEW root without the own property at the dot-separated path,
|
|
397
395
|
* copying only the plain objects and arrays on the path (structural sharing). Deleting an array element leaves a hole (the length is
|
|
398
|
-
* unchanged), like {@link
|
|
399
|
-
* {@link
|
|
396
|
+
* unchanged), like {@link deletePath}. When the path does not exist, `target` itself is returned. Same path rules as
|
|
397
|
+
* {@link updatePath}.
|
|
400
398
|
* @template T - The object type
|
|
401
399
|
* @template P - The path
|
|
402
400
|
* @param {T} target - The root (a plain object or an array)
|
|
@@ -407,18 +405,18 @@ export declare function updateInObjectByKeys<T extends object, P extends string>
|
|
|
407
405
|
* @throws {TypeError} when an intermediate object on the path is neither a plain object nor an array
|
|
408
406
|
* @example
|
|
409
407
|
* const config = { a: { b: 1, c: 2 }, d: { e: 3 } };
|
|
410
|
-
* const next =
|
|
408
|
+
* const next = omitPath(config, 'a.b');
|
|
411
409
|
* next; // => { a: { c: 2 }, d: { e: 3 } }
|
|
412
410
|
* next.d === config.d; // => true
|
|
413
|
-
*
|
|
411
|
+
* omitPath(config, 'a.x' as never) === config; // => true
|
|
414
412
|
*/
|
|
415
|
-
export declare function
|
|
413
|
+
export declare function omitPath<T extends object, P extends string>(target: T, path: P): OmitAtPath<T, P>;
|
|
416
414
|
/**
|
|
417
415
|
* Parses a property path written in JavaScript accessor syntax into its segments: dot-separated names (`a.b`) and brackets holding a
|
|
418
416
|
* canonical array index (`[0]`) or a quoted key (`['b.c']`, `["x"]`, with `\\`, `\'` and `\"` as the only escapes). The parser is
|
|
419
417
|
* STRICT: anything else (empty names, `a..b`, a trailing `.`, `a.[0]`, `[]`, `[-1]`, `[01]`, an unquoted name in brackets, a missing
|
|
420
418
|
* `]`, an unterminated quote, text right after `]`) is rejected rather than half-parsed, and so are `__proto__`, `constructor` and
|
|
421
|
-
* `prototype` segments. The `...
|
|
419
|
+
* `prototype` segments. The `...Path` helpers (`getPath`, `setPath`…) keep their plain dot syntax: join the segments with `'.'` when none contains one.
|
|
422
420
|
* @param {string} path - The path, e.g. `"a[0]['b.c'].d"`
|
|
423
421
|
* @returns {string[]} The segments (indices as strings), e.g. `['a', '0', 'b.c', 'd']`
|
|
424
422
|
* @throws {TypeError} when `path` is not a string
|
|
@@ -891,7 +889,7 @@ export interface UnflattenOptions extends FlattenOptions {
|
|
|
891
889
|
export declare function flattenObject(object: object, options?: FlattenOptions): Record<string, unknown>;
|
|
892
890
|
/**
|
|
893
891
|
* Rebuilds a nested object from a flat record of paths (the inverse of {@link flattenObject}). Keys are processed in `Object.keys` order;
|
|
894
|
-
* each one is split on `separator` and its value written like {@link
|
|
892
|
+
* each one is split on `separator` and its value written like {@link setPath} does: a missing container is created as an array
|
|
895
893
|
* when the next segment is a canonical array index (`'0'`, `'12'`) no larger than `arrayLimit` (default 1000), as a plain object
|
|
896
894
|
* otherwise; an array built by earlier keys becomes a plain object (same entries) as soon as a key gives it an index above the limit.
|
|
897
895
|
* So input such as a parsed query string `tags.4294967294=x` cannot build a 4-billion-element sparse array. The root is always a plain object.
|
|
@@ -918,7 +916,7 @@ export declare function flattenObject(object: object, options?: FlattenOptions):
|
|
|
918
916
|
*/
|
|
919
917
|
export declare function unflattenObject(record: Readonly<Record<string, unknown>>, options?: UnflattenOptions): Record<string, unknown>;
|
|
920
918
|
/**
|
|
921
|
-
* Checks whether a dot-separated path exists in an object: it is `true` exactly when {@link
|
|
919
|
+
* Checks whether a dot-separated path exists in an object: it is `true` exactly when {@link getPath} resolves the path
|
|
922
920
|
* to a property (whose value may be `undefined`) rather than falling back to the default value. Segments follow the same rule: own
|
|
923
921
|
* and inherited properties count (class getters, a string's `length` and indices, `Object.create(proto)` parents), but a
|
|
924
922
|
* `__proto__`, `constructor` or `prototype` segment never does, nor does an `Object.prototype` member the object does not own
|
|
@@ -927,16 +925,16 @@ export declare function unflattenObject(record: Readonly<Record<string, unknown>
|
|
|
927
925
|
* @param {string} path - The dot-separated path, e.g. `'a.b.0'`
|
|
928
926
|
* @returns {boolean} Whether every segment of the path resolves
|
|
929
927
|
* @example
|
|
930
|
-
*
|
|
931
|
-
*
|
|
932
|
-
*
|
|
933
|
-
*
|
|
928
|
+
* hasPath({ a: { b: [undefined] } }, 'a.b.0'); // => true
|
|
929
|
+
* hasPath({ a: {} }, 'a.toString'); // => false // an Object.prototype member
|
|
930
|
+
* hasPath({ a: {} }, 'a.constructor'); // => false
|
|
931
|
+
* hasPath({ name: 'Ada' }, 'name.length'); // => true
|
|
934
932
|
*/
|
|
935
|
-
export declare function
|
|
933
|
+
export declare function hasPath(target: object, path: string): boolean;
|
|
936
934
|
/**
|
|
937
935
|
* Deletes the property at a dot-separated path. MUTATES `target`. Only OWN properties are followed and deleted
|
|
938
936
|
* (an inherited property is never removed from a prototype). Deleting an array element leaves a hole (the length is unchanged).
|
|
939
|
-
* Like {@link
|
|
937
|
+
* Like {@link setPath}, the path may not contain `__proto__`, `constructor` or `prototype` segments, so it cannot remove
|
|
940
938
|
* a method shared by every instance of a class (`'Service.prototype.run'`).
|
|
941
939
|
* @param {object} target - The object to modify
|
|
942
940
|
* @param {string} path - The dot-separated path, e.g. `'a.b.0'`
|
|
@@ -945,12 +943,12 @@ export declare function hasInObjectByKeys(target: object, path: string): boolean
|
|
|
945
943
|
* @throws {RangeError} when a segment is `__proto__`, `constructor` or `prototype`
|
|
946
944
|
* @example
|
|
947
945
|
* const config = { a: { b: 1, c: 2 } };
|
|
948
|
-
*
|
|
946
|
+
* deletePath(config, 'a.b'); // => true
|
|
949
947
|
* config; // => { a: { c: 2 } }
|
|
950
|
-
*
|
|
951
|
-
*
|
|
948
|
+
* deletePath(config, 'a.x'); // => false
|
|
949
|
+
* deletePath({ C: class {} }, 'C.prototype.m'); // throws RangeError
|
|
952
950
|
*/
|
|
953
|
-
export declare function
|
|
951
|
+
export declare function deletePath(target: object, path: string): boolean;
|
|
954
952
|
/**
|
|
955
953
|
* Result of {@link diff}: dot-separated paths. `removed` and `changed` follow the depth-first key order of `a`, `added` that of `b`.
|
|
956
954
|
*/
|
|
@@ -1306,3 +1304,4 @@ export declare function stableStringify(value: unknown): string;
|
|
|
1306
1304
|
* Number.isSafeInteger(hash('anything', 42)); // => true
|
|
1307
1305
|
*/
|
|
1308
1306
|
export declare function hash(value: unknown, seed?: number): number;
|
|
1307
|
+
export {};
|
package/dist/objects/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isArray as Re,isBoolean as $e,isDate as $,isArrayBuffer as Be,isError as X,isFunction as P,isMap as A,isNull as Me,isNumber as Ie,isObject as c,isPlainObject as l,isPromise as B,isRegExp as V,isSet as S,isString as Le,isSymbol as Ve,isUndefined as We,isWeakMap as ye,isWeakSet as de}from"../guards/index.js";import{toCamelCase as ze,toKebabCase as Ne,toSnakeCase as _e}from"../strings/index.js";import{assertFunction as j,assertInteger as Ue,assertNumber as qe,describe as m}from"../utils/assert.js";const Y=new Set(["__proto__","constructor","prototype"]);function g(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function T(e){return W(e,Object.keys(e))}function W(e,n){for(const t of Object.getOwnPropertySymbols(e))Object.prototype.propertyIsEnumerable.call(e,t)&&n.push(t);return n}function G(e,n,t){Object.defineProperty(e,n,{value:t,writable:!0,enumerable:!0,configurable:!0})}function Z(e,n,t){n in e&&!g(e,n)?G(e,n,t):e[n]=t}function x(e,n,t){n in Object.prototype?G(e,n,t):e[n]=t}function z(e,n){return n==="prototype"||n in Object.prototype&&Fe(e,n)}function Fe(e,n){if(n==="__proto__"||n==="constructor")return!0;for(let t=e;t!==Object.prototype;t=Object.getPrototypeOf(t))if(t===null||g(t,n))return!1;return!0}function M(e,n){const t=e[n];return t===void 0||!z(e,n)?t:void 0}function k(e){return Object.prototype.toString.call(e)}function h(e,n){return Object.setPrototypeOf(e,Object.getPrototypeOf(n))}const pe=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag)?.get,Je=typeof SharedArrayBuffer=="function"?Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype,"byteLength")?.get:void 0;function He(e){if(!ArrayBuffer.isView(e))return h(e.slice(0),e);const n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),t=pe.call(e)??"DataView",r=globalThis[t];return h(new r(n),e)}function Q(e){if(ArrayBuffer.isView(e))return!0;const n=k(e);if(n==="[object ArrayBuffer]")return Be(e);if(n!=="[object SharedArrayBuffer]")return!1;try{return Je?.call(e)!==void 0}catch{return!1}}function v(e){return ye(e)||de(e)||B(e)}const Xe=new Map([["[object Number]",Number.prototype.valueOf],["[object String]",String.prototype.valueOf],["[object Boolean]",Boolean.prototype.valueOf],["[object BigInt]",BigInt.prototype.valueOf],["[object Symbol]",Symbol.prototype.valueOf]]);function N(e){const n=Xe.get(k(e));if(n===void 0)return[!1,void 0];try{return[!0,n.call(e)]}catch{return[!1,void 0]}}function Ye(e){const n=new RegExp(e.source,e.flags);return n.lastIndex=e.lastIndex,h(n,e)}function ee(e,n){return n===Object.prototype?!B(e)&&k(e)==="[object Object]"&&!ArrayBuffer.isView(e):n===Array.prototype&&Array.isArray(e)&&!B(e)&&k(e)==="[object Array]"}function le(e){const n=e.length,t=Object.keys(e);return t.length===n&&(n===0||t[n-1]===String(n-1))&&Object.getOwnPropertySymbols(e).length===0}function pn(e,...n){if(n.length===1)return{...e,...n[0]};let t={...e};for(const r of n)t={...t,...r};return t}function Ge(e){if(c(e)&&ee(e,Object.getPrototypeOf(e))){if(!Array.isArray(e))return{...e};if(le(e))return Array.from(e)}return E(e)}function ln(e,n){return g(e,n)}function bn(e,n){return M(e,n)}function gn(e,n,t){if(n==="__proto__")throw new RangeError('setProperty: `property` must not be the unsafe key "__proto__"');e[n]=t}function Tn(e,n){delete e[n]}function xn(e){return Object.getOwnPropertyNames(e)}function kn(e){if(Array.isArray(e))return e.length===0;if(A(e)||S(e))return e.size===0;const n=Object(e);for(const t in n)if(g(n,t))return!1;for(const t of Object.getOwnPropertySymbols(n))if(Object.prototype.propertyIsEnumerable.call(n,t))return!1;return!0}function wn(e,n){const t={};for(const r of n){const o=e[r];(o!==void 0||r in e)&&!z(e,r)&&x(t,r,o)}return t}function mn(e,n){const t=new Set;for(const o of n)t.add(typeof o=="number"?String(o):o);const r={};for(const o of T(e))t.has(o)||x(r,o,e[o]);return r}function Kn(e,n){j("mapValues","fn",n);const t=Array.isArray(e),r=t?new Array(e.length):{};for(const o of T(e)){const s=n(e[o],o,e);t?Z(r,o,s):x(r,o,s)}return r}function jn(e,n){j("mapKeys","fn",n);const t={};for(const r of T(e)){const o=e[r];x(t,n(o,r,e),o)}return t}function hn(e){const n={};for(const t of Object.keys(e)){const r=e[t];if(typeof r!="string"&&typeof r!="number"&&typeof r!="symbol")throw new TypeError(`invert: \`object.${t}\` must be a string, number or symbol, got ${m(r)}`);x(n,r,t)}return n}const Ze=2**32-1,ne=/^(?:0|[1-9]\d*)$/,te=1e3;function be(e){return ne.test(e)?Number(e):-1}function _(e,n,t,r){const o=t.split(r);for(const s of o)if(s===""||Y.has(s))throw new RangeError(`${e}: ${n} must not contain ${s===""?"empty segments":`the unsafe segment "${s}"`}, got ${JSON.stringify(t)}`);return o}function ge(e,n,t,r,o,s,f,i){let u=e;const a=n.length-1;let y=!1;for(let d=0;d<a;d++){const b=n[d],w=!y&&g(u,b);let p=w?u[b]:void 0;if(i!==void 0&&w&&!i.has(p))throw new TypeError(`${s}: cannot set "${r}": "${n.slice(0,d+1).join(o)}" is already set by another key`);if(p==null){const ce=be(n[d+1]),L=ce!==-1&&ce<=f?[]:{};y&&!(b in u)?u[b]=L:G(u,b,L),i?.add(L),y=!0,p=L}else{if(!c(p)&&!P(p))throw new TypeError(`${s}: cannot set "${r}": "${n.slice(0,d+1).join(o)}" is a ${typeof p}, not an object`);i!==void 0&&Number(n[d+1])>f&&ne.test(n[d+1])&&Array.isArray(p)&&(p=Object.assign({},p),i.add(p),u[b]=p)}u=p}if(i!==void 0&&g(u,n[a]))throw new TypeError(`${s}: cannot set "${r}": "${n.join(o)}" already holds values set by other keys`);u[n[a]]=t}function On(e,n,t){let r=e;if(n.indexOf(".")===-1)r=r==null?void 0:M(r,n);else for(const o of n.split(".")){if(r==null)return t;r=M(r,o)}return r===void 0?t:r}function An(e,n,t){return ge(e,_("setInObjectByKeys","`path`",n,"."),t,n,".","setInObjectByKeys",te),e}function Te(e){return Array.isArray(e)?Ge(e):Object.getPrototypeOf(e)===null?Object.assign(Object.create(null),e):{...e}}function re(e,n,t,r){const o=Te(e);return r?Reflect.deleteProperty(o,n):Z(o,n,t),o}function xe(e,n,t,r,o,s){const f=r[o],i=g(t,f),u=i?t[f]:void 0;if(o===r.length-1){if(s===void 0)return i?re(t,f,void 0,!0):t;const d=s(u);return i&&Object.is(d,u)?t:re(t,f,d,!1)}let a;if(D(u))a=u;else if(u==null||s===void 0&&!c(u)&&!P(u)){if(s===void 0)return t;const d=be(r[o+1]);a=d!==-1&&d<=te?[]:{}}else{const d=c(u)||P(u)?"an object that is neither a plain object nor an array":`a ${typeof u}`;throw new TypeError(`${e}: cannot update "${n}": "${r.slice(0,o+1).join(".")}" is ${d}`)}const y=xe(e,n,a,r,o+1,s);return y===u?t:re(t,f,y,!1)}function ke(e,n,t,r){return J(e,"target",n),xe(e,t,n,_(e,"`path`",t,"."),0,r)}function Sn(e,n,t){return ke("updateInObjectByKeys",e,n,typeof t=="function"?t:function(){return t})}function Pn(e,n){return ke("omitInObjectByKeys",e,n,void 0)}function C(e,n,t){throw new RangeError(`toPath: \`path\` ${t} at index ${n}, got ${JSON.stringify(e)}`)}function Cn(e){if(typeof e!="string")throw new TypeError(`toPath: \`path\` must be a string, got ${m(e)}`);const n=[];let t=0,r=!1;for(;;){const o=t;let s="";if(e[t]==="["&&!r){const f=e[++t];if(f==='"'||f==="'"){for(let i=e[++t];i!==f;i=e[++t])i===void 0&&C(e,o,"has an unterminated quoted key"),i==="\\"&&(i=e[++t],i!=="\\"&&i!=='"'&&i!=="'"&&C(e,t-1,"has an invalid escape")),s+=i;t++}else{const i=e.indexOf("]",t);s=e.slice(t,i===-1?t:i),ne.test(s)||C(e,o,"must hold a canonical index or a quoted key in brackets"),t=i}e[t]!=="]"&&C(e,t,"is missing ']'"),t++}else{for(;t<e.length&&e[t]!=="."&&e[t]!=="["&&e[t]!=="]";)t++;t===o&&C(e,o,"has an empty segment"),s=e.slice(o,t)}if(Y.has(s)&&C(e,o,`has the unsafe segment "${s}"`),n.push(s),t===e.length)return n;r=e[t]===".",r?t++:e[t]!=="["&&C(e,t,`has an unexpected ${JSON.stringify(e[t])}`)}}function E(e,n){if(!c(e))return e;const t=n?.get(e);if(t!==void 0)return t;if(ee(e,Object.getPrototypeOf(e))){if(!Array.isArray(e)){const i={...e};n?.set(e,i);for(const u of T(i))i[u]=U(i[u],n);return i}if(le(e)){const i=new Array(e.length);n?.set(e,i);for(let u=0;u<e.length;u++)i[u]=U(e[u],n);return i}}if(v(e))return e;const[r,o]=N(e);if(r)return h(Object(o),e);if($(e))return h(new Date(e.getTime()),e);if(V(e))return Ye(e);if(Q(e))return He(e);if(A(e)){if(n===void 0)return h(new Map(e),e);const i=h(new Map,e);return n.set(e,i),e.forEach(function(u,a){i.set(E(a,n),E(u,n))}),i}if(S(e)){if(n===void 0)return h(new Set(e),e);const i=h(new Set,e);return n.set(e,i),e.forEach(function(u){i.add(E(u,n))}),i}const s=X(e),f=!s&&Array.isArray(e)?h(new Array(e.length),e):Object.create(Object.getPrototypeOf(e));n?.set(e,f);for(const i of s?Reflect.ownKeys(e):T(e))if(s){const u=Object.getOwnPropertyDescriptor(e,i);"value"in u&&(u.value=U(u.value,n)),Object.defineProperty(f,i,u)}else Z(f,i,U(e[i],n));return f}function U(e,n){return n===void 0?e:E(e,n)}function En(e){return E(e,new Map)}function Qe(e,n,t){const r=[].concat(e,n);return t?Array.from(new Set(r)):r}function q(e){return Object.getPrototypeOf(e)===null?Object.create(null):{}}function oe(e,n,t,r,o){if(t.includes(n))throw new TypeError(`${r.caller}: cannot merge objects with circular references`);t.push(n);const{customizer:s,fill:f,arrays:i}=r,u=s===void 0&&!f&&i==="replace";for(const a of T(n)){if(Y.has(a))continue;const y=n[a],d=r.deep&&l(y);let b=y;if(d||!u){const w=g(e,a)?e[a]:void 0;if(b=s===void 0?void 0:s(w,y,{key:a,path:[...o,a]}),b===void 0){const p=f&&w!==void 0&&!(r.nullish&&w===null);if(d&&(l(w)||!p))o.push(a),b=oe(l(w)?w:q(y),y,t,r,o),o.pop();else if(i!=="replace"&&Array.isArray(w)&&Array.isArray(y))b=Qe(w,y,i==="union");else{if(p)continue;b=y}}}x(e,a,b)}return t.pop(),e}function I(e,n,t){if(!l(n))throw new TypeError(`${e.caller}: \`target\` must be a plain object, got ${m(n)}`);const r=[],o=e.customizer===void 0?e:{...e,customizer:void 0},s=oe(q(n),n,r,o,[]);for(let f=0;f<t.length;f++){const i=t[f];if(i!=null){if(!l(i))throw new TypeError(`${e.caller}: \`sources[${f}]\` must be a plain object, got ${m(i)}`);oe(s,i,r,e,[])}}return s}function we(e,n,t){if(!c(n))throw new TypeError(`${e}: \`options\` must be an object, got ${m(n)}`);const{arrays:r="replace",customizer:o,missing:s="undefined",deep:f}=n;if(r!=="replace"&&r!=="concat"&&r!=="union")throw new RangeError(`${e}: \`arrays\` must be 'replace', 'concat' or 'union', got ${JSON.stringify(r)}`);if(s!=="undefined"&&s!=="nullish")throw new RangeError(`${e}: \`missing\` must be 'undefined' or 'nullish', got ${JSON.stringify(s)}`);return o!==void 0&&j(e,"customizer",o),{caller:e,deep:!t||f===!0,fill:t,nullish:s==="nullish",arrays:r,customizer:o}}const ve={caller:"deepMerge",deep:!0,fill:!1,nullish:!1,arrays:"replace",customizer:void 0};function Dn(e,...n){return I(ve,e,n)}function Rn(e,n,...t){return I(we("deepMergeWith",e,!1),n,t)}const en={caller:"defaults",deep:!1,fill:!0,nullish:!1,arrays:"replace",customizer:void 0},nn={caller:"defaultsDeep",deep:!0,fill:!0,nullish:!1,arrays:"replace",customizer:void 0};function $n(e,...n){return I(en,e,n)}function Bn(e,...n){return I(nn,e,n)}function Mn(e,n,...t){return I(we("defaultsWith",e,!0),n,t)}function K(e,n){return e===n||e!==e&&n!==n}function tn(e,n,t){if(e.size!==n.size)return!1;const r=Array.from(n).filter(function([s]){return c(s)}),o=[];for(const[s,f]of e){if(!c(s)){if(!n.has(s)||!O(f,n.get(s),t,s))return!1;continue}const i=r.findIndex(function([u,a],y){return!o[y]&&O(s,u,t)&&O(f,a,t,s)});if(i===-1)return!1;o[i]=!0}return!0}function rn(e,n,t){if(e.size!==n.size)return!1;const r=Array.from(n).filter(c),o=[];for(const s of e){if(!c(s)){if(!n.has(s))return!1;continue}const f=r.findIndex(function(i,u){return!o[u]&&O(s,i,t)});if(f===-1)return!1;o[f]=!0}return!0}function on(e,n){let t=e,r=n;if(!ArrayBuffer.isView(e))t=new Uint8Array(e),r=new Uint8Array(n);else if(k(e)==="[object DataView]"){const o=n;t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}return t.length===r.length&&Array.prototype.every.call(t,function(o,s){return K(o,r[s])})}function me(e,n,t){const r=T(e),o=T(n);if(r.length!==o.length)return!1;for(const s of r)if(!Object.prototype.propertyIsEnumerable.call(n,s)||!O(e[s],n[s],t,s))return!1;return!0}function Ke(e,n,t){if(ee(e,Object.getPrototypeOf(e)))return(!Array.isArray(e)||e.length===n.length)&&me(e,n,t);if(v(e))return!1;if($(e))return K(e.getTime(),n.getTime());if(V(e))return e.source===n.source&&e.flags===n.flags;if(A(e))return tn(e,n,t);if(S(e))return rn(e,n,t);if(Q(e))return on(e,n);const[r,o]=N(e);if(r){const[s,f]=N(n);if(!s||!K(o,f))return!1}return X(e)&&(e.name!==n.name||e.message!==n.message)||Array.isArray(e)&&e.length!==n.length?!1:me(e,n,t)}function je(e,n){return Object.getPrototypeOf(e)===Object.getPrototypeOf(n)&&k(e)===k(n)}function se(e,n,t){for(const[r,o]of e)if(r===n&&o===t)return!0;return!1}function O(e,n,t,r){if(t.customizer!==void 0)return sn(e,n,t,r,t.customizer);if(K(e,n))return!0;if(!c(e)||!c(n)||!je(e,n))return!1;if(se(t,e,n))return!0;t.push([e,n]);const o=Ke(e,n,t);return t.pop(),o}function sn(e,n,t,r,o){if(Object.is(e,n))return!0;const s=c(e)&&c(n);if(s&&se(t,e,n))return!0;const f=t.length,i=[];for(let y=1;y<f;y++)i.push(t[y][2]);f>0&&i.push(r);const u=t[f-1];s&&t.push([e,n,r]);let a=o(e,n,{key:r,path:i,parentA:u?.[0],parentB:u?.[1],equals:t.equals});return a===void 0&&(a=K(e,n)||s&&je(e,n)&&Ke(e,n,t)),s&&t.pop(),!!a}function fn(e,n){return O(e,n,[])}function In(e,n,t){j("isEqualWith","customizer",t);const r=[];return r.customizer=t,r.equals=function(o,s){return O(o,s,r)},O(e,n,r)}function F(e,n,t,r){if(K(e,n))return!0;const o=l(n);if(!o&&!Array.isArray(n))return c(n)&&O(e,n,[]);if(!(c(e)||P(e))||!o&&!Array.isArray(e))return!1;if(se(r,e,n))return!0;r.push([e,n]);let s;if(o)s=T(n).every(function(f){const i=n[f],u=M(e,f);return i===void 0?u===void 0&&f in e&&!z(e,f):F(u,i,t,r)});else{const f=e;s=t?n.every(function(i){return f.some(function(u){return F(u,i,t,r)})}):f.length===n.length&&n.every(function(i,u){return F(f[u],i,t,r)})}return r.pop(),s}function Ln(e,n,t={}){const r=t.arrays??"exact";if(r!=="exact"&&r!=="subset")throw new RangeError(`isMatch: \`arrays\` must be 'exact' or 'subset', got ${JSON.stringify(r)}`);return F(e,n,r==="subset",[])}function Vn(e,n){if(K(e,n))return!0;if(!c(e)||!c(n))return!1;const t=Object.getPrototypeOf(e);if(t!==Object.getPrototypeOf(n))return!1;if(t!==Object.prototype&&t!==null){const r=k(e);if(r!==k(n))return!1;if(Array.isArray(e)){if(!Array.isArray(n)||e.length!==n.length)return!1;for(let o=0;o<e.length;o++){const s=e[o];if(!K(s,n[o])||s===void 0&&o in e!=o in n)return!1}return!0}if(A(e)){const o=n;if(!A(n)||e.size!==o.size)return!1;for(const[s,f]of e)if(!o.has(s)||!K(f,o.get(s)))return!1;return!0}if(S(e)){const o=n;if(!S(n)||e.size!==o.size)return!1;for(const s of e)if(!o.has(s))return!1;return!0}if($(e))return $(n)&&K(e.getTime(),n.getTime());if(r!=="[object Object]"||B(e))return!1}return he(e,n,Object.keys(e),Object.keys(n))&&he(e,n,W(e,[]),W(n,[]))}function he(e,n,t,r){if(t.length!==r.length)return!1;for(let o=0;o<t.length;o++){const s=t[o];if(s!==r[o]&&!Object.prototype.propertyIsEnumerable.call(n,s)||!K(e[s],n[s]))return!1}return!0}function Wn(e){const n=new WeakSet,t=[e];for(;t.length>0;){const r=t.pop();if(!(!c(r)||n.has(r)||ArrayBuffer.isView(r))){n.add(r),A(r)?r.forEach(function(o,s){t.push(s,o)}):S(r)&&r.forEach(function(o){t.push(o)});for(const o of Reflect.ownKeys(r))t.push(Object.getOwnPropertyDescriptor(r,o).value);Object.freeze(r)}}return e}function zn(e){return Object.keys(e)}function Nn(e){return Object.entries(e)}function _n(e){const n={};for(const[t,r]of e)x(n,t,r);return n}function Oe(e,n){j("pickBy","predicate",n);const t={};for(const r of T(e)){const o=e[r];n(o,r,e)&&x(t,r,o)}return t}function Un(e,n){return j("omitBy","predicate",n),Oe(e,function(t,r,o){return!n(t,r,o)})}function qn(e){return Oe(e,function(n){return n!==void 0})}function Ae(e,n){const t=n.separator??".";if(typeof t!="string")throw new TypeError(`${e}: \`separator\` must be a string, got ${m(t)}`);if(t==="")throw new RangeError(`${e}: \`separator\` must not be empty`);return t}function D(e){return Array.isArray(e)||l(e)}function J(e,n,t){if(!D(t))throw new TypeError(`${e}: \`${n}\` must be a plain object or an array, got ${m(t)}`)}function Se(e,n,t,r,o,s){if(s.includes(e))throw new TypeError("flattenObject: cannot flatten a circular structure");s.push(e);for(const f of n){const i=e[f],u=t+f,a=D(i)?Object.keys(i):void 0;a!==void 0&&a.length>0?Se(i,a,u+r,r,o,s):x(o,u,i)}s.pop()}function Fn(e,n={}){const t=Ae("flattenObject",n);J("flattenObject","object",e);const r={};return Se(e,Object.keys(e),"",t,r,[]),r}function Jn(e,n={}){const t=Ae("unflattenObject",n),r=n.arrayLimit??te;Ue("unflattenObject","arrayLimit",r,0,!0);const o=Math.min(r,Ze-1),s={},f=new WeakSet;for(const i of Object.keys(e))ge(s,_("unflattenObject","`record` keys",i,t),e[i],i,t,"unflattenObject",o,f);return s}function Hn(e,n){const t=n.split("."),r=t.length-1;let o=e;for(let f=0;f<r&&o!=null;f++)o=M(o,t[f]);if(o==null)return!1;const s=t[r];return s in Object(o)&&!z(o,s)}function Xn(e,n){const t=_("deleteFromObjectByKeys","`path`",n,"."),r=t.length-1;let o=e;for(let f=0;f<r;f++){if(!(c(o)||P(o))||!g(o,t[f]))return!1;o=o[t[f]]}const s=t[r];return(c(o)||P(o))&&g(o,s)&&Reflect.deleteProperty(o,s)}function ie(e,n,t,r,o,s){if(s.has(e))throw new TypeError("diff: cannot diff circular structures");s.add(e);for(const f of Object.keys(e)){const i=t+f;if(!Object.prototype.propertyIsEnumerable.call(n,f)){r.push(i);continue}const u=e[f],a=n[f];u!==a&&(Array.isArray(u)&&Array.isArray(a)||l(u)&&l(a)?ie(u,a,i+".",r,o,s):o!==void 0&&!fn(u,a)&&o.push(i))}s.delete(e)}function Yn(e,n){if(!(Array.isArray(e)&&Array.isArray(n)||l(e)&&l(n)))throw new TypeError("diff: `a` and `b` must both be plain objects or both be arrays");const t={added:[],removed:[],changed:[]};return ie(e,n,"",t.removed,t.changed,new Set),ie(n,e,"",t.added,void 0,new Set),t}function Gn(e,n){return Pe("findKey",e,n)?.[0]}function Zn(e,n){return Pe("findEntry",e,n)}function Pe(e,n,t){j(e,"predicate",t);for(const r of Object.keys(n)){const o=n[r];if(t(o,r,n))return[r,o]}}function Qn(e,n){j("mapEntries","fn",n);const t={};for(const r of Object.keys(e)){const o=n(e[r],r,e);if(o===void 0)continue;const s=Array.isArray(o)?o[0]:void 0;if(typeof s!="string"&&typeof s!="number"&&typeof s!="symbol")throw new TypeError(`mapEntries: \`fn\` must return undefined or a [key, value] array with a string, number or symbol key, got ${m(o)} for "${r}"`);x(t,s,o[1])}return t}function fe(e,n,t){if(!D(e))return e;if(t?.includes(e))throw new TypeError("sortKeys: cannot sort a circular structure");t?.push(e);let r;if(Array.isArray(e)){const o=new Array(e.length);for(let s=0;s<e.length;s++)s in e&&(o[s]=t?fe(e[s],n,t):e[s]);r=o}else{r=q(e);for(const o of W(e,Object.keys(e).sort(n))){const s=e[o];x(r,o,t?fe(s,n,t):s)}}return t?.pop(),r}function vn(e,n={}){J("sortKeys","object",e);const{compare:t,deep:r}=n;return t!==void 0&&j("sortKeys","compare",t),fe(e,t,r===!0?[]:void 0)}function Ce(e,n,t){if(t.includes(n))throw new TypeError("evolve: `transforms` must not be circular");t.push(n);const r=Te(e);for(const o of T(n)){const s=n[o],f=l(s);if(!f&&typeof s!="function")throw new TypeError(`evolve: \`transforms.${String(o)}\` must be a function or a plain object, got ${m(s)}`);if(!g(e,o))continue;const i=e[o];f?D(i)&&(r[o]=Ce(i,s,t)):r[o]=s(i)}return t.pop(),r}function et(e,n){if(J("evolve","object",e),!l(n))throw new TypeError(`evolve: \`transforms\` must be a plain object, got ${m(n)}`);return Ce(e,n,[])}function H(e,n,t,r){if(!D(n))return n;if(r.includes(n))throw new TypeError(`${e}: cannot transform a circular structure`);r.push(n);let o;if(Array.isArray(n)){const s=new Array(n.length);for(let f=0;f<n.length;f++)f in n&&(s[f]=H(e,n[f],t,r));o=s}else{o=q(n);const s=T(n),f=[];for(const i of s){const u=typeof i=="string"?t(i):i;if(typeof u!="string"&&typeof u!="symbol")throw new TypeError(`${e}: \`fn\` must return a string, got ${m(u)} for "${String(i)}"`);if(g(o,u))throw new RangeError(`${e}: keys "${String(s[f.indexOf(u)])}" and "${String(i)}" both become "${String(u)}"`);f.push(u),x(o,u,H(e,n[i],t,r))}}return r.pop(),o}function nt(e,n){return j("transformKeysDeep","fn",n),H("transformKeysDeep",e,n,[])}function ue(e,n,t){const r=new Map;return H(e,n,function(o){let s=r.get(o);return s===void 0&&(s=o==="__proto__"?o:t(o),r.set(o,s)),s},[])}function tt(e){return ue("toCamelCaseKeys",e,ze)}function rt(e){return ue("toSnakeCaseKeys",e,_e)}function ot(e){return ue("toKebabCaseKeys",e,Ne)}function Ee(e,n){const t=Object.keys(e).sort();let r="{";for(let o=0;o<t.length;o++)r+=(o===0?"":",")+JSON.stringify(t[o])+":"+R(e[t[o]],n);return r+"}"}function ae(e,n){let t="[";for(let r=0;r<e.length;r++)r>0&&(t+=","),r in e&&(t+=R(e[r],n));return t+"]"}function De(e,n){const t=[];for(const r of e)t.push(R(r,n));return"["+t.sort().join(",")+"]"}function un(e,n){if(v(e))throw new TypeError(`stableStringify: cannot serialize a ${k(e).slice(8,-1)}`);if($(e))return`Date(${R(e.getTime(),n)})`;if(V(e))return`RegExp(${JSON.stringify(String(e))})`;if(A(e))return`Map(${De(e,n)})`;if(S(e))return`Set(${De(e,n)})`;if(Q(e)){if(!ArrayBuffer.isView(e))return`${k(e).slice(8,-1)}(${ae(new Uint8Array(e),n)})`;const f=pe.call(e),i=f===void 0?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e;return`${f??"DataView"}(${ae(i,n)})`}const[t,r]=N(e);if(t)return`${k(e).slice(8,-1)}(${R(r,n)})`;const o=Object.getPrototypeOf(e)?.constructor;return(typeof o=="function"&&o.name!==""?o.name:"?")+Ee(e,n)}function R(e,n){switch(typeof e){case"string":return JSON.stringify(e);case"number":return e===0&&1/e<0?"-0":String(e);case"boolean":case"undefined":return String(e);case"bigint":return`${e}n`;case"object":if(e===null)return"null";break;default:throw new TypeError(`stableStringify: cannot serialize a ${typeof e}`)}if(n.includes(e))throw new TypeError("stableStringify: cannot serialize a circular structure");n.push(e);const t=l(e)?Ee(e,n):Array.isArray(e)?ae(e,n):un(e,n);return n.pop(),t}function an(e){return R(e,[])}function st(e,n=0){qe("hash","seed",n,Number.isInteger(n)&&n>=0&&n<=4294967295,"an integer between 0 and 4294967295");const t=an(e);let r=3735928559^n,o=1103547991^n;for(let s=0;s<t.length;s++){const f=t.charCodeAt(s);r=Math.imul(r^f,2654435761),o=Math.imul(o^f,1597334677)}return r=Math.imul(r^r>>>16,2246822507)^Math.imul(o^o>>>13,3266489909),o=Math.imul(o^o>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),4294967296*(2097151&o)+(r>>>0)}export{Ge as clone,qn as compactObject,En as deepClone,Wn as deepFreeze,Dn as deepMerge,Rn as deepMergeWith,$n as defaults,Bn as defaultsDeep,Mn as defaultsWith,Xn as deleteFromObjectByKeys,Tn as deleteProperty,Yn as diff,et as evolve,Zn as findEntry,Gn as findKey,Fn as flattenObject,On as getFromObjectByKeys,bn as getProperty,xn as getPropertyNames,Hn as hasInObjectByKeys,ln as hasProperty,st as hash,hn as invert,Re as isArray,$e as isBoolean,kn as isEmpty,fn as isEqual,In as isEqualWith,X as isError,P as isFunction,A as isMap,Ln as isMatch,Me as isNull,Ie as isNumber,c as isObject,B as isPromise,V as isRegExp,S as isSet,Le as isString,Ve as isSymbol,We as isUndefined,ye as isWeakMap,de as isWeakSet,Qn as mapEntries,jn as mapKeys,Kn as mapValues,pn as merge,mn as omit,Un as omitBy,Pn as omitInObjectByKeys,wn as pick,Oe as pickBy,An as setInObjectByKeys,gn as setProperty,Vn as shallowEqual,vn as sortKeys,an as stableStringify,tt as toCamelCaseKeys,ot as toKebabCaseKeys,Cn as toPath,rt as toSnakeCaseKeys,nt as transformKeysDeep,Nn as typedEntries,_n as typedFromEntries,zn as typedKeys,Jn as unflattenObject,Sn as updateInObjectByKeys};
|
|
1
|
+
import{isDate as $,isArrayBuffer as Ee,isError as ce,isFunction as C,isMap as A,isObject as y,isPlainObject as l,isPromise as L,isRegExp as H,isSet as S,isWeakMap as De,isWeakSet as Re}from"../guards/index.js";import{toCamelCase as $e,toKebabCase as Me,toSnakeCase as Be}from"../strings/index.js";import{assertFunction as h,assertInteger as Ie,assertNumber as Le,describe as m}from"../utils/assert.js";const X=new Set(["__proto__","constructor","prototype"]);function g(e,n){return Object.prototype.hasOwnProperty.call(e,n)}function T(e){return V(e,Object.keys(e))}function V(e,n){for(const t of Object.getOwnPropertySymbols(e))Object.prototype.propertyIsEnumerable.call(e,t)&&n.push(t);return n}function Y(e,n,t){Object.defineProperty(e,n,{value:t,writable:!0,enumerable:!0,configurable:!0})}function G(e,n,t){n in e&&!g(e,n)?Y(e,n,t):e[n]=t}function x(e,n,t){n in Object.prototype?Y(e,n,t):e[n]=t}function W(e,n){return n==="prototype"||n in Object.prototype&&Ve(e,n)}function Ve(e,n){if(n==="__proto__"||n==="constructor")return!0;for(let t=e;t!==Object.prototype;t=Object.getPrototypeOf(t))if(t===null||g(t,n))return!1;return!0}function M(e,n){const t=e[n];return t===void 0||!W(e,n)?t:void 0}function k(e){return Object.prototype.toString.call(e)}function j(e,n){return Object.setPrototypeOf(e,Object.getPrototypeOf(n))}const ye=Object.getOwnPropertyDescriptor(Object.getPrototypeOf(Uint8Array.prototype),Symbol.toStringTag)?.get,We=typeof SharedArrayBuffer=="function"?Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype,"byteLength")?.get:void 0;function ze(e){if(!ArrayBuffer.isView(e))return j(e.slice(0),e);const n=e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength),t=ye.call(e)??"DataView",r=globalThis[t];return j(new r(n),e)}function Z(e){if(ArrayBuffer.isView(e))return!0;const n=k(e);if(n==="[object ArrayBuffer]")return Ee(e);if(n!=="[object SharedArrayBuffer]")return!1;try{return We?.call(e)!==void 0}catch{return!1}}function Q(e){return De(e)||Re(e)||L(e)}const Ne=new Map([["[object Number]",Number.prototype.valueOf],["[object String]",String.prototype.valueOf],["[object Boolean]",Boolean.prototype.valueOf],["[object BigInt]",BigInt.prototype.valueOf],["[object Symbol]",Symbol.prototype.valueOf]]);function z(e){const n=Ne.get(k(e));if(n===void 0)return[!1,void 0];try{return[!0,n.call(e)]}catch{return[!1,void 0]}}function _e(e){const n=new RegExp(e.source,e.flags);return n.lastIndex=e.lastIndex,j(n,e)}function v(e,n){return n===Object.prototype?!L(e)&&k(e)==="[object Object]"&&!ArrayBuffer.isView(e):n===Array.prototype&&Array.isArray(e)&&!L(e)&&k(e)==="[object Array]"}function de(e){const n=e.length,t=Object.keys(e);return t.length===n&&(n===0||t[n-1]===String(n-1))&&Object.getOwnPropertySymbols(e).length===0}function sn(e,...n){if(n.length===1)return{...e,...n[0]};let t={...e};for(const r of n)t={...t,...r};return t}function Ue(e){if(y(e)&&v(e,Object.getPrototypeOf(e))){if(!Array.isArray(e))return{...e};if(de(e))return Array.from(e)}return E(e)}function fn(e,n){return g(e,n)}function un(e,n){return M(e,n)}function an(e,n,t){if(n==="__proto__")throw new RangeError('setProperty: `property` must not be the unsafe key "__proto__"');e[n]=t}function cn(e,n){delete e[n]}function yn(e){return Object.getOwnPropertyNames(e)}function dn(e){if(Array.isArray(e))return e.length===0;if(A(e)||S(e))return e.size===0;const n=Object(e);for(const t in n)if(g(n,t))return!1;for(const t of Object.getOwnPropertySymbols(n))if(Object.prototype.propertyIsEnumerable.call(n,t))return!1;return!0}function pn(e,n){const t={};for(const r of n){const o=e[r];(o!==void 0||r in e)&&!W(e,r)&&x(t,r,o)}return t}function ln(e,n){const t=new Set;for(const o of n)t.add(typeof o=="number"?String(o):o);const r={};for(const o of T(e))t.has(o)||x(r,o,e[o]);return r}function bn(e,n){h("mapValues","fn",n);const t=Array.isArray(e),r=t?new Array(e.length):{};for(const o of T(e)){const s=n(e[o],o,e);t?G(r,o,s):x(r,o,s)}return r}function gn(e,n){h("mapKeys","fn",n);const t={};for(const r of T(e)){const o=e[r];x(t,n(o,r,e),o)}return t}function Tn(e){const n={};for(const t of Object.keys(e)){const r=e[t];if(typeof r!="string"&&typeof r!="number"&&typeof r!="symbol")throw new TypeError(`invert: \`object.${t}\` must be a string, number or symbol, got ${m(r)}`);x(n,r,t)}return n}const qe=2**32-1,ee=/^(?:0|[1-9]\d*)$/,ne=1e3;function pe(e){return ee.test(e)?Number(e):-1}function N(e,n,t,r){const o=t.split(r);for(const s of o)if(s===""||X.has(s))throw new RangeError(`${e}: ${n} must not contain ${s===""?"empty segments":`the unsafe segment "${s}"`}, got ${JSON.stringify(t)}`);return o}function le(e,n,t,r,o,s,f,i){let u=e;const a=n.length-1;let c=!1;for(let d=0;d<a;d++){const b=n[d],w=!c&&g(u,b);let p=w?u[b]:void 0;if(i!==void 0&&w&&!i.has(p))throw new TypeError(`${s}: cannot set "${r}": "${n.slice(0,d+1).join(o)}" is already set by another key`);if(p==null){const ae=pe(n[d+1]),I=ae!==-1&&ae<=f?[]:{};c&&!(b in u)?u[b]=I:Y(u,b,I),i?.add(I),c=!0,p=I}else{if(!y(p)&&!C(p))throw new TypeError(`${s}: cannot set "${r}": "${n.slice(0,d+1).join(o)}" is a ${typeof p}, not an object`);i!==void 0&&Number(n[d+1])>f&&ee.test(n[d+1])&&Array.isArray(p)&&(p=Object.assign({},p),i.add(p),u[b]=p)}u=p}if(i!==void 0&&g(u,n[a]))throw new TypeError(`${s}: cannot set "${r}": "${n.join(o)}" already holds values set by other keys`);u[n[a]]=t}function xn(e,n,t){let r=e;if(n.indexOf(".")===-1)r=r==null?void 0:M(r,n);else for(const o of n.split(".")){if(r==null)return t;r=M(r,o)}return r===void 0?t:r}function kn(e,n,t){return le(e,N("setPath","`path`",n,"."),t,n,".","setPath",ne),e}function be(e){return Array.isArray(e)?Ue(e):Object.getPrototypeOf(e)===null?Object.assign(Object.create(null),e):{...e}}function te(e,n,t,r){const o=be(e);return r?Reflect.deleteProperty(o,n):G(o,n,t),o}function ge(e,n,t,r,o,s){const f=r[o],i=g(t,f),u=i?t[f]:void 0;if(o===r.length-1){if(s===void 0)return i?te(t,f,void 0,!0):t;const d=s(u);return i&&Object.is(d,u)?t:te(t,f,d,!1)}let a;if(D(u))a=u;else if(u==null||s===void 0&&!y(u)&&!C(u)){if(s===void 0)return t;const d=pe(r[o+1]);a=d!==-1&&d<=ne?[]:{}}else{const d=y(u)||C(u)?"an object that is neither a plain object nor an array":`a ${typeof u}`;throw new TypeError(`${e}: cannot update "${n}": "${r.slice(0,o+1).join(".")}" is ${d}`)}const c=ge(e,n,a,r,o+1,s);return c===u?t:te(t,f,c,!1)}function Te(e,n,t,r){return F(e,"target",n),ge(e,t,n,N(e,"`path`",t,"."),0,r)}function wn(e,n,t){return Te("updatePath",e,n,typeof t=="function"?t:function(){return t})}function mn(e,n){return Te("omitPath",e,n,void 0)}function P(e,n,t){throw new RangeError(`toPath: \`path\` ${t} at index ${n}, got ${JSON.stringify(e)}`)}function Kn(e){if(typeof e!="string")throw new TypeError(`toPath: \`path\` must be a string, got ${m(e)}`);const n=[];let t=0,r=!1;for(;;){const o=t;let s="";if(e[t]==="["&&!r){const f=e[++t];if(f==='"'||f==="'"){for(let i=e[++t];i!==f;i=e[++t])i===void 0&&P(e,o,"has an unterminated quoted key"),i==="\\"&&(i=e[++t],i!=="\\"&&i!=='"'&&i!=="'"&&P(e,t-1,"has an invalid escape")),s+=i;t++}else{const i=e.indexOf("]",t);s=e.slice(t,i===-1?t:i),ee.test(s)||P(e,o,"must hold a canonical index or a quoted key in brackets"),t=i}e[t]!=="]"&&P(e,t,"is missing ']'"),t++}else{for(;t<e.length&&e[t]!=="."&&e[t]!=="["&&e[t]!=="]";)t++;t===o&&P(e,o,"has an empty segment"),s=e.slice(o,t)}if(X.has(s)&&P(e,o,`has the unsafe segment "${s}"`),n.push(s),t===e.length)return n;r=e[t]===".",r?t++:e[t]!=="["&&P(e,t,`has an unexpected ${JSON.stringify(e[t])}`)}}function E(e,n){if(!y(e))return e;const t=n?.get(e);if(t!==void 0)return t;if(v(e,Object.getPrototypeOf(e))){if(!Array.isArray(e)){const i={...e};n?.set(e,i);for(const u of T(i))i[u]=_(i[u],n);return i}if(de(e)){const i=new Array(e.length);n?.set(e,i);for(let u=0;u<e.length;u++)i[u]=_(e[u],n);return i}}if(Q(e))return e;const[r,o]=z(e);if(r)return j(Object(o),e);if($(e))return j(new Date(e.getTime()),e);if(H(e))return _e(e);if(Z(e))return ze(e);if(A(e)){if(n===void 0)return j(new Map(e),e);const i=j(new Map,e);return n.set(e,i),e.forEach(function(u,a){i.set(E(a,n),E(u,n))}),i}if(S(e)){if(n===void 0)return j(new Set(e),e);const i=j(new Set,e);return n.set(e,i),e.forEach(function(u){i.add(E(u,n))}),i}const s=ce(e),f=!s&&Array.isArray(e)?j(new Array(e.length),e):Object.create(Object.getPrototypeOf(e));n?.set(e,f);for(const i of s?Reflect.ownKeys(e):T(e))if(s){const u=Object.getOwnPropertyDescriptor(e,i);"value"in u&&(u.value=_(u.value,n)),Object.defineProperty(f,i,u)}else G(f,i,_(e[i],n));return f}function _(e,n){return n===void 0?e:E(e,n)}function hn(e){return E(e,new Map)}function Fe(e,n,t){const r=[].concat(e,n);return t?Array.from(new Set(r)):r}function U(e){return Object.getPrototypeOf(e)===null?Object.create(null):{}}function re(e,n,t,r,o){if(t.includes(n))throw new TypeError(`${r.caller}: cannot merge objects with circular references`);t.push(n);const{customizer:s,fill:f,arrays:i}=r,u=s===void 0&&!f&&i==="replace";for(const a of T(n)){if(X.has(a))continue;const c=n[a],d=r.deep&&l(c);let b=c;if(d||!u){const w=g(e,a)?e[a]:void 0;if(b=s===void 0?void 0:s(w,c,{key:a,path:[...o,a]}),b===void 0){const p=f&&w!==void 0&&!(r.nullish&&w===null);if(d&&(l(w)||!p))o.push(a),b=re(l(w)?w:U(c),c,t,r,o),o.pop();else if(i!=="replace"&&Array.isArray(w)&&Array.isArray(c))b=Fe(w,c,i==="union");else{if(p)continue;b=c}}}x(e,a,b)}return t.pop(),e}function B(e,n,t){if(!l(n))throw new TypeError(`${e.caller}: \`target\` must be a plain object, got ${m(n)}`);const r=[],o=e.customizer===void 0?e:{...e,customizer:void 0},s=re(U(n),n,r,o,[]);for(let f=0;f<t.length;f++){const i=t[f];if(i!=null){if(!l(i))throw new TypeError(`${e.caller}: \`sources[${f}]\` must be a plain object, got ${m(i)}`);re(s,i,r,e,[])}}return s}function xe(e,n,t){if(!y(n))throw new TypeError(`${e}: \`options\` must be an object, got ${m(n)}`);const{arrays:r="replace",customizer:o,missing:s="undefined",deep:f}=n;if(r!=="replace"&&r!=="concat"&&r!=="union")throw new RangeError(`${e}: \`arrays\` must be 'replace', 'concat' or 'union', got ${JSON.stringify(r)}`);if(s!=="undefined"&&s!=="nullish")throw new RangeError(`${e}: \`missing\` must be 'undefined' or 'nullish', got ${JSON.stringify(s)}`);return o!==void 0&&h(e,"customizer",o),{caller:e,deep:!t||f===!0,fill:t,nullish:s==="nullish",arrays:r,customizer:o}}const Je={caller:"deepMerge",deep:!0,fill:!1,nullish:!1,arrays:"replace",customizer:void 0};function jn(e,...n){return B(Je,e,n)}function On(e,n,...t){return B(xe("deepMergeWith",e,!1),n,t)}const He={caller:"defaults",deep:!1,fill:!0,nullish:!1,arrays:"replace",customizer:void 0},Xe={caller:"defaultsDeep",deep:!0,fill:!0,nullish:!1,arrays:"replace",customizer:void 0};function An(e,...n){return B(He,e,n)}function Sn(e,...n){return B(Xe,e,n)}function Pn(e,n,...t){return B(xe("defaultsWith",e,!0),n,t)}function K(e,n){return e===n||e!==e&&n!==n}function Ye(e,n,t){if(e.size!==n.size)return!1;const r=Array.from(n).filter(function([s]){return y(s)}),o=[];for(const[s,f]of e){if(!y(s)){if(!n.has(s)||!O(f,n.get(s),t,s))return!1;continue}const i=r.findIndex(function([u,a],c){return!o[c]&&O(s,u,t)&&O(f,a,t,s)});if(i===-1)return!1;o[i]=!0}return!0}function Ge(e,n,t){if(e.size!==n.size)return!1;const r=Array.from(n).filter(y),o=[];for(const s of e){if(!y(s)){if(!n.has(s))return!1;continue}const f=r.findIndex(function(i,u){return!o[u]&&O(s,i,t)});if(f===-1)return!1;o[f]=!0}return!0}function Ze(e,n){let t=e,r=n;if(!ArrayBuffer.isView(e))t=new Uint8Array(e),r=new Uint8Array(n);else if(k(e)==="[object DataView]"){const o=n;t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),r=new Uint8Array(o.buffer,o.byteOffset,o.byteLength)}return t.length===r.length&&Array.prototype.every.call(t,function(o,s){return K(o,r[s])})}function ke(e,n,t){const r=T(e),o=T(n);if(r.length!==o.length)return!1;for(const s of r)if(!Object.prototype.propertyIsEnumerable.call(n,s)||!O(e[s],n[s],t,s))return!1;return!0}function we(e,n,t){if(v(e,Object.getPrototypeOf(e)))return(!Array.isArray(e)||e.length===n.length)&&ke(e,n,t);if(Q(e))return!1;if($(e))return K(e.getTime(),n.getTime());if(H(e))return e.source===n.source&&e.flags===n.flags;if(A(e))return Ye(e,n,t);if(S(e))return Ge(e,n,t);if(Z(e))return Ze(e,n);const[r,o]=z(e);if(r){const[s,f]=z(n);if(!s||!K(o,f))return!1}return ce(e)&&(e.name!==n.name||e.message!==n.message)||Array.isArray(e)&&e.length!==n.length?!1:ke(e,n,t)}function me(e,n){return Object.getPrototypeOf(e)===Object.getPrototypeOf(n)&&k(e)===k(n)}function oe(e,n,t){for(const[r,o]of e)if(r===n&&o===t)return!0;return!1}function O(e,n,t,r){if(t.customizer!==void 0)return Qe(e,n,t,r,t.customizer);if(K(e,n))return!0;if(!y(e)||!y(n)||!me(e,n))return!1;if(oe(t,e,n))return!0;t.push([e,n]);const o=we(e,n,t);return t.pop(),o}function Qe(e,n,t,r,o){if(Object.is(e,n))return!0;const s=y(e)&&y(n);if(s&&oe(t,e,n))return!0;const f=t.length,i=[];for(let c=1;c<f;c++)i.push(t[c][2]);f>0&&i.push(r);const u=t[f-1];s&&t.push([e,n,r]);let a=o(e,n,{key:r,path:i,parentA:u?.[0],parentB:u?.[1],equals:t.equals});return a===void 0&&(a=K(e,n)||s&&me(e,n)&&we(e,n,t)),s&&t.pop(),!!a}function ve(e,n){return O(e,n,[])}function Cn(e,n,t){h("isEqualWith","customizer",t);const r=[];return r.customizer=t,r.equals=function(o,s){return O(o,s,r)},O(e,n,r)}function q(e,n,t,r){if(K(e,n))return!0;const o=l(n);if(!o&&!Array.isArray(n))return y(n)&&O(e,n,[]);if(!(y(e)||C(e))||!o&&!Array.isArray(e))return!1;if(oe(r,e,n))return!0;r.push([e,n]);let s;if(o)s=T(n).every(function(f){const i=n[f],u=M(e,f);return i===void 0?u===void 0&&f in e&&!W(e,f):q(u,i,t,r)});else{const f=e;s=t?n.every(function(i){return f.some(function(u){return q(u,i,t,r)})}):f.length===n.length&&n.every(function(i,u){return q(f[u],i,t,r)})}return r.pop(),s}function En(e,n,t={}){const r=t.arrays??"exact";if(r!=="exact"&&r!=="subset")throw new RangeError(`isMatch: \`arrays\` must be 'exact' or 'subset', got ${JSON.stringify(r)}`);return q(e,n,r==="subset",[])}function Dn(e,n){if(K(e,n))return!0;if(!y(e)||!y(n))return!1;const t=Object.getPrototypeOf(e);if(t!==Object.getPrototypeOf(n))return!1;if(t!==Object.prototype&&t!==null){const r=k(e);if(r!==k(n))return!1;if(Array.isArray(e)){if(!Array.isArray(n)||e.length!==n.length)return!1;for(let o=0;o<e.length;o++){const s=e[o];if(!K(s,n[o])||s===void 0&&o in e!=o in n)return!1}return!0}if(A(e)){const o=n;if(!A(n)||e.size!==o.size)return!1;for(const[s,f]of e)if(!o.has(s)||!K(f,o.get(s)))return!1;return!0}if(S(e)){const o=n;if(!S(n)||e.size!==o.size)return!1;for(const s of e)if(!o.has(s))return!1;return!0}if($(e))return $(n)&&K(e.getTime(),n.getTime());if(r!=="[object Object]"||L(e))return!1}return Ke(e,n,Object.keys(e),Object.keys(n))&&Ke(e,n,V(e,[]),V(n,[]))}function Ke(e,n,t,r){if(t.length!==r.length)return!1;for(let o=0;o<t.length;o++){const s=t[o];if(s!==r[o]&&!Object.prototype.propertyIsEnumerable.call(n,s)||!K(e[s],n[s]))return!1}return!0}function Rn(e){const n=new WeakSet,t=[e];for(;t.length>0;){const r=t.pop();if(!(!y(r)||n.has(r)||ArrayBuffer.isView(r))){n.add(r),A(r)?r.forEach(function(o,s){t.push(s,o)}):S(r)&&r.forEach(function(o){t.push(o)});for(const o of Reflect.ownKeys(r))t.push(Object.getOwnPropertyDescriptor(r,o).value);Object.freeze(r)}}return e}function $n(e){return Object.keys(e)}function Mn(e){return Object.entries(e)}function Bn(e){const n={};for(const[t,r]of e)x(n,t,r);return n}function he(e,n){h("pickBy","predicate",n);const t={};for(const r of T(e)){const o=e[r];n(o,r,e)&&x(t,r,o)}return t}function In(e,n){return h("omitBy","predicate",n),he(e,function(t,r,o){return!n(t,r,o)})}function Ln(e){return he(e,function(n){return n!==void 0})}function je(e,n){const t=n.separator??".";if(typeof t!="string")throw new TypeError(`${e}: \`separator\` must be a string, got ${m(t)}`);if(t==="")throw new RangeError(`${e}: \`separator\` must not be empty`);return t}function D(e){return Array.isArray(e)||l(e)}function F(e,n,t){if(!D(t))throw new TypeError(`${e}: \`${n}\` must be a plain object or an array, got ${m(t)}`)}function Oe(e,n,t,r,o,s){if(s.includes(e))throw new TypeError("flattenObject: cannot flatten a circular structure");s.push(e);for(const f of n){const i=e[f],u=t+f,a=D(i)?Object.keys(i):void 0;a!==void 0&&a.length>0?Oe(i,a,u+r,r,o,s):x(o,u,i)}s.pop()}function Vn(e,n={}){const t=je("flattenObject",n);F("flattenObject","object",e);const r={};return Oe(e,Object.keys(e),"",t,r,[]),r}function Wn(e,n={}){const t=je("unflattenObject",n),r=n.arrayLimit??ne;Ie("unflattenObject","arrayLimit",r,0,!0);const o=Math.min(r,qe-1),s={},f=new WeakSet;for(const i of Object.keys(e))le(s,N("unflattenObject","`record` keys",i,t),e[i],i,t,"unflattenObject",o,f);return s}function zn(e,n){const t=n.split("."),r=t.length-1;let o=e;for(let f=0;f<r&&o!=null;f++)o=M(o,t[f]);if(o==null)return!1;const s=t[r];return s in Object(o)&&!W(o,s)}function Nn(e,n){const t=N("deletePath","`path`",n,"."),r=t.length-1;let o=e;for(let f=0;f<r;f++){if(!(y(o)||C(o))||!g(o,t[f]))return!1;o=o[t[f]]}const s=t[r];return(y(o)||C(o))&&g(o,s)&&Reflect.deleteProperty(o,s)}function se(e,n,t,r,o,s){if(s.has(e))throw new TypeError("diff: cannot diff circular structures");s.add(e);for(const f of Object.keys(e)){const i=t+f;if(!Object.prototype.propertyIsEnumerable.call(n,f)){r.push(i);continue}const u=e[f],a=n[f];u!==a&&(Array.isArray(u)&&Array.isArray(a)||l(u)&&l(a)?se(u,a,i+".",r,o,s):o!==void 0&&!ve(u,a)&&o.push(i))}s.delete(e)}function _n(e,n){if(!(Array.isArray(e)&&Array.isArray(n)||l(e)&&l(n)))throw new TypeError("diff: `a` and `b` must both be plain objects or both be arrays");const t={added:[],removed:[],changed:[]};return se(e,n,"",t.removed,t.changed,new Set),se(n,e,"",t.added,void 0,new Set),t}function Un(e,n){return Ae("findKey",e,n)?.[0]}function qn(e,n){return Ae("findEntry",e,n)}function Ae(e,n,t){h(e,"predicate",t);for(const r of Object.keys(n)){const o=n[r];if(t(o,r,n))return[r,o]}}function Fn(e,n){h("mapEntries","fn",n);const t={};for(const r of Object.keys(e)){const o=n(e[r],r,e);if(o===void 0)continue;const s=Array.isArray(o)?o[0]:void 0;if(typeof s!="string"&&typeof s!="number"&&typeof s!="symbol")throw new TypeError(`mapEntries: \`fn\` must return undefined or a [key, value] array with a string, number or symbol key, got ${m(o)} for "${r}"`);x(t,s,o[1])}return t}function ie(e,n,t){if(!D(e))return e;if(t?.includes(e))throw new TypeError("sortKeys: cannot sort a circular structure");t?.push(e);let r;if(Array.isArray(e)){const o=new Array(e.length);for(let s=0;s<e.length;s++)s in e&&(o[s]=t?ie(e[s],n,t):e[s]);r=o}else{r=U(e);for(const o of V(e,Object.keys(e).sort(n))){const s=e[o];x(r,o,t?ie(s,n,t):s)}}return t?.pop(),r}function Jn(e,n={}){F("sortKeys","object",e);const{compare:t,deep:r}=n;return t!==void 0&&h("sortKeys","compare",t),ie(e,t,r===!0?[]:void 0)}function Se(e,n,t){if(t.includes(n))throw new TypeError("evolve: `transforms` must not be circular");t.push(n);const r=be(e);for(const o of T(n)){const s=n[o],f=l(s);if(!f&&typeof s!="function")throw new TypeError(`evolve: \`transforms.${String(o)}\` must be a function or a plain object, got ${m(s)}`);if(!g(e,o))continue;const i=e[o];f?D(i)&&(r[o]=Se(i,s,t)):r[o]=s(i)}return t.pop(),r}function Hn(e,n){if(F("evolve","object",e),!l(n))throw new TypeError(`evolve: \`transforms\` must be a plain object, got ${m(n)}`);return Se(e,n,[])}function J(e,n,t,r){if(!D(n))return n;if(r.includes(n))throw new TypeError(`${e}: cannot transform a circular structure`);r.push(n);let o;if(Array.isArray(n)){const s=new Array(n.length);for(let f=0;f<n.length;f++)f in n&&(s[f]=J(e,n[f],t,r));o=s}else{o=U(n);const s=T(n),f=[];for(const i of s){const u=typeof i=="string"?t(i):i;if(typeof u!="string"&&typeof u!="symbol")throw new TypeError(`${e}: \`fn\` must return a string, got ${m(u)} for "${String(i)}"`);if(g(o,u))throw new RangeError(`${e}: keys "${String(s[f.indexOf(u)])}" and "${String(i)}" both become "${String(u)}"`);f.push(u),x(o,u,J(e,n[i],t,r))}}return r.pop(),o}function Xn(e,n){return h("transformKeysDeep","fn",n),J("transformKeysDeep",e,n,[])}function fe(e,n,t){const r=new Map;return J(e,n,function(o){let s=r.get(o);return s===void 0&&(s=o==="__proto__"?o:t(o),r.set(o,s)),s},[])}function Yn(e){return fe("toCamelCaseKeys",e,$e)}function Gn(e){return fe("toSnakeCaseKeys",e,Be)}function Zn(e){return fe("toKebabCaseKeys",e,Me)}function Pe(e,n){const t=Object.keys(e).sort();let r="{";for(let o=0;o<t.length;o++)r+=(o===0?"":",")+JSON.stringify(t[o])+":"+R(e[t[o]],n);return r+"}"}function ue(e,n){let t="[";for(let r=0;r<e.length;r++)r>0&&(t+=","),r in e&&(t+=R(e[r],n));return t+"]"}function Ce(e,n){const t=[];for(const r of e)t.push(R(r,n));return"["+t.sort().join(",")+"]"}function en(e,n){if(Q(e))throw new TypeError(`stableStringify: cannot serialize a ${k(e).slice(8,-1)}`);if($(e))return`Date(${R(e.getTime(),n)})`;if(H(e))return`RegExp(${JSON.stringify(String(e))})`;if(A(e))return`Map(${Ce(e,n)})`;if(S(e))return`Set(${Ce(e,n)})`;if(Z(e)){if(!ArrayBuffer.isView(e))return`${k(e).slice(8,-1)}(${ue(new Uint8Array(e),n)})`;const f=ye.call(e),i=f===void 0?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e;return`${f??"DataView"}(${ue(i,n)})`}const[t,r]=z(e);if(t)return`${k(e).slice(8,-1)}(${R(r,n)})`;const o=Object.getPrototypeOf(e)?.constructor;return(typeof o=="function"&&o.name!==""?o.name:"?")+Pe(e,n)}function R(e,n){switch(typeof e){case"string":return JSON.stringify(e);case"number":return e===0&&1/e<0?"-0":String(e);case"boolean":case"undefined":return String(e);case"bigint":return`${e}n`;case"object":if(e===null)return"null";break;default:throw new TypeError(`stableStringify: cannot serialize a ${typeof e}`)}if(n.includes(e))throw new TypeError("stableStringify: cannot serialize a circular structure");n.push(e);const t=l(e)?Pe(e,n):Array.isArray(e)?ue(e,n):en(e,n);return n.pop(),t}function nn(e){return R(e,[])}function Qn(e,n=0){Le("hash","seed",n,Number.isInteger(n)&&n>=0&&n<=4294967295,"an integer between 0 and 4294967295");const t=nn(e);let r=3735928559^n,o=1103547991^n;for(let s=0;s<t.length;s++){const f=t.charCodeAt(s);r=Math.imul(r^f,2654435761),o=Math.imul(o^f,1597334677)}return r=Math.imul(r^r>>>16,2246822507)^Math.imul(o^o>>>13,3266489909),o=Math.imul(o^o>>>16,2246822507)^Math.imul(r^r>>>13,3266489909),4294967296*(2097151&o)+(r>>>0)}export{Ue as clone,Ln as compactObject,hn as deepClone,Rn as deepFreeze,jn as deepMerge,On as deepMergeWith,An as defaults,Sn as defaultsDeep,Pn as defaultsWith,Nn as deletePath,cn as deleteProperty,_n as diff,Hn as evolve,qn as findEntry,Un as findKey,Vn as flattenObject,xn as getPath,un as getProperty,yn as getPropertyNames,zn as hasPath,fn as hasProperty,Qn as hash,Tn as invert,dn as isEmpty,ve as isEqual,Cn as isEqualWith,En as isMatch,Fn as mapEntries,gn as mapKeys,bn as mapValues,sn as merge,ln as omit,In as omitBy,mn as omitPath,pn as pick,he as pickBy,kn as setPath,an as setProperty,Dn as shallowEqual,Jn as sortKeys,nn as stableStringify,Yn as toCamelCaseKeys,Zn as toKebabCaseKeys,Kn as toPath,Gn as toSnakeCaseKeys,Xn as transformKeysDeep,Mn as typedEntries,Bn as typedFromEntries,$n as typedKeys,Wn as unflattenObject,wn as updatePath};
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -12,12 +12,6 @@ export type AnyFunction = (...args: never[]) => unknown;
|
|
|
12
12
|
* type R = UnionToIntersection<{ a: 1 } | { b: 2 }>; // { a: 1 } & { b: 2 }
|
|
13
13
|
*/
|
|
14
14
|
export type UnionToIntersection<U> = (U extends unknown ? (arg: U) => void : never) extends (arg: infer I) => void ? I : never;
|
|
15
|
-
/**
|
|
16
|
-
* Recursively marks every property of `T` as optional.
|
|
17
|
-
*/
|
|
18
|
-
export type DeepPartial<T> = T extends Primitive | AnyFunction | Date | RegExp ? T : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : {
|
|
19
|
-
[K in keyof T]?: DeepPartial<T[K]>;
|
|
20
|
-
};
|
|
21
15
|
/**
|
|
22
16
|
* Recursively marks every property of `T` as `readonly`.
|
|
23
17
|
*/
|
|
@@ -52,18 +46,6 @@ type PathSegmentValue<T, K extends string> = K extends keyof NonNullable<T> ? No
|
|
|
52
46
|
* type V = PathValue<{ a: { b: string } }, 'a.b'>; // string
|
|
53
47
|
*/
|
|
54
48
|
export type PathValue<T, P extends string> = P extends `${infer K}.${infer Rest}` ? PathValue<PathSegmentValue<T, K>, Rest> : PathSegmentValue<T, P>;
|
|
55
|
-
/**
|
|
56
|
-
* Removes the array wrapper from `T`, if any.
|
|
57
|
-
*/
|
|
58
|
-
export type UnArray<T> = T extends ReadonlyArray<infer U> ? U : T;
|
|
59
|
-
/**
|
|
60
|
-
* Picks `K` from `T` and `KNK` from the nested property `KN` (which can be an object or an array of objects).
|
|
61
|
-
* @example
|
|
62
|
-
* type P = NestedPick<User, 'id', 'posts', 'title'>; // { id: number; posts: { title: string }[] }
|
|
63
|
-
*/
|
|
64
|
-
export type NestedPick<T, K extends keyof T, KN extends keyof T, KNK extends keyof UnArray<T[KN]>> = Pick<T, K> & {
|
|
65
|
-
[Key in KN]: T[KN] extends ReadonlyArray<unknown> ? Array<Pick<UnArray<T[KN]>, KNK>> : Pick<UnArray<T[KN]>, KNK>;
|
|
66
|
-
};
|
|
67
49
|
/**
|
|
68
50
|
* Structural subset of the standard `AbortSignal`, so the library works without the DOM or Node type libraries.
|
|
69
51
|
*/
|
package/dist/validate/index.d.ts
CHANGED
|
@@ -78,8 +78,8 @@ export declare function isEmail(value: unknown): value is string;
|
|
|
78
78
|
*
|
|
79
79
|
* The host is also checked against the text, so that for an accepted URL the host a client connects to is the one a reader (or a
|
|
80
80
|
* string-based allow/deny list) sees: `new URL(value).hostname` is the written host, lower-cased, or its punycode form for
|
|
81
|
-
* internationalized names (`münchen.de`, `例え.jp`; each non-ASCII label must stay a punycode label, so `https://ẞa.com`, which IDNA case
|
|
82
|
-
* folding turns into `ssa.com`, is rejected). So the following are also rejected: invisible characters anywhere (format characters
|
|
81
|
+
* internationalized names (`münchen.de`, `例え.jp`; each non-ASCII label must stay a punycode label, so `https://ẞa.com`, which older IDNA case
|
|
82
|
+
* folding turns into `ssa.com`, is rejected there). So the following are also rejected: invisible characters anywhere (format characters
|
|
83
83
|
* such as U+00AD soft hyphen, U+200B zero-width space or bidi controls, and other default-ignorable code points such as U+034F or
|
|
84
84
|
* variation selectors), a backslash in the authority (`http://evil.com\@good.com`, which parsers disagree on), and host names with
|
|
85
85
|
* a `%` (percent-decoded by the parser), an empty label (`https://a..b`, `https://.`; one trailing dot is allowed), characters that
|
package/llms-full.txt
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Key facts for code generation:
|
|
4
4
|
- ESM only, zero dependencies, Node >= 20.19 or any modern browser/runtime. TypeScript types ship in the package.
|
|
5
5
|
- Import from module entry points: `import { debounce } from 'tinkit/functions'` (the root entry exposes namespaces: `import { functions } from 'tinkit'`).
|
|
6
|
-
- Helpers never mutate their inputs unless the name or docs say so (`
|
|
6
|
+
- Helpers never mutate their inputs unless the name or docs say so (`setPath`, `deletePath`).
|
|
7
7
|
- Invalid arguments throw `TypeError` (wrong type) or `RangeError` (invalid value) whose message names the function and the parameter (`fn: param must be …, got …`).
|
|
8
8
|
- Randomised helpers take an optional `random` generator last; the default is `Math.random`. Pass `secureRandom` (random module) for tokens, OTPs and lotteries.
|
|
9
9
|
- Type guards compose into validators: `isShape`, `isArrayOf`, `isUnion`, `isOptional`…; `explain` lists issues with paths, `ensure` throws a `ValidationError`, `toStandardSchema` adapts any guard for tRPC, TanStack Form, Hono and other Standard Schema consumers.
|
|
@@ -18,7 +18,7 @@ Import: `import { … } from 'tinkit/arrays';`
|
|
|
18
18
|
- `last<T>(array: ReadonlyArray<T>): T | undefined` — Get the last item in an array.
|
|
19
19
|
- `flatten<T>(array: ReadonlyArray<T | ReadonlyArray<T>>): T[]` — Flatten an array by exactly one level, like `Array.prototype.flat()` (holes in sparse arrays are skipped).
|
|
20
20
|
- `flattenDeep<T>(array: ReadonlyArray<T>): Array<FlatDeep<T>>` — Recursively flatten nested arrays of any depth, like `Array.prototype.flat(Infinity)` (holes are skipped).
|
|
21
|
-
- `
|
|
21
|
+
- `unique<T>(iterable: Iterable<T>): T[]` — Remove duplicates from an iterable (SameValueZero equality), keeping the first occurrence of each value.
|
|
22
22
|
- `union<T>(a: Iterable<T>, b: Iterable<T>): T[]` — Get the union of two iterables: every distinct value from `a`, then every distinct value of `b` not already in `a`.
|
|
23
23
|
- `intersection<T>(a: Iterable<T>, b: Iterable<T>): T[]` — Get the intersection of two iterables: the distinct values of `a` that also appear in `b`.
|
|
24
24
|
- `difference<T>(a: Iterable<T>, b: Iterable<T>): T[]` — Get the difference of two iterables: the distinct values of `a` that do not appear in `b`.
|
|
@@ -57,7 +57,7 @@ Import: `import { … } from 'tinkit/arrays';`
|
|
|
57
57
|
- `longestCommonSubsequence<T>(a: Iterable<T>, b: Iterable<T>, equals: (x: T, y: T) => boolean = sameValueZero, options: DiffOptions = {}): T[]` — Computes a longest common subsequence of `a` and `b`: the longest list of elements that appear in both, in the same relative order (not necessarily contiguously).
|
|
58
58
|
- `unionBy<T, U = T>(a: Iterable<T>, b: Iterable<U>, keyFn: (item: T | U) => unknown): Array<T | U>` — Like `union`, but items are compared by the key `keyFn` returns (SameValueZero): every item of `a`, then of `b`, whose key was not seen before, so only the FIRST item per key is kept.
|
|
59
59
|
- `symmetricDifferenceBy<T, U = T>(a: Iterable<T>, b: Iterable<U>, keyFn: (item: T | U) => unknown): Array<T | U>` — Like `symmetricDifference`, but items are compared by the key `keyFn` returns (SameValueZero): the items of `a` whose key is not the key of any item of `b`, followed by the items of `b` whose key is not the key of any item of `a`, keeping only the FIRST item per key.
|
|
60
|
-
- `uniqueWith<T>(iterable: Iterable<T>, equals: (x: T, y: T) => boolean): T[]` — Remove the items `equals` to an earlier item, keeping the first occurrence: `
|
|
60
|
+
- `uniqueWith<T>(iterable: Iterable<T>, equals: (x: T, y: T) => boolean): T[]` — Remove the items `equals` to an earlier item, keeping the first occurrence: `unique` with a custom equality, for values that have no identity key (e.g. points within a tolerance).
|
|
61
61
|
- `unionWith<T, U = T>(a: Iterable<T>, b: Iterable<U>, equals: (x: T | U, y: T | U) => boolean): Array<T | U>` — `union` with a custom equality: every item of `a`, then of `b`, not `equals` to an item already kept (first occurrence wins).
|
|
62
62
|
- `differenceWith<T, U = T>(a: Iterable<T>, b: Iterable<U>, equals: (x: T, y: T | U) => boolean): T[]` — `difference` with a custom equality: the items of `a` not `equals` to any item of `b`, keeping only the first of several items of `a` that are `equals` to each other.
|
|
63
63
|
- `intersectionWith<T, U = T>(a: Iterable<T>, b: Iterable<U>, equals: (x: T, y: T | U) => boolean): T[]` — `intersection` with a custom equality: the items of `a` `equals` to some item of `b`, keeping only the first of several items of `a` that are `equals` to each other.
|
|
@@ -104,10 +104,10 @@ Import: `import { … } from 'tinkit/objects';`
|
|
|
104
104
|
- `mapValues<T extends object, R>(object: T, fn: (value: T[keyof T], key: keyof T, object: T) => R): { [K in keyof T]: R }` — Creates a new object with the same own enumerable (string and symbol) keys, whose values are the results of `fn`.
|
|
105
105
|
- `mapKeys<T extends object, K extends PropertyKey>(object: T, fn: (value: T[keyof T], key: keyof T, object: T) => K): Record<K, T[keyof T]>` — Creates a new object with the same values, whose keys are the results of `fn`.
|
|
106
106
|
- `invert<T extends Record<PropertyKey, PropertyKey>>(object: T): Invert<T>` — Creates a new object whose keys are the values of `object` and whose values are the (string) keys.
|
|
107
|
-
- `
|
|
108
|
-
- `
|
|
109
|
-
- `
|
|
110
|
-
- `
|
|
107
|
+
- `getPath<T extends object, P extends NestedKeyOf<T>>(target: T, keys: P): PathValue<T, P>` — Safely reads a nested value through a dot-separated path (array elements are addressed with numeric segments: `'list.0.id'`).
|
|
108
|
+
- `setPath<T extends object>(target: T, path: string, value: unknown): T` — Sets a nested value through a dot-separated path.
|
|
109
|
+
- `updatePath<T extends object, P extends string>(target: T, path: P, valueOrUpdater: PathUpdateValue<T, P> | ((current: PathUpdateValue<T, P>) => PathUpdateValue<T, P>)): T` — IMMUTABLE counterpart of `setPath`: returns a NEW root in which the value at the dot-separated path is replaced by `valueOrUpdater` (or, when it is a function, by `valueOrUpdater(currentValue)`).
|
|
110
|
+
- `omitPath<T extends object, P extends string>(target: T, path: P): OmitAtPath<T, P>` — IMMUTABLE counterpart of `deletePath`: returns a NEW root without the own property at the dot-separated path, copying only the plain objects and arrays on the path (structural sharing).
|
|
111
111
|
- `toPath(path: string): string[]` — Parses a property path written in JavaScript accessor syntax into its segments: dot-separated names (`a.b`) and brackets holding a canonical array index (`[0]`) or a quoted key (`['b.c']`, `["x"]`, with `\\`, `\'` and `\"` as the only escapes).
|
|
112
112
|
- `deepClone<T>(value: T): T` — Creates a deep copy of a value without using `structuredClone`.
|
|
113
113
|
- `deepMerge<T extends object, S extends object[]>(target: T, ...sources: S): DeepMergeAll<T, S>` — Deeply merges plain objects into a NEW object, left to right (later sources win).
|
|
@@ -128,8 +128,8 @@ Import: `import { … } from 'tinkit/objects';`
|
|
|
128
128
|
- `compactObject<T extends object>(object: T): CompactObject<T>` — Creates a SHALLOW copy of an object without the own properties whose value is `undefined`.
|
|
129
129
|
- `flattenObject(object: object, options: FlattenOptions = {}): Record<string, unknown>` — Flattens nested plain objects and arrays into a single-level record mapping each LEAF path to its value.
|
|
130
130
|
- `unflattenObject(record: Readonly<Record<string, unknown>>, options: UnflattenOptions = {}): Record<string, unknown>` — Rebuilds a nested object from a flat record of paths (the inverse of `flattenObject`).
|
|
131
|
-
- `
|
|
132
|
-
- `
|
|
131
|
+
- `hasPath(target: object, path: string): boolean` — Checks whether a dot-separated path exists in an object: it is `true` exactly when `getPath` resolves the path to a property (whose value may be `undefined`) rather than falling back to the default value.
|
|
132
|
+
- `deletePath(target: object, path: string): boolean` — Deletes the property at a dot-separated path.
|
|
133
133
|
- `diff(a: object, b: object): ObjectDiff` — Computes the structural differences between two trees of plain objects and arrays, as dot-separated paths (array elements use numeric segments: `'list.0'`).
|
|
134
134
|
- `findKey<T extends object, S extends T[keyof T]>(object: T, predicate: (value: T[keyof T], key: StringKeyOf<T>, object: T) => value is S): KeysMatching<T, S> | undefined` — Returns the first own enumerable string key (in `Object.keys` order) whose value satisfies `predicate`.
|
|
135
135
|
- `findEntry<T extends object, S extends T[keyof T]>(object: T, predicate: (value: T[keyof T], key: StringKeyOf<T>, object: T) => value is S): [KeysMatching<T, S>, S] | undefined` — Returns the first `[key, value]` own enumerable string-keyed entry whose value satisfies a type-guard `predicate`, narrowed.
|
package/llms.txt
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
Key facts for code generation:
|
|
6
6
|
- ESM only, zero dependencies, Node >= 20.19 or any modern browser/runtime. TypeScript types ship in the package.
|
|
7
7
|
- Import from module entry points: `import { debounce } from 'tinkit/functions'` (the root entry exposes namespaces: `import { functions } from 'tinkit'`).
|
|
8
|
-
- Helpers never mutate their inputs unless the name or docs say so (`
|
|
8
|
+
- Helpers never mutate their inputs unless the name or docs say so (`setPath`, `deletePath`).
|
|
9
9
|
- Invalid arguments throw `TypeError` (wrong type) or `RangeError` (invalid value) whose message names the function and the parameter (`fn: param must be …, got …`).
|
|
10
10
|
- Randomised helpers take an optional `random` generator last; the default is `Math.random`. Pass `secureRandom` (random module) for tokens, OTPs and lotteries.
|
|
11
11
|
- Type guards compose into validators: `isShape`, `isArrayOf`, `isUnion`, `isOptional`…; `explain` lists issues with paths, `ensure` throws a `ValidationError`, `toStandardSchema` adapts any guard for tRPC, TanStack Form, Hono and other Standard Schema consumers.
|