@absoluteui/helpers 0.0.0-stage → 0.13.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/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +47 -2
- package/SECURITY.md +102 -0
- package/dist/array/compare.d.ts +8 -0
- package/dist/array/compare.js +2 -0
- package/dist/array/index.d.ts +328 -0
- package/dist/array/index.js +2 -0
- package/dist/array/tree.d.ts +48 -0
- package/dist/array/tree.js +2 -0
- package/dist/async/batch.d.ts +103 -0
- package/dist/async/batch.js +2 -0
- package/dist/async/concurrency.d.ts +92 -0
- package/dist/async/concurrency.js +2 -0
- package/dist/async/control.d.ts +77 -0
- package/dist/async/control.js +2 -0
- package/dist/async/index.d.ts +8 -0
- package/dist/async/index.js +2 -0
- package/dist/async/signal.d.ts +95 -0
- package/dist/async/signal.js +2 -0
- package/dist/boolean/index.d.ts +83 -0
- package/dist/boolean/index.js +2 -0
- package/dist/business-calendar/days.d.ts +397 -0
- package/dist/business-calendar/days.js +2 -0
- package/dist/business-calendar/describe.d.ts +45 -0
- package/dist/business-calendar/describe.js +2 -0
- package/dist/business-calendar/engine.d.ts +305 -0
- package/dist/business-calendar/engine.js +2 -0
- package/dist/business-calendar/hours.d.ts +96 -0
- package/dist/business-calendar/hours.js +2 -0
- package/dist/business-calendar/index.d.ts +29 -0
- package/dist/business-calendar/index.js +2 -0
- package/dist/business-calendar/internal.d.ts +44 -0
- package/dist/business-calendar/internal.js +2 -0
- package/dist/business-calendar/rules.d.ts +260 -0
- package/dist/business-calendar/rules.js +2 -0
- package/dist/color/index.d.ts +200 -0
- package/dist/color/index.js +2 -0
- package/dist/color/named.d.ts +4 -0
- package/dist/color/named.js +2 -0
- package/dist/compare/index.d.ts +186 -0
- package/dist/compare/index.js +2 -0
- package/dist/convert/index.d.ts +152 -0
- package/dist/convert/index.js +2 -0
- package/dist/csv/index.d.ts +6 -0
- package/dist/csv/index.js +2 -0
- package/dist/csv/parse.d.ts +85 -0
- package/dist/csv/parse.js +12 -0
- package/dist/csv/stringify.d.ts +48 -0
- package/dist/csv/stringify.js +5 -0
- package/dist/date/calendar.d.ts +339 -0
- package/dist/date/calendar.js +2 -0
- package/dist/date/format.d.ts +66 -0
- package/dist/date/format.js +2 -0
- package/dist/date/index.d.ts +26 -0
- package/dist/date/index.js +2 -0
- package/dist/date/intervals.d.ts +110 -0
- package/dist/date/intervals.js +2 -0
- package/dist/date/intl-cache.d.ts +10 -0
- package/dist/date/intl-cache.js +2 -0
- package/dist/date/locale.d.ts +58 -0
- package/dist/date/locale.js +2 -0
- package/dist/date/plain-date.d.ts +105 -0
- package/dist/date/plain-date.js +2 -0
- package/dist/date/plain-time.d.ts +121 -0
- package/dist/date/plain-time.js +2 -0
- package/dist/date/zone.d.ts +121 -0
- package/dist/date/zone.js +2 -0
- package/dist/decimal/index.d.ts +149 -0
- package/dist/decimal/index.js +2 -0
- package/dist/ds/avl.d.ts +50 -0
- package/dist/ds/avl.js +2 -0
- package/dist/ds/bitset.d.ts +46 -0
- package/dist/ds/bitset.js +2 -0
- package/dist/ds/bloom.d.ts +41 -0
- package/dist/ds/bloom.js +2 -0
- package/dist/ds/caches.d.ts +141 -0
- package/dist/ds/caches.js +2 -0
- package/dist/ds/disjoint-set.d.ts +38 -0
- package/dist/ds/disjoint-set.js +2 -0
- package/dist/ds/emitter.d.ts +53 -0
- package/dist/ds/emitter.js +2 -0
- package/dist/ds/graph.d.ts +84 -0
- package/dist/ds/graph.js +2 -0
- package/dist/ds/heap.d.ts +49 -0
- package/dist/ds/heap.js +2 -0
- package/dist/ds/index.d.ts +20 -0
- package/dist/ds/index.js +2 -0
- package/dist/ds/internal.d.ts +19 -0
- package/dist/ds/internal.js +2 -0
- package/dist/ds/interval-tree.d.ts +49 -0
- package/dist/ds/interval-tree.js +2 -0
- package/dist/ds/linked-list.d.ts +54 -0
- package/dist/ds/linked-list.js +2 -0
- package/dist/ds/maps.d.ts +89 -0
- package/dist/ds/maps.js +2 -0
- package/dist/ds/ring.d.ts +99 -0
- package/dist/ds/ring.js +2 -0
- package/dist/ds/sorted.d.ts +104 -0
- package/dist/ds/sorted.js +2 -0
- package/dist/ds/stack.d.ts +28 -0
- package/dist/ds/stack.js +2 -0
- package/dist/ds/trie.d.ts +84 -0
- package/dist/ds/trie.js +2 -0
- package/dist/duration/index.d.ts +146 -0
- package/dist/duration/index.js +2 -0
- package/dist/encoding/index.d.ts +144 -0
- package/dist/encoding/index.js +2 -0
- package/dist/error/index.d.ts +316 -0
- package/dist/error/index.js +2 -0
- package/dist/fn/index.d.ts +129 -0
- package/dist/fn/index.js +2 -0
- package/dist/fn/memo.d.ts +46 -0
- package/dist/fn/memo.js +2 -0
- package/dist/fn/timing.d.ts +64 -0
- package/dist/fn/timing.js +2 -0
- package/dist/http/headers.d.ts +160 -0
- package/dist/http/headers.js +2 -0
- package/dist/http/index.d.ts +10 -0
- package/dist/http/index.js +2 -0
- package/dist/http/problem.d.ts +37 -0
- package/dist/http/problem.js +2 -0
- package/dist/http/response.d.ts +43 -0
- package/dist/http/response.js +2 -0
- package/dist/http/status.d.ts +169 -0
- package/dist/http/status.js +2 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +2 -0
- package/dist/internal/keys.d.ts +6 -0
- package/dist/internal/keys.js +2 -0
- package/dist/is/index.d.ts +219 -0
- package/dist/is/index.js +2 -0
- package/dist/json/index.d.ts +9 -0
- package/dist/json/index.js +2 -0
- package/dist/json/internal.d.ts +12 -0
- package/dist/json/internal.js +2 -0
- package/dist/json/ndjson.d.ts +28 -0
- package/dist/json/ndjson.js +4 -0
- package/dist/json/parse.d.ts +45 -0
- package/dist/json/parse.js +2 -0
- package/dist/json/patch.d.ts +62 -0
- package/dist/json/patch.js +2 -0
- package/dist/json/pointer.d.ts +43 -0
- package/dist/json/pointer.js +2 -0
- package/dist/json/stringify.d.ts +42 -0
- package/dist/json/stringify.js +2 -0
- package/dist/linq/enumerable.d.ts +208 -0
- package/dist/linq/enumerable.js +2 -0
- package/dist/linq/index.d.ts +6 -0
- package/dist/linq/index.js +2 -0
- package/dist/linq/operators.d.ts +503 -0
- package/dist/linq/operators.js +2 -0
- package/dist/number/core.d.ts +164 -0
- package/dist/number/core.js +2 -0
- package/dist/number/format.d.ts +80 -0
- package/dist/number/format.js +2 -0
- package/dist/number/index.d.ts +12 -0
- package/dist/number/index.js +2 -0
- package/dist/number/internal.d.ts +18 -0
- package/dist/number/internal.js +2 -0
- package/dist/number/parse.d.ts +45 -0
- package/dist/number/parse.js +2 -0
- package/dist/number/words.d.ts +19 -0
- package/dist/number/words.js +2 -0
- package/dist/object/basic.d.ts +130 -0
- package/dist/object/basic.js +2 -0
- package/dist/object/deep.d.ts +90 -0
- package/dist/object/deep.js +2 -0
- package/dist/object/diff.d.ts +57 -0
- package/dist/object/diff.js +2 -0
- package/dist/object/index.d.ts +8 -0
- package/dist/object/index.js +2 -0
- package/dist/object/internal.d.ts +21 -0
- package/dist/object/internal.js +2 -0
- package/dist/object/path.d.ts +17 -0
- package/dist/object/path.js +2 -0
- package/dist/random/core.d.ts +14 -0
- package/dist/random/core.js +2 -0
- package/dist/random/index.d.ts +167 -0
- package/dist/random/index.js +2 -0
- package/dist/random/seeded.d.ts +27 -0
- package/dist/random/seeded.js +2 -0
- package/dist/sanitize/index.d.ts +8 -0
- package/dist/sanitize/index.js +2 -0
- package/dist/sanitize/pii.d.ts +48 -0
- package/dist/sanitize/pii.js +2 -0
- package/dist/sanitize/records.d.ts +100 -0
- package/dist/sanitize/records.js +2 -0
- package/dist/sanitize/text.d.ts +101 -0
- package/dist/sanitize/text.js +2 -0
- package/dist/set/index.d.ts +162 -0
- package/dist/set/index.js +2 -0
- package/dist/stats/index.d.ts +190 -0
- package/dist/stats/index.js +2 -0
- package/dist/string/index.d.ts +494 -0
- package/dist/string/index.js +8 -0
- package/dist/string/internal.d.ts +33 -0
- package/dist/string/internal.js +2 -0
- package/dist/string/words.d.ts +14 -0
- package/dist/string/words.js +2 -0
- package/dist/timezone/index.d.ts +76 -0
- package/dist/timezone/index.js +2 -0
- package/dist/url/index.d.ts +178 -0
- package/dist/url/index.js +2 -0
- package/dist/validate/builders.d.ts +6 -0
- package/dist/validate/builders.js +2 -0
- package/dist/validate/formats.d.ts +237 -0
- package/dist/validate/formats.js +2 -0
- package/dist/validate/index.d.ts +13 -0
- package/dist/validate/index.js +2 -0
- package/dist/validate/schema.d.ts +220 -0
- package/dist/validate/schema.js +2 -0
- package/dist/zip/index.d.ts +8 -0
- package/dist/zip/index.js +2 -0
- package/dist/zip/internal.d.ts +69 -0
- package/dist/zip/internal.js +2 -0
- package/dist/zip/reader.d.ts +56 -0
- package/dist/zip/reader.js +2 -0
- package/dist/zip/writer.d.ts +65 -0
- package/dist/zip/writer.js +2 -0
- package/package.json +150 -4
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
export interface DeepOptions {
|
|
2
|
+
/** Recurse into nested plain objects and arrays. */
|
|
3
|
+
readonly deep?: boolean;
|
|
4
|
+
/** Maximum nesting depth; deeper input throws `HLP_SANITIZE_TOO_DEEP`. Default 100. */
|
|
5
|
+
readonly maxDepth?: number;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Trims every string; with `deep` (default true) also inside nested plain objects and arrays.
|
|
9
|
+
* @example trimStrings({ name: ' Ada ', tags: [' x '] }) // => { name: 'Ada', tags: ['x'] }
|
|
10
|
+
*/
|
|
11
|
+
export declare function trimStrings<T>(value: T, options?: DeepOptions): T;
|
|
12
|
+
/**
|
|
13
|
+
* Removes `null` and `undefined` properties and array items (top level unless `deep`).
|
|
14
|
+
* @example removeNullish({ a: 1, b: null, c: undefined }) // => { a: 1 }
|
|
15
|
+
*/
|
|
16
|
+
export declare function removeNullish<T>(value: T, options?: DeepOptions): T;
|
|
17
|
+
export interface RemoveEmptyOptions extends DeepOptions {
|
|
18
|
+
/** Treat whitespace-only strings as empty. Default true. */
|
|
19
|
+
readonly whitespace?: boolean;
|
|
20
|
+
/** Also remove `null` and `undefined`. Default true. */
|
|
21
|
+
readonly nullish?: boolean;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Removes empty strings, empty arrays and empty plain objects (and, by default, nullish values).
|
|
25
|
+
* With `deep`, containers that become empty after cleaning are removed too.
|
|
26
|
+
* @example removeEmpty({ a: '', b: [], c: {}, d: 0 }) // => { d: 0 }
|
|
27
|
+
*/
|
|
28
|
+
export declare function removeEmpty<T>(value: T, options?: RemoveEmptyOptions): T;
|
|
29
|
+
export interface NormalizeRecordRules {
|
|
30
|
+
/** Trim string values. Default true. */
|
|
31
|
+
readonly trim?: boolean;
|
|
32
|
+
/** Collapse internal whitespace runs to one space. Default false. */
|
|
33
|
+
readonly collapseWhitespace?: boolean;
|
|
34
|
+
/** Remove zero-width and bidi control characters. Default true. */
|
|
35
|
+
readonly stripInvisible?: boolean;
|
|
36
|
+
/** Turn empty strings (after trimming) into `null`. Default false. */
|
|
37
|
+
readonly emptyToNull?: boolean;
|
|
38
|
+
/** Lowercase property names. Default false. */
|
|
39
|
+
readonly lowercaseKeys?: boolean;
|
|
40
|
+
/** Also trim property names. Default true. */
|
|
41
|
+
readonly trimKeys?: boolean;
|
|
42
|
+
/** Fields to convert to numbers (invalid -> `null`). Matched after key normalization. */
|
|
43
|
+
readonly toNumber?: readonly string[];
|
|
44
|
+
/** Fields to convert to booleans (`true/false/yes/no/y/n/1/0/on/off`; invalid -> `null`). */
|
|
45
|
+
readonly toBoolean?: readonly string[];
|
|
46
|
+
/** Fields to lowercase (for example e-mail addresses). */
|
|
47
|
+
readonly lowercase?: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Normalizes one flat record: trims strings, strips invisible characters, optionally collapses
|
|
51
|
+
* whitespace, maps empty strings to `null`, normalizes keys, and converts listed fields.
|
|
52
|
+
* @example
|
|
53
|
+
* normalizeRecord({ ' Age ': ' 42 ', Name: ' Ada L ' }, { lowercaseKeys: true, collapseWhitespace: true, toNumber: ['age'] })
|
|
54
|
+
* // { age: 42, name: 'Ada L' }
|
|
55
|
+
*/
|
|
56
|
+
export declare function normalizeRecord(record: Readonly<Record<string, unknown>>, rules?: NormalizeRecordRules): Record<string, unknown>;
|
|
57
|
+
export interface DedupeOptions {
|
|
58
|
+
/** Which duplicate survives. Default `'first'`. Order follows the survivors' positions. */
|
|
59
|
+
readonly keep?: 'first' | 'last';
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Removes duplicates by a key (compared with `SameValueZero`), in O(n).
|
|
63
|
+
* @example dedupeBy([{ id: 1, v: 'a' }, { id: 1, v: 'b' }], (r) => r.id, { keep: 'last' }) // => [{ id: 1, v: 'b' }]
|
|
64
|
+
*/
|
|
65
|
+
export declare function dedupeBy<T>(records: readonly T[], keyFn: (record: T, index: number) => unknown, options?: DedupeOptions): T[];
|
|
66
|
+
export interface CleanRecordsOptions<T> {
|
|
67
|
+
/** Normalization rules applied to every record. Default: trim + strip invisible. */
|
|
68
|
+
readonly normalize?: NormalizeRecordRules | false;
|
|
69
|
+
/** Drop records whose values are all nullish or empty strings. Default true. */
|
|
70
|
+
readonly dropEmpty?: boolean;
|
|
71
|
+
/** De-duplicate by this key after normalization. */
|
|
72
|
+
readonly dedupeBy?: (record: Record<string, unknown>, index: number) => unknown;
|
|
73
|
+
/** Which duplicate survives. Default `'first'`. */
|
|
74
|
+
readonly keep?: 'first' | 'last';
|
|
75
|
+
/** Final filter. */
|
|
76
|
+
readonly filter?: (record: Record<string, unknown>) => boolean;
|
|
77
|
+
/** Final mapping. */
|
|
78
|
+
readonly map?: (record: Record<string, unknown>) => T;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Cleaning pipeline for imported rows: normalize -> drop empty rows -> dedupe -> filter -> map.
|
|
82
|
+
* @example
|
|
83
|
+
* const rows = [{ name: ' Ada ', email: 'ada@example.com' }, { name: '', email: '' }, { name: 'Ada L.', email: 'ada@example.com' }];
|
|
84
|
+
* cleanRecords(rows, { normalize: { emptyToNull: true }, dedupeBy: (r) => r.email, keep: 'last' }); // => [{ name: 'Ada L.', email: 'ada@example.com' }]
|
|
85
|
+
*/
|
|
86
|
+
export declare function cleanRecords<T = Record<string, unknown>>(records: readonly Readonly<Record<string, unknown>>[], options?: CleanRecordsOptions<T>): T[];
|
|
87
|
+
/** Target types for {@link coerceRecordTypes}. */
|
|
88
|
+
export type CoerceType = 'string' | 'number' | 'integer' | 'boolean' | 'date' | 'json';
|
|
89
|
+
export interface CoerceOptions {
|
|
90
|
+
/** What to do with values that cannot be converted. Default `'null'`. */
|
|
91
|
+
readonly onInvalid?: 'null' | 'keep' | 'omit';
|
|
92
|
+
/** Drop properties not listed in the type map. Default false. */
|
|
93
|
+
readonly strip?: boolean;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Converts record fields from strings to the listed types (CSV/form import). `date` yields a
|
|
97
|
+
* `Date` from an ISO 8601 string; `json` parses JSON text (max 100 000 characters).
|
|
98
|
+
* @example coerceRecordTypes({ n: '4', ok: 'yes' }, { n: 'integer', ok: 'boolean' }) // => { n: 4, ok: true }
|
|
99
|
+
*/
|
|
100
|
+
export declare function coerceRecordTypes(record: Readonly<Record<string, unknown>>, types: Readonly<Record<string, CoerceType>>, options?: CoerceOptions): Record<string, unknown>;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as x}from"../error/index.js";import{isUnsafeKey as b}from"../internal/keys.js";import{isPlainObject as w}from"../is/index.js";import{collapseWhitespace as D,stripInvisible as h}from"./text.js";const S=e=>Array.isArray(e)||w(e);function g(e,n,r,u){const s=new WeakMap,t=(o,l)=>{s.set(o,l)},i=(o,l)=>{if(l>r)throw new x("HLP_SANITIZE_TOO_DEEP","Input nesting exceeds the limit.",{details:{maxDepth:r}});return u(o,y=>{if(S(y)){if(!n)return y;const m=s.get(y);if(m!==void 0)return m}return i(y,l+1)},t)};return i(e,0)}function R(e,n,r,u){if(Array.isArray(e)){const s=[];r(e,s);for(const t of e){const i=n(t);u(i)&&s.push(i)}return s}if(w(e)){const s={};r(e,s);for(const t of Object.keys(e)){if(b(t))continue;const i=n(e[t]);u(i)&&(s[t]=i)}return s}return e}function W(e,n={}){const{deep:r=!0,maxDepth:u=100}=n;return g(e,r,u,(s,t,i)=>typeof s=="string"?s.trim():R(s,t,i,()=>!0))}function M(e,n={}){const{deep:r=!1,maxDepth:u=100}=n;return g(e,r,u,(s,t,i)=>R(s,t,i,o=>o!=null))}function P(e,n={}){const{deep:r=!1,maxDepth:u=100,whitespace:s=!0,nullish:t=!0}=n,i=o=>o==null?!t:typeof o=="string"?(s?o.trim():o)!=="":Array.isArray(o)?o.length>0:w(o)?Object.keys(o).length>0:!0;return g(e,r,u,(o,l,p)=>R(o,l,p,i))}const E=new Set(["true","yes","y","1","on"]),I=new Set(["false","no","n","0","off"]);function O(e){if(typeof e=="boolean")return e;if(typeof e=="number")return e===1?!0:e===0?!1:null;if(typeof e!="string")return null;const n=e.trim().toLowerCase();return E.has(n)?!0:I.has(n)?!1:null}const j=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i;function T(e){if(typeof e=="number")return Number.isFinite(e)?e:null;if(typeof e!="string")return null;const n=e.trim();if(n.length===0||n.length>400||!j.test(n))return null;const r=Number(n);return Number.isFinite(r)?r:null}function N(e,n={}){const{trim:r=!0,collapseWhitespace:u=!1,stripInvisible:s=!0,emptyToNull:t=!1,lowercaseKeys:i=!1,trimKeys:o=!0}=n,l=new Set(n.toNumber),p=new Set(n.toBoolean),y=new Set(n.lowercase),m={};for(const k of Object.keys(e)){let f=s?h(k):k;if(o&&(f=f.trim()),i&&(f=f.toLowerCase()),b(f)||b(k))continue;let a=e[k];if(typeof a=="string"){let d=s?h(a):a;u?d=D(d):r&&(d=d.trim()),y.has(f)&&(d=d.toLowerCase()),a=t&&d===""?null:d}l.has(f)&&a!==null&&a!==void 0?a=T(a):p.has(f)&&a!==null&&a!==void 0&&(a=O(a)),m[f]=a}return m}function C(e,n,r={}){const u=r.keep==="last",s=new Map;e.forEach((i,o)=>{const l=n(i,o);(u||!s.has(l))&&s.set(l,o)});const t=new Set(s.values());return e.filter((i,o)=>t.has(o))}function F(e,n={}){const{normalize:r={},dropEmpty:u=!0,keep:s="first"}=n;let t=e.map(o=>r===!1?N(o,{trim:!1,stripInvisible:!1,trimKeys:!1}):N(o,r));u&&(t=t.filter(o=>Object.values(o).some(l=>l!=null&&l!==""))),n.dedupeBy&&(t=C(t,n.dedupeBy,{keep:s})),n.filter&&(t=t.filter(n.filter));const i=n.map;return i?t.map(i):t}function V(e,n,r={}){const{onInvalid:u="null",strip:s=!1}=r,t={};for(const i of Object.keys(e)){if(b(i))continue;const o=e[i],l=Object.prototype.hasOwnProperty.call(n,i)?n[i]:void 0;if(l===void 0){s||(t[i]=o);continue}if(o==null||o===""){t[i]=null;continue}const p=L(o,l);p!==c?t[i]=p:u==="null"?t[i]=null:u==="keep"&&(t[i]=o)}return t}const c=Symbol("invalid"),A=/^\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d{1,9})?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;function L(e,n){switch(n){case"string":return typeof e=="string"?e:typeof e=="number"||typeof e=="boolean"||typeof e=="bigint"?String(e):c;case"number":return T(e)??c;case"integer":{const r=T(e);return r!==null&&Number.isSafeInteger(r)?r:c}case"boolean":return O(e)??c;case"date":{if(e instanceof Date)return Number.isNaN(e.getTime())?c:new Date(e.getTime());if(typeof e!="string"||e.length>40||!A.test(e.trim()))return c;const r=new Date(e.trim());return Number.isNaN(r.getTime())?c:r}case"json":{if(typeof e!="string"||e.length>1e5)return c;try{return JSON.parse(e,(r,u)=>b(r)?void 0:u)}catch{return c}}}}export{F as cleanRecords,V as coerceRecordTypes,C as dedupeBy,N as normalizeRecord,P as removeEmpty,M as removeNullish,W as trimStrings};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export interface StripInvisibleOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Keep ZWNJ/ZWJ (U+200C/U+200D), which are required in emoji sequences and some scripts
|
|
4
|
+
* (Persian, Indic). Default false: stripped.
|
|
5
|
+
*/
|
|
6
|
+
readonly keepJoiners?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Removes zero-width characters and bidi control characters (U+202A-202E, U+2066-2069),
|
|
10
|
+
* which can hide or reorder text (Trojan Source). Variation selectors are kept (emoji).
|
|
11
|
+
* @example stripInvisible('ad' + String.fromCharCode(0x200b) + 'min') // => 'admin'
|
|
12
|
+
*/
|
|
13
|
+
export declare function stripInvisible(text: string, options?: StripInvisibleOptions): string;
|
|
14
|
+
/**
|
|
15
|
+
* Removes C0/C1 control characters. Tab, LF and CR are kept unless `keepWhitespace` is false.
|
|
16
|
+
* @example stripControl('a\u0000b') // => 'ab'
|
|
17
|
+
*/
|
|
18
|
+
export declare function stripControl(text: string, options?: {
|
|
19
|
+
readonly keepWhitespace?: boolean;
|
|
20
|
+
}): string;
|
|
21
|
+
/**
|
|
22
|
+
* Unicode normalization (`NFC` default). Use `NFKC` to fold compatibility forms
|
|
23
|
+
* (full-width letters, ligatures) before comparisons or search.
|
|
24
|
+
* @example normalizeUnicode('full', 'NFKC') // => 'full'
|
|
25
|
+
*/
|
|
26
|
+
export declare function normalizeUnicode(text: string, form?: 'NFC' | 'NFD' | 'NFKC' | 'NFKD'): string;
|
|
27
|
+
/**
|
|
28
|
+
* Trims and collapses runs of whitespace (any Unicode `\s`) to a single space.
|
|
29
|
+
* @example collapseWhitespace(' a \n b ') // => 'a b'
|
|
30
|
+
*/
|
|
31
|
+
export declare function collapseWhitespace(text: string): string;
|
|
32
|
+
export interface SafeFileNameOptions {
|
|
33
|
+
/** Maximum length in UTF-8 bytes (the common file-system limit). Default 255. */
|
|
34
|
+
readonly maxLength?: number;
|
|
35
|
+
/** Replacement for forbidden characters. Must itself be safe. Default `'_'`. */
|
|
36
|
+
readonly replacement?: string;
|
|
37
|
+
/** Keep a leading dot (hidden files). Default false: leading dots are removed. */
|
|
38
|
+
readonly allowLeadingDot?: boolean;
|
|
39
|
+
/** Used when nothing usable remains. Default `'file'`. */
|
|
40
|
+
readonly fallback?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Makes a string safe to use as a single file name on Windows, macOS and Linux: strips path
|
|
44
|
+
* separators, control and invisible characters, reserved device names (`CON`, `NUL`, `COM1`...),
|
|
45
|
+
* trailing dots/spaces, and leading dots; truncates to `maxLength` UTF-8 bytes keeping the
|
|
46
|
+
* extension.
|
|
47
|
+
* @example safeFileName('../../etc/passwd') // => 'etc_passwd'
|
|
48
|
+
* @example safeFileName('CON.txt') // => '_CON.txt'
|
|
49
|
+
*/
|
|
50
|
+
export declare function safeFileName(name: string, options?: SafeFileNameOptions): string;
|
|
51
|
+
export interface NormalizeEmailOptions {
|
|
52
|
+
/** Lowercase the local part too. Default false (RFC 5321: local parts are case-sensitive). */
|
|
53
|
+
readonly lowercaseLocal?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Gmail canonicalization for `gmail.com`/`googlemail.com`: remove dots and `+tag`, map to
|
|
56
|
+
* `gmail.com`. Default false: only use for duplicate detection, never for sending.
|
|
57
|
+
*/
|
|
58
|
+
readonly gmail?: boolean;
|
|
59
|
+
/** Remove a `+tag` suffix for every domain. Default false. */
|
|
60
|
+
readonly stripPlusTag?: boolean;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Trims and lowercases the domain of an e-mail address. Returns `undefined` when the input
|
|
64
|
+
* has no single `@` separating non-empty parts or exceeds 254 characters.
|
|
65
|
+
* @example normalizeEmail(' John.Doe@Example.COM ') // => 'John.Doe@example.com'
|
|
66
|
+
*/
|
|
67
|
+
export declare function normalizeEmail(email: string, options?: NormalizeEmailOptions): string | undefined;
|
|
68
|
+
export interface NormalizePhoneOptions {
|
|
69
|
+
/**
|
|
70
|
+
* Country calling code used when the number has no international prefix, e.g. `'1'`, `'+44'`,
|
|
71
|
+
* `'91'`. Without it, only numbers starting with `+` or `00` normalize.
|
|
72
|
+
*/
|
|
73
|
+
readonly defaultCountryCode?: string;
|
|
74
|
+
/** Remove a single national trunk prefix `0` before adding the country code. Default true. */
|
|
75
|
+
readonly stripTrunkZero?: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Normalizes a phone number to E.164 (`+<digits>`, 8-15 digits) by digits only; no carrier or
|
|
79
|
+
* numbering-plan logic. Returns `undefined` when the result cannot be E.164.
|
|
80
|
+
* @example normalizePhone('(020) 7946 0958', { defaultCountryCode: '44' }) // => '+442079460958'
|
|
81
|
+
*/
|
|
82
|
+
export declare function normalizePhone(input: string, options?: NormalizePhoneOptions): string | undefined;
|
|
83
|
+
export interface SanitizeSearchQueryOptions {
|
|
84
|
+
/** Maximum length in code points. Default 200. */
|
|
85
|
+
readonly maxLength?: number;
|
|
86
|
+
/** Apply NFKC folding (full-width -> ASCII). Default true. */
|
|
87
|
+
readonly fold?: boolean;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Cleans free-text search input: strips control and invisible characters, folds compatibility
|
|
91
|
+
* forms, collapses whitespace, and limits length. Not an injection defense: always use
|
|
92
|
+
* parameterized queries.
|
|
93
|
+
* @example sanitizeSearchQuery(' hello world ') // => 'hello world'
|
|
94
|
+
*/
|
|
95
|
+
export declare function sanitizeSearchQuery(query: string, options?: SanitizeSearchQueryOptions): string;
|
|
96
|
+
/**
|
|
97
|
+
* Serializes any value for logging and truncates it to `maxLength` code units (default 1000),
|
|
98
|
+
* appending `...[+N]` with the number of characters removed. Handles cycles and BigInt.
|
|
99
|
+
* @example truncateForLog('x'.repeat(2000), 10) // => 'xx…[+1998]'
|
|
100
|
+
*/
|
|
101
|
+
export declare function truncateForLog(value: unknown, maxLength?: number): string;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as m}from"../error/index.js";function O(e,r){return e<173?!1:e===8204||e===8205?!r:e===173||e===1564||e===4447||e===4448||e===6068||e===6069||e===12644||e===65440||e>=6155&&e<=6159||e>=8203&&e<=8207||e>=8234&&e<=8238||e>=8288&&e<=8303||e===65279||e>=65529&&e<=65531}const h=e=>e<=31||e>=127&&e<=159;function u(e,r){let i="",t=0;for(let n=0;n<e.length;n++)r(e.charCodeAt(n))&&(i+=e.slice(t,n),t=n+1);return t===0?e:i+e.slice(t)}function f(e,r={}){const i=r.keepJoiners===!0;return u(e,t=>O(t,i))}function N(e,r={}){const i=r.keepWhitespace!==!1;return u(e,t=>h(t)&&!(i&&(t===9||t===10||t===13)))}function A(e,r="NFC"){return e.normalize(r)}function w(e){return e.trim().replace(/\s+/g," ")}const F='"*/:<>?\\|',x=e=>h(e)||F.includes(String.fromCharCode(e)),k=e=>u(e,x)!==e;function E(e,r){let i="";for(let t=0;t<e.length;t++)i+=x(e.charCodeAt(t))?r:e.charAt(t);return i}const $=/^(?:con|prn|aux|nul|com[\d\u00b9\u00b2\u00b3]|lpt[\d\u00b9\u00b2\u00b3]|conin\$|conout\$)$/i,I=new TextEncoder,b=e=>e==="."||e.trim()==="";function c(e){let r=e.length;for(;r>0&&b(e.charAt(r-1));)r--;return e.slice(0,r)}function L(e){let r=0;for(;r<e.length&&b(e.charAt(r));)r++;return e.slice(r)}const y=e=>I.encode(e).length;function d(e,r){let i=0,t="";for(const n of e){const s=n.codePointAt(0)??0,a=s<128?1:s<2048?2:s<65536?3:4;if(i+a>r)break;i+=a,t+=n}return t}function P(e,r={}){const{maxLength:i=255,replacement:t="_",allowLeadingDot:n=!1,fallback:s="file"}=r;if(k(t)||/[.\s]/.test(t)||f(t)!==t)throw new m("HLP_SANITIZE_REPLACEMENT","The replacement must not contain forbidden file name characters.");if(!Number.isInteger(i)||i<1)throw new m("HLP_SANITIZE_OPTION","maxLength must be a positive integer.");const a=f(e.normalize("NFC")).split(/[/\\]/).filter(l=>l!==""&&l!=="."&&l!=="..");let o=E(a.join(t),t);if(t!==""){const l=t+t;for(;o.includes(l);)o=o.replaceAll(l,t)}o=c(o.trim()),n||(o=L(o)),(o===""||o==="."||o==="..")&&(o=s);const g=o.indexOf(".");$.test((g>0?o.slice(0,g):o).trim())&&(o=`${t===""?"_":t}${o}`);const C=o.lastIndexOf(".");if(y(o)>i){const l=C>0?o.slice(o.lastIndexOf(".")):"",p=y(l);l!==""&&p<i/2?o=c(d(o.slice(0,o.length-l.length),i-p))+l:o=c(d(o,i)),o===""&&(o=d(s,i))}return o}const S=e=>{const r=e.indexOf("+");return r<0?e:e.slice(0,r)};function D(e,r={}){const i=f(e).trim();if(i.length>254)return;const t=i.lastIndexOf("@");if(t<=0||t===i.length-1)return;let n=i.slice(0,t),s=i.slice(t+1).toLowerCase();if(s.endsWith(".")&&(s=s.slice(0,-1)),!(n.includes("@")&&!(n.startsWith('"')&&n.endsWith('"')))&&(r.lowercaseLocal===!0&&(n=n.toLowerCase()),r.stripPlusTag===!0&&(n=S(n)),r.gmail===!0&&(s==="gmail.com"||s==="googlemail.com")&&(n=S(n.toLowerCase()).replaceAll(".",""),s="gmail.com"),n!==""))return`${n}@${s}`}function T(e,r={}){const i=e.trim();if(i.length===0||i.length>64)return;const t=i.replace(/(?:ext\.?|x|#) ?\d{1,6}$/i,"").trimEnd();if(/[^\d\s().+\-/]/.test(t))return;let n=t.replace(/\D/g,"");const s=t.startsWith("+");if(!(s&&t.lastIndexOf("+")!==0)&&!(!s&&t.includes("+"))){if(!s)if(n.startsWith("00"))n=n.slice(2);else{const a=r.defaultCountryCode?.replace(/^\+/,"");if(a===void 0||!/^[1-9]\d{0,2}$/.test(a))return;r.stripTrunkZero!==!1&&n.startsWith("0")&&(n=n.slice(1)),n=a+n}if(/^[1-9]\d{7,14}$/.test(n))return`+${n}`}}function _(e,r={}){const{maxLength:i=200,fold:t=!0}=r;let n=e.slice(0,i*4+16);n=f(N(n,{keepWhitespace:!1})),t&&(n=n.normalize("NFKC")),n=w(n);const s=Array.from(n);return s.length>i?s.slice(0,i).join("").trimEnd():n}function W(e){if(typeof e=="string")return e;if(e===void 0)return"undefined";if(typeof e=="bigint")return`${e.toString()}n`;if(typeof e=="symbol"||typeof e=="function")return e.toString();if(e instanceof Error)return`${e.name}: ${e.message}`;const r=new WeakSet;try{return JSON.stringify(e,(t,n)=>{if(typeof n=="bigint")return`${n.toString()}n`;if(typeof n=="object"&&n!==null){if(r.has(n))return"[Circular]";r.add(n)}return n})??Object.prototype.toString.call(e)}catch{return Object.prototype.toString.call(e)}}function j(e,r=1e3){const i=W(e);if(i.length<=r)return i;let t=`\u2026[+${i.length-r}]`,n=Math.max(0,r-t.length);t=`\u2026[+${i.length-n}]`,n=Math.max(0,r-t.length);const s=i.charCodeAt(n-1);return n>0&&s>=55296&&s<=56319&&(n-=1),i.slice(0,n)+t}export{w as collapseWhitespace,D as normalizeEmail,T as normalizePhone,A as normalizeUnicode,P as safeFileName,_ as sanitizeSearchQuery,N as stripControl,f as stripInvisible,j as truncateForLog};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
type Collection<T> = Iterable<T>;
|
|
2
|
+
type Key<T> = (item: T) => unknown;
|
|
3
|
+
/**
|
|
4
|
+
* Items in either collection, `a` first.
|
|
5
|
+
* @example
|
|
6
|
+
* union([1, 2], [2, 3]); // => [1, 2, 3]
|
|
7
|
+
* union(new Set([1]), [2]); // => new Set([1, 2])
|
|
8
|
+
*/
|
|
9
|
+
export declare function union<T>(a: ReadonlySet<T>, b: Collection<T>): Set<T>;
|
|
10
|
+
export declare function union<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
11
|
+
/**
|
|
12
|
+
* Union by key; the first item per key wins.
|
|
13
|
+
* @example
|
|
14
|
+
* unionBy([{ id: 1, v: 'a' }], [{ id: 1, v: 'b' }, { id: 2 }], (x) => x.id); // => [{ id: 1, v: 'a' }, { id: 2 }]
|
|
15
|
+
*/
|
|
16
|
+
export declare function unionBy<T>(a: ReadonlySet<T>, b: Collection<T>, key: Key<T>): Set<T>;
|
|
17
|
+
export declare function unionBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): T[];
|
|
18
|
+
/**
|
|
19
|
+
* Items of `a` also in `b`, in `a`'s order.
|
|
20
|
+
* @example
|
|
21
|
+
* intersect([3, 1, 2], [2, 3]); // => [3, 2]
|
|
22
|
+
*/
|
|
23
|
+
export declare function intersect<T>(a: ReadonlySet<T>, b: Collection<T>): Set<T>;
|
|
24
|
+
export declare function intersect<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
25
|
+
/**
|
|
26
|
+
* Items of `a` whose key occurs in `b`, deduplicated by key.
|
|
27
|
+
* @example
|
|
28
|
+
* intersectBy([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // => [{ id: 2 }]
|
|
29
|
+
*/
|
|
30
|
+
export declare function intersectBy<T>(a: ReadonlySet<T>, b: Collection<T>, key: Key<T>): Set<T>;
|
|
31
|
+
export declare function intersectBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): T[];
|
|
32
|
+
/**
|
|
33
|
+
* Items of `a` not in `b` (set difference).
|
|
34
|
+
* @example
|
|
35
|
+
* except([1, 2, 3], [2]); // => [1, 3]
|
|
36
|
+
*/
|
|
37
|
+
export declare function except<T>(a: ReadonlySet<T>, b: Collection<T>): Set<T>;
|
|
38
|
+
export declare function except<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
39
|
+
/**
|
|
40
|
+
* Items of `a` whose key does not occur in `b`, deduplicated by key.
|
|
41
|
+
* @example
|
|
42
|
+
* exceptBy([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // => [{ id: 1 }]
|
|
43
|
+
*/
|
|
44
|
+
export declare function exceptBy<T>(a: ReadonlySet<T>, b: Collection<T>, key: Key<T>): Set<T>;
|
|
45
|
+
export declare function exceptBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): T[];
|
|
46
|
+
/**
|
|
47
|
+
* Items in exactly one collection: `a`'s first, then `b`'s.
|
|
48
|
+
* @example
|
|
49
|
+
* symmetricDifference([1, 2], [2, 3]); // => [1, 3]
|
|
50
|
+
*/
|
|
51
|
+
export declare function symmetricDifference<T>(a: ReadonlySet<T>, b: Collection<T>): Set<T>;
|
|
52
|
+
export declare function symmetricDifference<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
53
|
+
/**
|
|
54
|
+
* Symmetric difference by key.
|
|
55
|
+
* @example
|
|
56
|
+
* symmetricDifferenceBy([{ id: 1 }, { id: 2 }], [{ id: 2 }, { id: 3 }], (x) => x.id); // => [{ id: 1 }, { id: 3 }]
|
|
57
|
+
*/
|
|
58
|
+
export declare function symmetricDifferenceBy<T>(a: ReadonlySet<T>, b: Collection<T>, key: Key<T>): Set<T>;
|
|
59
|
+
export declare function symmetricDifferenceBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): T[];
|
|
60
|
+
/**
|
|
61
|
+
* True when every item of `a` is in `b`.
|
|
62
|
+
* @example
|
|
63
|
+
* isSubset([1, 2], [1, 2, 3]); // => true
|
|
64
|
+
*/
|
|
65
|
+
export declare function isSubset<T>(a: Collection<T>, b: Collection<T>): boolean;
|
|
66
|
+
/**
|
|
67
|
+
* True when every key of `a` occurs in `b`.
|
|
68
|
+
* @example
|
|
69
|
+
* isSubsetBy([{ id: 1 }], [{ id: 1 }, { id: 2 }], (x) => x.id); // => true
|
|
70
|
+
*/
|
|
71
|
+
export declare function isSubsetBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* True when every item of `b` is in `a`.
|
|
74
|
+
* @example
|
|
75
|
+
* isSuperset([1, 2, 3], [2]); // => true
|
|
76
|
+
*/
|
|
77
|
+
export declare function isSuperset<T>(a: Collection<T>, b: Collection<T>): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* True when every key of `b` occurs in `a`.
|
|
80
|
+
* @example
|
|
81
|
+
* isSupersetBy([{ id: 1 }, { id: 2 }], [{ id: 2 }], (x) => x.id); // => true
|
|
82
|
+
*/
|
|
83
|
+
export declare function isSupersetBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): boolean;
|
|
84
|
+
/**
|
|
85
|
+
* True when the collections share no item.
|
|
86
|
+
* @example
|
|
87
|
+
* isDisjoint([1, 2], [3]); // => true
|
|
88
|
+
*/
|
|
89
|
+
export declare function isDisjoint<T>(a: Collection<T>, b: Collection<T>): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* True when the collections share no key.
|
|
92
|
+
* @example
|
|
93
|
+
* isDisjointBy([{ id: 1 }], [{ id: 2 }], (x) => x.id); // => true
|
|
94
|
+
*/
|
|
95
|
+
export declare function isDisjointBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* True when both contain the same distinct items (order and duplicates ignored).
|
|
98
|
+
* @example
|
|
99
|
+
* setEquals([1, 2, 2], new Set([2, 1])); // => true
|
|
100
|
+
*/
|
|
101
|
+
export declare function setEquals<T>(a: Collection<T>, b: Collection<T>): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* True when both contain the same distinct keys.
|
|
104
|
+
* @example
|
|
105
|
+
* setEqualsBy([{ id: 1 }], [{ id: 1 }, { id: 1 }], (x) => x.id); // => true
|
|
106
|
+
*/
|
|
107
|
+
export declare function setEqualsBy<T>(a: Collection<T>, b: Collection<T>, key: Key<T>): boolean;
|
|
108
|
+
/** Default maximum number of tuples from `cartesianProduct`. */
|
|
109
|
+
export declare const MAX_CARTESIAN_SIZE = 1000000;
|
|
110
|
+
/** Default maximum distinct input size for `powerSet` (2^20 subsets). */
|
|
111
|
+
export declare const MAX_POWER_SET_ITEMS = 20;
|
|
112
|
+
export interface CartesianProductOptions {
|
|
113
|
+
/** Maximum number of result tuples. Default `MAX_CARTESIAN_SIZE`. */
|
|
114
|
+
readonly maxSize?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* All tuples picking one item from each list, first list varying slowest.
|
|
118
|
+
* Throws `HLP_SET_PRODUCT_TOO_LARGE` above `maxSize`.
|
|
119
|
+
* @example
|
|
120
|
+
* cartesianProduct([[1, 2], ['a', 'b']]); // => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
|
|
121
|
+
*/
|
|
122
|
+
export declare function cartesianProduct<const T extends readonly unknown[]>(lists: {
|
|
123
|
+
readonly [K in keyof T]: Iterable<T[K]>;
|
|
124
|
+
}, options?: CartesianProductOptions): {
|
|
125
|
+
-readonly [K in keyof T]: T[K];
|
|
126
|
+
}[];
|
|
127
|
+
export interface PowerSetOptions {
|
|
128
|
+
/** Maximum distinct input items. Default `MAX_POWER_SET_ITEMS`. */
|
|
129
|
+
readonly maxItems?: number;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Every subset of the distinct items, ordered by binary counting (`[]` first).
|
|
133
|
+
* Throws `HLP_SET_POWERSET_TOO_LARGE` when the input has more than `maxItems` distinct items.
|
|
134
|
+
* @example
|
|
135
|
+
* powerSet(['a', 'b']); // => [[], ['a'], ['b'], ['a', 'b']]
|
|
136
|
+
*/
|
|
137
|
+
export declare function powerSet<T>(items: Collection<T>, options?: PowerSetOptions): T[][];
|
|
138
|
+
/**
|
|
139
|
+
* Occurrence count per item (SameValueZero), in first-occurrence order.
|
|
140
|
+
* @example
|
|
141
|
+
* countOccurrences(['a', 'b', 'a']); // => new Map([['a', 2], ['b', 1]])
|
|
142
|
+
*/
|
|
143
|
+
export declare function countOccurrences<T>(items: Collection<T>): Map<T, number>;
|
|
144
|
+
/**
|
|
145
|
+
* Multiset union: each item appears max(count in a, count in b) times, grouped in first-occurrence order.
|
|
146
|
+
* @example
|
|
147
|
+
* multisetUnion([1, 1, 2], [1, 2, 2]); // => [1, 1, 2, 2]
|
|
148
|
+
*/
|
|
149
|
+
export declare function multisetUnion<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
150
|
+
/**
|
|
151
|
+
* Multiset intersection: each item appears min(count in a, count in b) times.
|
|
152
|
+
* @example
|
|
153
|
+
* multisetIntersect([1, 1, 2], [1, 3]); // => [1]
|
|
154
|
+
*/
|
|
155
|
+
export declare function multisetIntersect<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
156
|
+
/**
|
|
157
|
+
* Multiset difference: each item appears max(0, count in a - count in b) times.
|
|
158
|
+
* @example
|
|
159
|
+
* multisetExcept([1, 1, 2], [1]); // => [1, 2]
|
|
160
|
+
*/
|
|
161
|
+
export declare function multisetExcept<T>(a: Collection<T>, b: Collection<T>): T[];
|
|
162
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as m}from"../error/index.js";const a=e=>e,s=e=>e instanceof Set,f=e=>s(e)?e:new Set(e);function u(e,n){return s(e)?new Set(n):[...n]}function S(e,n){const o=new Map;for(const t of e){const i=n(t);o.has(i)||o.set(i,t)}return o}function p(e,n){const o=new Set;for(const t of e)o.add(n(t));return o}function K(e,n){if(s(e)&&s(n)){const t=a(e).union;if(t)return t.call(e,n)}const o=new Set(e);for(const t of n)o.add(t);return u(e,o)}function R(e,n,o){const t=S(e,o);for(const i of n){const c=o(i);t.has(c)||t.set(c,i)}return u(e,t.values())}function B(e,n){if(s(e)&&s(n)&&e.size<=n.size){const t=a(e).intersection;if(t)return t.call(e,n)}const o=f(n);return u(e,[...new Set(e)].filter(t=>o.has(t)))}function M(e,n,o){const t=p(n,o);return u(e,[...S(e,o)].filter(([i])=>t.has(i)).map(([,i])=>i))}function _(e,n){if(s(e)&&s(n)){const t=a(e).difference;if(t)return t.call(e,n)}const o=f(n);return u(e,[...new Set(e)].filter(t=>!o.has(t)))}function E(e,n,o){const t=p(n,o);return u(e,[...S(e,o)].filter(([i])=>!t.has(i)).map(([,i])=>i))}function O(e,n){if(s(e)&&s(n)){const i=a(e).symmetricDifference;if(i)return i.call(e,n)}const o=f(e),t=f(n);return u(e,[...[...o].filter(i=>!t.has(i)),...[...t].filter(i=>!o.has(i))])}function z(e,n,o){const t=S(e,o),i=S(n,o),c=[];for(const[r,l]of t)i.has(r)||c.push(l);for(const[r,l]of i)t.has(r)||c.push(l);return u(e,c)}function b(e,n){const o=f(e),t=f(n),i=a(o).isSubsetOf;if(i)return i.call(o,t);if(o.size>t.size)return!1;for(const c of o)if(!t.has(c))return!1;return!0}function d(e,n,o){const t=p(n,o);for(const i of e)if(!t.has(o(i)))return!1;return!0}function D(e,n){return b(n,e)}function I(e,n,o){return d(n,e,o)}function g(e,n){const o=f(e),t=f(n),i=a(o).isDisjointFrom;if(i)return i.call(o,t);const[c,r]=o.size<=t.size?[o,t]:[t,o];for(const l of c)if(r.has(l))return!1;return!0}function P(e,n,o){const t=p(n,o);for(const i of e)if(t.has(o(i)))return!1;return!0}function v(e,n){const o=f(e),t=f(n);return o.size===t.size&&b(o,t)}function A(e,n,o){const t=p(e,o),i=p(n,o);if(t.size!==i.size)return!1;for(const c of t)if(!i.has(c))return!1;return!0}const h=1e6,w=20;function L(e,n={}){const o=n.maxSize??h,t=e.map(l=>[...l]);if(t.length===0)return[];const i=t.reduce((l,T)=>l*T.length,1);if(i>o)throw new m("HLP_SET_PRODUCT_TOO_LARGE","The cartesian product exceeds the size limit.",{details:{limit:o}});const c=[],r=t.map(()=>0);for(let l=0;l<i;l++){c.push(t.map((T,x)=>T[r[x]??0]));for(let T=t.length-1;T>=0;T--){const x=(r[T]??0)+1;if(x<(t[T]?.length??0)){r[T]=x;break}r[T]=0}}return c}function j(e,n={}){const o=Math.min(n.maxItems??w,30),t=[...new Set(e)];if(t.length>o)throw new m("HLP_SET_POWERSET_TOO_LARGE","The power set input exceeds the item limit.",{details:{limit:o}});const i=2**t.length,c=[];for(let r=0;r<i;r++)c.push(t.filter((l,T)=>(r&1<<T)!==0));return c}function y(e){const n=new Map;for(const o of e)n.set(o,(n.get(o)??0)+1);return n}function C(e){const n=[];for(const[o,t]of e)for(let i=0;i<t;i++)n.push(o);return n}function N(e,n){const o=y(e);for(const[t,i]of y(n))o.set(t,Math.max(o.get(t)??0,i));return C(o)}function q(e,n){const o=y(n),t=new Map;for(const[i,c]of y(e)){const r=Math.min(c,o.get(i)??0);r>0&&t.set(i,r)}return C(t)}function F(e,n){const o=y(n),t=new Map;for(const[i,c]of y(e)){const r=c-(o.get(i)??0);r>0&&t.set(i,r)}return C(t)}export{h as MAX_CARTESIAN_SIZE,w as MAX_POWER_SET_ITEMS,L as cartesianProduct,y as countOccurrences,_ as except,E as exceptBy,B as intersect,M as intersectBy,g as isDisjoint,P as isDisjointBy,b as isSubset,d as isSubsetBy,D as isSuperset,I as isSupersetBy,F as multisetExcept,q as multisetIntersect,N as multisetUnion,j as powerSet,v as setEquals,A as setEqualsBy,O as symmetricDifference,z as symmetricDifferenceBy,K as union,R as unionBy};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
export interface StatsOptions {
|
|
2
|
+
/** `throw` (default) rejects `NaN`/`+/-Infinity`; `ignore` drops them (pairs are dropped together). */
|
|
3
|
+
readonly nonFinite?: 'throw' | 'ignore';
|
|
4
|
+
}
|
|
5
|
+
export interface VarianceOptions extends StatsOptions {
|
|
6
|
+
/** Population statistic (divide by n) instead of the sample statistic (n - 1, Excel `VAR.S`). Default false. */
|
|
7
|
+
readonly population?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Arithmetic mean.
|
|
11
|
+
* @example mean([1, 2, 3, 4]) // => 2.5
|
|
12
|
+
*/
|
|
13
|
+
export declare function mean(values: readonly number[], options?: StatsOptions): number | undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Weighted mean; weights must be finite and non-negative. `undefined` when all weights are 0.
|
|
16
|
+
* @example weightedMean([80, 90], [1, 3]) // => 87.5
|
|
17
|
+
*/
|
|
18
|
+
export declare function weightedMean(values: readonly number[], weights: readonly number[], options?: StatsOptions): number | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Median (mean of the two middle values for even counts).
|
|
21
|
+
* @example median([3, 1, 4, 2]) // => 2.5
|
|
22
|
+
*/
|
|
23
|
+
export declare function median(values: readonly number[], options?: StatsOptions): number | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* All most-frequent values, ascending (several for multi-modal data).
|
|
26
|
+
* @example mode([1, 2, 2, 3, 3]) // => [2, 3]
|
|
27
|
+
*/
|
|
28
|
+
export declare function mode(values: readonly number[], options?: StatsOptions): number[] | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* `[min, max]` in one pass (no spread, safe for huge arrays).
|
|
31
|
+
* @example extent([3, 1, 4]) // => [1, 4]
|
|
32
|
+
*/
|
|
33
|
+
export declare function extent(values: readonly number[], options?: StatsOptions): [number, number] | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Range `max - min` (named `rangeOf` to avoid clashing with the array module's `range`).
|
|
36
|
+
* @example rangeOf([3, 1, 4]) // => 3
|
|
37
|
+
*/
|
|
38
|
+
export declare function rangeOf(values: readonly number[], options?: StatsOptions): number | undefined;
|
|
39
|
+
/**
|
|
40
|
+
* Variance (sample by default; `population: true` for n). Sample variance needs >= 2 values.
|
|
41
|
+
* @example variance([2, 4, 4, 4, 5, 5, 7, 9], { population: true }) // => 4
|
|
42
|
+
*/
|
|
43
|
+
export declare function variance(values: readonly number[], options?: VarianceOptions): number | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Standard deviation (sample by default).
|
|
46
|
+
* @example stdDev([2, 4, 4, 4, 5, 5, 7, 9], { population: true }) // => 2
|
|
47
|
+
*/
|
|
48
|
+
export declare function stdDev(values: readonly number[], options?: VarianceOptions): number | undefined;
|
|
49
|
+
/** Percentile interpolation methods (NumPy names); `linear` equals Excel `PERCENTILE.INC`. */
|
|
50
|
+
export type PercentileMethod = 'linear' | 'nearest' | 'lower' | 'higher' | 'midpoint';
|
|
51
|
+
export interface PercentileOptions extends StatsOptions {
|
|
52
|
+
/** Default `linear`. */
|
|
53
|
+
readonly method?: PercentileMethod;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Percentile for `p` in `[0, 100]`.
|
|
57
|
+
* @example percentile([1, 2, 3, 4, 5], 90) // => 4.6 // Excel PERCENTILE.INC
|
|
58
|
+
*/
|
|
59
|
+
export declare function percentile(values: readonly number[], p: number, options?: PercentileOptions): number | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Quantile for `q` in `[0, 1]` (same methods as `percentile`).
|
|
62
|
+
* @example quantile([1, 2, 3, 4], 0.25) // => 1.75
|
|
63
|
+
*/
|
|
64
|
+
export declare function quantile(values: readonly number[], q: number, options?: PercentileOptions): number | undefined;
|
|
65
|
+
/**
|
|
66
|
+
* The `n - 1` cut points dividing the data into `n` equal-probability groups (`n` in 2..1000).
|
|
67
|
+
* @example quantiles([1, 2, 3, 4, 5], 4) // => [2, 3, 4]
|
|
68
|
+
*/
|
|
69
|
+
export declare function quantiles(values: readonly number[], n: number, options?: PercentileOptions): number[] | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* `[Q1, median, Q3]` (linear method).
|
|
72
|
+
* @example quartiles([1, 2, 3, 4, 5]) // => [2, 3, 4]
|
|
73
|
+
*/
|
|
74
|
+
export declare function quartiles(values: readonly number[], options?: PercentileOptions): [number, number, number] | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* Interquartile range `Q3 - Q1`.
|
|
77
|
+
* @example iqr([1, 2, 3, 4, 5]) // => 2
|
|
78
|
+
*/
|
|
79
|
+
export declare function iqr(values: readonly number[], options?: PercentileOptions): number | undefined;
|
|
80
|
+
export interface OutlierOptions extends StatsOptions {
|
|
81
|
+
/** Fence multiplier. Default 1.5 (Tukey); 3 flags "far out" values. */
|
|
82
|
+
readonly k?: number;
|
|
83
|
+
}
|
|
84
|
+
export interface OutlierResult {
|
|
85
|
+
readonly lowerFence: number;
|
|
86
|
+
readonly upperFence: number;
|
|
87
|
+
/** Outliers in input order. */
|
|
88
|
+
readonly outliers: number[];
|
|
89
|
+
/** Input indexes of the outliers. */
|
|
90
|
+
readonly indexes: number[];
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Tukey fences `[Q1 - k|IQR, Q3 + k|IQR]` and the values outside them.
|
|
94
|
+
* @example outliers([1, 2, 3, 4, 100])?.outliers // => [100]
|
|
95
|
+
*/
|
|
96
|
+
export declare function outliers(values: readonly number[], options?: OutlierOptions): OutlierResult | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Standard score `(value - mean) / stdDev`; `undefined` when `stdDev` is 0.
|
|
99
|
+
* @example zScore(130, 100, 15) // => 2
|
|
100
|
+
*/
|
|
101
|
+
export declare function zScore(value: number, meanValue: number, stdDevValue: number): number | undefined;
|
|
102
|
+
/**
|
|
103
|
+
* Z-scores of every value (sample standard deviation unless `population`). `undefined` when constant.
|
|
104
|
+
* @example standardize([1, 2, 3]) // => [-1, 0, 1]
|
|
105
|
+
*/
|
|
106
|
+
export declare function standardize(values: readonly number[], options?: VarianceOptions): number[] | undefined;
|
|
107
|
+
/**
|
|
108
|
+
* Min-max scaling to `[0, 1]`; a constant series maps to all zeros.
|
|
109
|
+
* @example normalize([10, 15, 20]) // => [0, 0.5, 1]
|
|
110
|
+
*/
|
|
111
|
+
export declare function normalize(values: readonly number[], options?: StatsOptions): number[] | undefined;
|
|
112
|
+
export interface HistogramBin {
|
|
113
|
+
/** Inclusive lower edge. */
|
|
114
|
+
readonly x0: number;
|
|
115
|
+
/** Exclusive upper edge (inclusive for the last bin). */
|
|
116
|
+
readonly x1: number;
|
|
117
|
+
readonly count: number;
|
|
118
|
+
}
|
|
119
|
+
export interface HistogramOptions extends StatsOptions {
|
|
120
|
+
/** Number of equal-width bins. Default: Sturges' rule. */
|
|
121
|
+
readonly bins?: number;
|
|
122
|
+
/** Bin width; edges align to multiples of the width. Overrides `bins`. */
|
|
123
|
+
readonly binWidth?: number;
|
|
124
|
+
/** Fixed `[min, max]`; values outside are ignored. */
|
|
125
|
+
readonly domain?: readonly [number, number];
|
|
126
|
+
}
|
|
127
|
+
/** Largest bin count `histogram` produces. */
|
|
128
|
+
export declare const MAX_HISTOGRAM_BINS = 10000;
|
|
129
|
+
/**
|
|
130
|
+
* Equal-width histogram.
|
|
131
|
+
* @example histogram([1, 2, 2, 3, 9], { bins: 2 }) // => [{ x0: 1, x1: 5, count: 4 }, { x0: 5, x1: 9, count: 1 }]
|
|
132
|
+
*/
|
|
133
|
+
export declare function histogram(values: readonly number[], options?: HistogramOptions): HistogramBin[];
|
|
134
|
+
/**
|
|
135
|
+
* Occurrence counts in first-seen order (a `Map`, so any value type is safe as a key).
|
|
136
|
+
* @example frequencies(['a', 'b', 'a']) // => new Map([['a', 2], ['b', 1]])
|
|
137
|
+
*/
|
|
138
|
+
export declare function frequencies<T>(values: Iterable<T>): Map<T, number>;
|
|
139
|
+
/**
|
|
140
|
+
* Covariance of paired series (sample by default).
|
|
141
|
+
* @example covariance([1, 2, 3], [2, 4, 6]) // => 2
|
|
142
|
+
*/
|
|
143
|
+
export declare function covariance(xs: readonly number[], ys: readonly number[], options?: VarianceOptions): number | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Pearson correlation in `[-1, 1]`; `undefined` for fewer than 2 pairs or a constant series.
|
|
146
|
+
* @example correlation([1, 2, 3], [3, 2, 1]) // => -1
|
|
147
|
+
*/
|
|
148
|
+
export declare function correlation(xs: readonly number[], ys: readonly number[], options?: StatsOptions): number | undefined;
|
|
149
|
+
export interface LinearRegression {
|
|
150
|
+
readonly slope: number;
|
|
151
|
+
readonly intercept: number;
|
|
152
|
+
/** Coefficient of determination; 1 when every y is equal (a perfect horizontal fit). */
|
|
153
|
+
readonly r2: number;
|
|
154
|
+
predict(x: number): number;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Ordinary least squares fit `y = slope|x + intercept`; `undefined` for < 2 pairs or constant x.
|
|
158
|
+
* @example linearRegression([1, 2, 3], [2, 4, 6])?.predict(4) // => 8
|
|
159
|
+
*/
|
|
160
|
+
export declare function linearRegression(xs: readonly number[], ys: readonly number[], options?: StatsOptions): LinearRegression | undefined;
|
|
161
|
+
/**
|
|
162
|
+
* Trailing simple moving average; result has `length - window + 1` entries (empty when window > length).
|
|
163
|
+
* @example movingAverage([1, 2, 3, 4], 2) // => [1.5, 2.5, 3.5]
|
|
164
|
+
*/
|
|
165
|
+
export declare function movingAverage(values: readonly number[], window: number, options?: StatsOptions): number[];
|
|
166
|
+
/**
|
|
167
|
+
* Running totals (compensated).
|
|
168
|
+
* @example cumulativeSum([0.1, 0.2, 0.3]) // => [0.1, 0.30000000000000004, 0.6] // naive running addition ends at 0.6000000000000001
|
|
169
|
+
*/
|
|
170
|
+
export declare function cumulativeSum(values: readonly number[], options?: StatsOptions): number[];
|
|
171
|
+
/**
|
|
172
|
+
* Geometric mean of non-negative values (0 if any is 0); `undefined` if any is negative.
|
|
173
|
+
* @example geometricMean([1, 4, 16]) // => 4
|
|
174
|
+
*/
|
|
175
|
+
export declare function geometricMean(values: readonly number[], options?: StatsOptions): number | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Harmonic mean of non-negative values (0 if any is 0); `undefined` if any is negative.
|
|
178
|
+
* @example harmonicMean([1, 4, 4]) // => 2
|
|
179
|
+
*/
|
|
180
|
+
export declare function harmonicMean(values: readonly number[], options?: StatsOptions): number | undefined;
|
|
181
|
+
/**
|
|
182
|
+
* Skewness: sample-adjusted (Excel `SKEW`, n >= 3) by default, or population `g1`.
|
|
183
|
+
* @example skewness([1, 2, 3]) // => 0
|
|
184
|
+
*/
|
|
185
|
+
export declare function skewness(values: readonly number[], options?: VarianceOptions): number | undefined;
|
|
186
|
+
/**
|
|
187
|
+
* Excess kurtosis: sample-adjusted (Excel `KURT`, n >= 4) by default, or population `g2`.
|
|
188
|
+
* @example kurtosis([1, 2, 3, 4]) // => ≈ -1.2
|
|
189
|
+
*/
|
|
190
|
+
export declare function kurtosis(values: readonly number[], options?: VarianceOptions): number | undefined;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.1 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as N,ValidationError as f}from"../error/index.js";import{kahanSum as p}from"../number/index.js";function d(t,n={}){let e=!1;for(const r of t)if(!Number.isFinite(r)){e=!0;break}if(!e)return t;if(n.nonFinite==="ignore")return t.filter(r=>Number.isFinite(r));throw new f("HLP_STATS_NOT_FINITE","Values must be finite numbers.")}function h(t,n,e={}){if(t.length!==n.length)throw new f("HLP_STATS_LENGTH","Both series must have the same length.");const r=u=>Number.isFinite(t[u])&&Number.isFinite(n[u]);let o=!1;for(let u=0;u<t.length;u++)if(!r(u)){o=!0;break}if(!o)return[t,n];if(e.nonFinite!=="ignore")throw new f("HLP_STATS_NOT_FINITE","Values must be finite numbers.");const i=[],s=[];for(let u=0;u<t.length;u++)r(u)&&(i.push(t[u]??0),s.push(n[u]??0));return[i,s]}const y=t=>Float64Array.from(t).sort();function F(t,n){const e=d(t,n);return e.length?p(e)/e.length:void 0}function q(t,n,e){const[r,o]=h(t,n,e);let i=0;const s=[];for(let u=0;u<r.length;u++){const m=o[u]??0;if(m<0)throw new f("HLP_STATS_WEIGHT","Weights must not be negative.");i+=m,s.push((r[u]??0)*m)}return i>0?p(s)/p(o):void 0}function W(t,n){return x(y(d(t,n)),.5,"linear")}function k(t,n){const e=d(t,n);if(!e.length)return;const r=new Map;let o=0;for(const s of e){const u=(r.get(s)??0)+1;r.set(s,u),u>o&&(o=u)}const i=[];for(const[s,u]of r)u===o&&i.push(s);return i.sort((s,u)=>s-u)}function g(t,n){const e=d(t,n);if(!e.length)return;let r=1/0,o=-1/0;for(const i of e)i<r&&(r=i),i>o&&(o=i);return[r,o]}function V(t,n){const e=g(t,n);return e?e[1]-e[0]:void 0}function P(t){let n=0,e=0,r=0;for(const o of t){n++;const i=o-e;e+=i/n,r+=i*(o-e)}return{n,mean:e,m2:r}}function A(t,n={}){const{n:e,m2:r}=P(d(t,n)),o=n.population?e:e-1;return o>0?r/o:void 0}function I(t,n={}){const e=A(t,n);return e===void 0?void 0:Math.sqrt(e)}function x(t,n,e){const r=t.length;if(!r)return;const o=(r-1)*n,i=Math.floor(o),s=Math.ceil(o),u=t[i]??0,m=t[s]??0;switch(e){case"lower":return u;case"higher":return m;case"midpoint":return(u+m)/2;case"nearest":{const a=o-i;return a<.5?u:a>.5?m:i%2===0?u:m}case"linear":return u+(m-u)*(o-i)}}function O(t,n){if(!(t>=0&&t<=n))throw new f("HLP_STATS_PERCENTILE","The percentile is out of range.")}function B(t,n,e={}){return O(n,100),x(y(d(t,e)),n/100,e.method??"linear")}function R(t,n,e={}){return O(n,1),x(y(d(t,e)),n,e.method??"linear")}function v(t,n,e={}){if(!Number.isInteger(n)||n<2||n>1e3)throw new f("HLP_STATS_QUANTILES","The group count must be an integer between 2 and 1000.");const r=y(d(t,e));if(!r.length)return;const o=[];for(let i=1;i<n;i++)o.push(x(r,i/n,e.method??"linear")??0);return o}function T(t,n={}){const e=v(t,4,n);return e?[e[0]??0,e[1]??0,e[2]??0]:void 0}function z(t,n={}){const e=T(t,n);return e?e[2]-e[0]:void 0}function G(t,n={}){const{k:e=1.5}=n,r=T(t,n);if(!r)return;const o=r[2]-r[0],i=r[0]-e*o,s=r[2]+e*o,u=[],m=[];return t.forEach((a,c)=>{Number.isFinite(a)&&(a<i||a>s)&&(u.push(a),m.push(c))}),{lowerFence:i,upperFence:s,outliers:u,indexes:m}}function U(t,n,e){return e===0||!Number.isFinite(e)?void 0:(t-n)/e}function j(t,n={}){const e=d(t,n),r=F(e),o=I(e,n);if(!(r===void 0||o===void 0||o===0))return e.map(i=>(i-r)/o)}function C(t,n){const e=d(t,n),r=g(e);if(!r)return;const[o,i]=r;return e.map(s=>i===o?0:(s-o)/(i-o))}const H=1e4;function D(t,n={}){const e=d(t,n),r=n.domain??g(e);if(!r)return[];const[o,i]=r;if(!Number.isFinite(o)||!Number.isFinite(i)||o>i)throw new f("HLP_STATS_DOMAIN","The domain must be a finite [min, max] pair.");let s=o,u,m;if(n.binWidth!==void 0){if(!(n.binWidth>0)||!Number.isFinite(n.binWidth))throw new f("HLP_STATS_BINS","The bin width must be a positive finite number.");u=n.binWidth,s=Math.floor(o/u)*u,m=Math.max(1,Math.floor((i-s)/u)+1)}else{if(m=n.bins??(i===o?1:Math.ceil(Math.log2(Math.max(e.length,1)))+1),!Number.isInteger(m)||m<1)throw new f("HLP_STATS_BINS","The bin count must be a positive integer.");u=i===o?1:(i-o)/m}if(m>H)throw new N("HLP_STATS_TOO_MANY_BINS","The bin count exceeds the limit.");const a=new Array(m).fill(0);for(const c of e){if(c<o||c>i)continue;const l=(c-s)/u,b=Number.isFinite(l)?Math.min(m-1,Math.floor(l)):c>s?m-1:0;a[b]=(a[b]??0)+1}return a.map((c,l)=>({x0:s+l*u,x1:l===m-1&&n.binWidth===void 0&&i!==o?i:s+(l+1)*u,count:c}))}function Q(t){const n=new Map;for(const e of t)n.set(e,(n.get(e)??0)+1);return n}function S(t,n){let e=0,r=0,o=0,i=0,s=0,u=0;for(let m=0;m<t.length;m++){const a=t[m]??0,c=n[m]??0;e++;const l=a-r;r+=l/e;const b=c-o;o+=b/e,i+=l*(c-o),s+=l*(a-r),u+=b*(c-o)}return{n:e,mx:r,my:o,cxy:i,m2x:s,m2y:u}}function X(t,n,e={}){const[r,o]=h(t,n,e),{n:i,cxy:s}=S(r,o),u=e.population?i:i-1;return u>0?s/u:void 0}function Y(t,n,e){const[r,o]=h(t,n,e),{n:i,cxy:s,m2x:u,m2y:m}=S(r,o);if(!(i<2||u===0||m===0))return Math.max(-1,Math.min(1,s/Math.sqrt(u*m)))}function J(t,n,e){const[r,o]=h(t,n,e),{n:i,mx:s,my:u,cxy:m,m2x:a,m2y:c}=S(r,o);if(i<2||a===0)return;const l=m/a,b=u-l*s,w=c===0?1:Math.min(1,m*m/(a*c));return Object.freeze({slope:l,intercept:b,r2:w,predict:_=>l*_+b})}function K(t,n,e){if(!Number.isInteger(n)||n<1)throw new f("HLP_STATS_WINDOW","The window must be a positive integer.");const r=d(t,e),o=[];let i=0,s=0;const u=m=>{const a=i+m;s+=Math.abs(i)>=Math.abs(m)?i-a+m:m-a+i,i=a};for(let m=0;m<r.length;m++)u(r[m]??0),m>=n&&u(-(r[m-n]??0)),m>=n-1&&o.push((i+s)/n);return o}function Z(t,n){const e=d(t,n),r=[];let o=0,i=0;for(const s of e){const u=o+s;i+=Math.abs(o)>=Math.abs(s)?o-u+s:s-u+o,o=u,r.push(o+i)}return r}function $(t,n){const e=d(t,n);if(!(!e.length||e.some(r=>r<0)))return e.includes(0)?0:Math.exp(p(e.map(Math.log))/e.length)}function ee(t,n){const e=d(t,n);if(!(!e.length||e.some(r=>r<0)))return e.includes(0)?0:e.length/p(e.map(r=>1/r))}function M(t){const n=t.length,e=p(t)/n;let r=0,o=0,i=0;for(const s of t){const u=s-e,m=u*u;r+=m,o+=m*u,i+=m*m}return{n,m2:r/n,m3:o/n,m4:i/n}}function ne(t,n={}){const e=d(t,n),{n:r,m2:o,m3:i}=M(e);if(r<(n.population?1:3)||o===0)return;const s=i/o**1.5;return n.population?s:Math.sqrt(r*(r-1))/(r-2)*s}function te(t,n={}){const e=d(t,n),{n:r,m2:o,m4:i}=M(e);if(r<(n.population?1:4)||o===0)return;const s=i/(o*o)-3;return n.population?s:(r-1)/((r-2)*(r-3))*((r+1)*s+6)}export{H as MAX_HISTOGRAM_BINS,Y as correlation,X as covariance,Z as cumulativeSum,g as extent,Q as frequencies,$ as geometricMean,ee as harmonicMean,D as histogram,z as iqr,te as kurtosis,J as linearRegression,F as mean,W as median,k as mode,K as movingAverage,C as normalize,G as outliers,B as percentile,R as quantile,v as quantiles,T as quartiles,V as rangeOf,ne as skewness,j as standardize,I as stdDev,A as variance,q as weightedMean,U as zScore};
|