@absoluteui/helpers 0.0.0-stage → 0.13.2
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,186 @@
|
|
|
1
|
+
/** Standard comparator: negative, zero or positive. */
|
|
2
|
+
export type Comparer<T> = (a: T, b: T) => number;
|
|
3
|
+
/** Where `null`/`undefined` (and invalid numbers/dates) sort. */
|
|
4
|
+
export type NullsOrder = 'first' | 'last';
|
|
5
|
+
export interface CompareOptions {
|
|
6
|
+
/** Default `'last'`. Applies regardless of direction. */
|
|
7
|
+
readonly nulls?: NullsOrder;
|
|
8
|
+
/** Collator for strings; default is UTF-16 code unit order. */
|
|
9
|
+
readonly collator?: Intl.Collator;
|
|
10
|
+
}
|
|
11
|
+
export interface ByOptions extends CompareOptions {
|
|
12
|
+
/** Default `'asc'`. */
|
|
13
|
+
readonly direction?: 'asc' | 'desc';
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Compares numbers, bigints, strings, dates and booleans ascending; mixed types order
|
|
17
|
+
* boolean < number/bigint < string < date < other. Null-like values (`null`, `undefined`,
|
|
18
|
+
* `NaN`, invalid dates) go last by default.
|
|
19
|
+
* @example [3, null, 1].sort(compareValues) // => [1, 3, null]
|
|
20
|
+
*/
|
|
21
|
+
export declare function compareValues(a: unknown, b: unknown, options?: CompareOptions): number;
|
|
22
|
+
/**
|
|
23
|
+
* Builds a comparer from a key selector. Nulls stay where `nulls` says in either direction.
|
|
24
|
+
* @example
|
|
25
|
+
* const people = [{ name: 'Ada', age: 36 }, { name: 'Ben', age: 41 }, { name: 'Cy', age: 29 }];
|
|
26
|
+
* people.sort(by((p) => p.age, { direction: 'desc' })).map((p) => p.name); // => ['Ben', 'Ada', 'Cy']
|
|
27
|
+
*/
|
|
28
|
+
export declare function by<T>(selector: (item: T) => unknown, options?: ByOptions): Comparer<T>;
|
|
29
|
+
/**
|
|
30
|
+
* Adds a key-selector tie-breaker to a comparer (use `composeComparers` to chain comparers).
|
|
31
|
+
* @example
|
|
32
|
+
* const rows = [{ first: 'Ben', last: 'Kay' }, { first: 'Ada', last: 'Lee' }, { first: 'Al', last: 'Kay' }];
|
|
33
|
+
* rows.sort(thenBy(by((r) => r.last), (r) => r.first)).map((r) => r.first); // => ['Al', 'Ben', 'Ada']
|
|
34
|
+
*/
|
|
35
|
+
export declare function thenBy<T>(primary: Comparer<T>, selector: (item: T) => unknown, options?: ByOptions): Comparer<T>;
|
|
36
|
+
/**
|
|
37
|
+
* Combines comparers: the first non-zero result wins.
|
|
38
|
+
* @example
|
|
39
|
+
* const rows = [{ dept: 'IT', salary: 50 }, { dept: 'HR', salary: 40 }, { dept: 'IT', salary: 70 }];
|
|
40
|
+
* rows.sort(composeComparers(by((r) => r.dept), by((r) => r.salary, { direction: 'desc' }))).map((r) => r.salary); // => [40, 70, 50]
|
|
41
|
+
*/
|
|
42
|
+
export declare function composeComparers<T>(...comparers: readonly Comparer<T>[]): Comparer<T>;
|
|
43
|
+
/**
|
|
44
|
+
* Reverses a comparer.
|
|
45
|
+
* @example [1, 3, 2].sort(reverseComparer(compareValues)) // => [3, 2, 1]
|
|
46
|
+
*/
|
|
47
|
+
export declare function reverseComparer<T>(comparer: Comparer<T>): Comparer<T>;
|
|
48
|
+
export interface NaturalCompareOptions {
|
|
49
|
+
readonly locale?: string | readonly string[];
|
|
50
|
+
/** Default: the collator's default (`'variant'`). Use `'base'` to ignore case and accents. */
|
|
51
|
+
readonly sensitivity?: Intl.CollatorOptions['sensitivity'];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Numeric-aware, locale-aware string comparison (`Intl.Collator` with `numeric: true`, cached).
|
|
55
|
+
* @example ['file10', 'file2'].sort(naturalCompare) // => ['file2', 'file10']
|
|
56
|
+
*/
|
|
57
|
+
export declare function naturalCompare(a: string, b: string, options?: NaturalCompareOptions): number;
|
|
58
|
+
/**
|
|
59
|
+
* Equality: SameValueZero by default, structural with `{ deep: true }` (see `deepEqual`).
|
|
60
|
+
* @example equals({ a: 1 }, { a: 1 }, { deep: true }) // => true
|
|
61
|
+
*/
|
|
62
|
+
export declare function equals(a: unknown, b: unknown, options?: {
|
|
63
|
+
readonly deep?: boolean;
|
|
64
|
+
}): boolean;
|
|
65
|
+
export interface BetweenOptions extends CompareOptions {
|
|
66
|
+
/** Which bounds are included. Default `'both'`; `true` = `'both'`, `false` = `'none'`. */
|
|
67
|
+
readonly inclusive?: 'both' | 'none' | 'left' | 'right' | boolean;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* True when `value` lies between `min` and `max` (numbers, bigints, strings, dates).
|
|
71
|
+
* Null-like values are never between.
|
|
72
|
+
* @example between(5, 1, 5) // => true
|
|
73
|
+
* @example between(5, 1, 5, { inclusive: 'left' }) // => false
|
|
74
|
+
*/
|
|
75
|
+
export declare function between<T>(value: T, min: T, max: T, options?: BetweenOptions): boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Half-open numeric range test `start <= value < end`.
|
|
78
|
+
* @example inRange(3, 0, 3) // => false
|
|
79
|
+
*/
|
|
80
|
+
export declare function inRange(value: number, start: number, end: number): boolean;
|
|
81
|
+
/**
|
|
82
|
+
* First value that is not `null`/`undefined`.
|
|
83
|
+
* @example coalesce(undefined, null, 0, 1) // => 0
|
|
84
|
+
*/
|
|
85
|
+
export declare function coalesce<T>(...values: readonly T[]): NonNullable<T> | undefined;
|
|
86
|
+
/**
|
|
87
|
+
* First value that is not nullish and not a blank (whitespace-only) string.
|
|
88
|
+
* @example coalesceBlank(' ', null, 'x') // => 'x'
|
|
89
|
+
*/
|
|
90
|
+
export declare function coalesceBlank<T>(...values: readonly T[]): NonNullable<T> | undefined;
|
|
91
|
+
/** Fluent matcher returned by `match`. */
|
|
92
|
+
export interface Matcher<T, R> {
|
|
93
|
+
/** Adds a case: a predicate (functions are always predicates) or a literal compared with SameValueZero. */
|
|
94
|
+
with<U extends T>(predicate: (value: T) => value is U, handler: (value: U) => R): Matcher<T, R>;
|
|
95
|
+
with(test: ((value: T) => boolean) | T, handler: (value: T) => R): Matcher<T, R>;
|
|
96
|
+
/** Result of the first matching case, else of `handler`. */
|
|
97
|
+
otherwise(handler: (value: T) => R): R;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Minimal pattern matching; the first matching case wins and later cases are not evaluated.
|
|
101
|
+
* @example
|
|
102
|
+
* const label = (status: number): string =>
|
|
103
|
+
* match<number, string>(status).with(200, () => 'ok').with((s) => s >= 500, () => 'server').otherwise(() => 'other');
|
|
104
|
+
* label(200); // => 'ok'
|
|
105
|
+
* label(503); // => 'server'
|
|
106
|
+
* label(404); // => 'other'
|
|
107
|
+
*/
|
|
108
|
+
export declare function match<T, R = unknown>(value: T): Matcher<T, R>;
|
|
109
|
+
/**
|
|
110
|
+
* Returns a function that applies `fn` when `predicate` holds, else returns the input.
|
|
111
|
+
* @example [1, -2].map(when((n: number) => n < 0, (n) => -n)) // => [1, 2]
|
|
112
|
+
*/
|
|
113
|
+
export declare function when<T, R>(predicate: (value: T) => boolean, fn: (value: T) => R): (value: T) => T | R;
|
|
114
|
+
/**
|
|
115
|
+
* Returns a function that applies `fn` unless `predicate` holds.
|
|
116
|
+
* @example unless((s: string) => s.endsWith('/'), (s) => `${s}/`)('a') // => 'a/'
|
|
117
|
+
*/
|
|
118
|
+
export declare function unless<T, R>(predicate: (value: T) => boolean, fn: (value: T) => R): (value: T) => T | R;
|
|
119
|
+
/**
|
|
120
|
+
* Returns a function that runs the handler of the first passing predicate, else `fallback` (or `undefined`).
|
|
121
|
+
* @example const grade = cond([[(n: number) => n >= 90, () => 'A'], [(n) => n >= 80, () => 'B']], () => 'C');
|
|
122
|
+
*/
|
|
123
|
+
export declare function cond<T, R>(pairs: readonly (readonly [(value: T) => boolean, (value: T) => R])[], fallback?: (value: T) => R): (value: T) => R | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Returns a function choosing between two branches.
|
|
126
|
+
* @example ifElse((n: number) => n % 2 === 0, () => 'even', () => 'odd')(3) // => 'odd'
|
|
127
|
+
*/
|
|
128
|
+
export declare function ifElse<T, A, B>(predicate: (value: T) => boolean, onTrue: (value: T) => A, onFalse: (value: T) => B): (value: T) => A | B;
|
|
129
|
+
/**
|
|
130
|
+
* Equality on a selected key (SameValueZero, or deep with `{ deep: true }`).
|
|
131
|
+
* @example isEqualBy((u: { id: number }) => u.id)({ id: 1 }, { id: 1 }) // => true
|
|
132
|
+
*/
|
|
133
|
+
export declare function isEqualBy<T>(selector: (value: T) => unknown, options?: {
|
|
134
|
+
readonly deep?: boolean;
|
|
135
|
+
}): (a: T, b: T) => boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Smallest item by comparer (first wins on ties), or `undefined` when empty.
|
|
138
|
+
* @example minOf([3, 1, 2]) // => 1
|
|
139
|
+
*/
|
|
140
|
+
export declare function minOf<T>(items: Iterable<T>, comparer?: Comparer<T>): T | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Largest item by comparer (first wins on ties), or `undefined` when empty.
|
|
143
|
+
* @example maxOf(['b', 'a'], naturalCompare) // => 'b'
|
|
144
|
+
*/
|
|
145
|
+
export declare function maxOf<T>(items: Iterable<T>, comparer?: Comparer<T>): T | undefined;
|
|
146
|
+
/**
|
|
147
|
+
* Predicate that passes when all predicates pass (short-circuit; empty -> true).
|
|
148
|
+
* @example allPass([(n: number) => n > 0, (n) => n < 10])(5) // => true
|
|
149
|
+
*/
|
|
150
|
+
export declare function allPass<T>(predicates: readonly ((value: T) => boolean)[]): (value: T) => boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Predicate that passes when any predicate passes (empty -> false).
|
|
153
|
+
* @example anyPass([(n: number) => n < 0, (n) => n > 10])(11) // => true
|
|
154
|
+
*/
|
|
155
|
+
export declare function anyPass<T>(predicates: readonly ((value: T) => boolean)[]): (value: T) => boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Predicate that passes when no predicate passes.
|
|
158
|
+
* @example nonePass([(s: string) => s === ''])('x') // => true
|
|
159
|
+
*/
|
|
160
|
+
export declare function nonePass<T>(predicates: readonly ((value: T) => boolean)[]): (value: T) => boolean;
|
|
161
|
+
/**
|
|
162
|
+
* Predicate that passes when exactly one predicate passes (n-ary xor on predicates).
|
|
163
|
+
* @example onePass([(n: number) => n > 0, (n) => n > 5])(3) // => true
|
|
164
|
+
*/
|
|
165
|
+
export declare function onePass<T>(predicates: readonly ((value: T) => boolean)[]): (value: T) => boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Negates a predicate.
|
|
168
|
+
* @example [1, 2].filter(complement((n: number) => n % 2 === 0)) // => [1]
|
|
169
|
+
*/
|
|
170
|
+
export declare function complement<A extends unknown[]>(predicate: (...args: A) => boolean): (...args: A) => boolean;
|
|
171
|
+
export interface OrderCheckOptions<T> {
|
|
172
|
+
/** Default `compareValues`. */
|
|
173
|
+
readonly comparer?: Comparer<T>;
|
|
174
|
+
/** Require strictly increasing/decreasing values (no equal neighbours). Default false. */
|
|
175
|
+
readonly strict?: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* True when the array is in ascending order.
|
|
179
|
+
* @example isAscending([1, 2, 2, 3]) // => true
|
|
180
|
+
*/
|
|
181
|
+
export declare function isAscending<T>(items: readonly T[], options?: OrderCheckOptions<T>): boolean;
|
|
182
|
+
/**
|
|
183
|
+
* True when the array is in descending order.
|
|
184
|
+
* @example isDescending([3, 2, 1], { strict: true }) // => true
|
|
185
|
+
*/
|
|
186
|
+
export declare function isDescending<T>(items: readonly T[], options?: OrderCheckOptions<T>): boolean;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{deepEqual as y}from"../object/index.js";const f=n=>n<0?-1:n>0?1:0;function i(n){if(n==null)return-1;switch(typeof n){case"boolean":return 1;case"number":return Number.isNaN(n)?-1:2;case"bigint":return 2;case"string":return 3;default:return n instanceof Date?Number.isNaN(n.getTime())?-1:4:5}}function T(n,e,r){const o=i(n),t=i(e);return o!==t?o-t:typeof n=="string"&&typeof e=="string"?r?f(r.compare(n,e)):n<e?-1:n>e?1:0:n instanceof Date&&e instanceof Date?f(n.getTime()-e.getTime()):(typeof n=="number"||typeof n=="bigint")&&(typeof e=="number"||typeof e=="bigint")?n<e?-1:n>e?1:0:typeof n=="boolean"&&typeof e=="boolean"?Number(n)-Number(e):0}function m(n,e,r,o){const t=i(n)===-1,u=i(e)===-1;if(t||u){if(t&&u){const a=l=>l===null?0:l===void 0?1:2;return f(a(n)-a(e))}return(t?-1:1)*(r==="first"?1:-1)}return o()}function p(n,e,r={}){const{nulls:o="last",collator:t}=r;return m(n,e,o,()=>T(n,e,t))}function x(n,e={}){const{direction:r="asc",nulls:o="last",collator:t}=e,u=r==="desc"?-1:1;return(a,l)=>{const s=n(a),c=n(l);return m(s,c,o,()=>u*T(s,c,t))}}function R(n,e,r={}){const o=x(e,r);return(t,u)=>n(t,u)||o(t,u)}function O(...n){return(e,r)=>{for(const o of n){const t=o(e,r);if(t!==0)return t}return 0}}function k(n){return(e,r)=>-n(e,r)||0}const d=new Map;function h(n,e){const r=`${Array.isArray(n)?n.join(","):String(n??"")}|${e??""}`;let o=d.get(r);return o||(d.size>=32&&d.clear(),o=new Intl.Collator(n,{numeric:!0,...e?{sensitivity:e}:{}}),d.set(r,o)),o}function N(n,e,r={}){return f(h(r.locale,r.sensitivity).compare(n,e))}function b(n,e,r={}){return r.deep?y(n,e):n===e||Number.isNaN(n)&&Number.isNaN(e)}function v(n,e,r,o={}){const t=o.inclusive??"both",u=t===!0?"both":t===!1?"none":t;if(i(n)===-1||i(e)===-1||i(r)===-1)return!1;const a=T(n,e,o.collator),l=T(n,r,o.collator),s=u==="both"||u==="left"?a>=0:a>0,c=u==="both"||u==="right"?l<=0:l<0;return s&&c}function B(n,e,r){return n>=e&&n<r}function A(...n){for(const e of n)if(e!=null)return e}function I(...n){for(const e of n)if(e!=null&&!(typeof e=="string"&&e.trim()===""))return e}function M(n){let e=!1,r;const o={with(t,u){return e||(typeof t=="function"?t(n):b(t,n))&&(e=!0,r=u(n)),o},otherwise(t){return e?r:t(n)}};return o}function D(n,e){return r=>n(r)?e(r):r}function P(n,e){return r=>n(r)?r:e(r)}function q(n,e){return r=>{for(const[o,t]of n)if(o(r))return t(r);return e?.(r)}}function E(n,e,r){return o=>n(o)?e(o):r(o)}function U(n,e={}){return(r,o)=>b(n(r),n(o),e)}function g(n,e=p){let r,o=!1;for(const t of n)(!o||e(t,r)<0)&&(r=t,o=!0);return r}function $(n,e=p){return g(n,(r,o)=>e(o,r))}function j(n){return e=>n.every(r=>r(e))}function z(n){return e=>n.some(r=>r(e))}function S(n){return e=>!n.some(r=>r(e))}function V(n){return e=>{let r=0;for(const o of n)if(o(e)&&++r>1)return!1;return r===1}}function F(n){return(...e)=>!n(...e)}function w(n,e={}){const{comparer:r=p,strict:o=!1}=e;for(let t=1;t<n.length;t++){const u=r(n[t-1],n[t]);if(u>0||o&&u===0)return!1}return!0}function G(n,e={}){const{comparer:r=p,strict:o=!1}=e;return w(n,{comparer:(t,u)=>r(u,t),strict:o})}export{j as allPass,z as anyPass,v as between,x as by,A as coalesce,I as coalesceBlank,p as compareValues,F as complement,O as composeComparers,q as cond,b as equals,E as ifElse,B as inRange,w as isAscending,G as isDescending,U as isEqualBy,M as match,$ as maxOf,g as minOf,N as naturalCompare,S as nonePass,V as onePass,k as reverseComparer,R as thenBy,P as unless,D as when};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict conversions (docs/PLAN-HELPERS.md section 2 `convert`). Every `to*` returns `undefined` on
|
|
3
|
+
* failure, never `NaN`; `...OrThrow` variants throw `ValidationError`.
|
|
4
|
+
*/
|
|
5
|
+
import { type Result, ValidationError } from '../error/index.js';
|
|
6
|
+
import { type ParseBooleanOptions } from '../boolean/index.js';
|
|
7
|
+
export interface ToNumberOptions {
|
|
8
|
+
/** Parse locale-formatted text (group/decimal separators, native digits), e.g. `'de'` for `'1.234,5'`. */
|
|
9
|
+
readonly locale?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Strict number conversion. Accepts finite numbers, safe-range bigints and numeric strings
|
|
13
|
+
* (trimmed; sign, decimals, exponent; `-` U+2212 as minus). Rejects `''`, whitespace, `'12abc'`,
|
|
14
|
+
* hex, `NaN` and `+/-Infinity`.
|
|
15
|
+
* @example toNumber(' -1.5e3 ') // => -1500
|
|
16
|
+
* @example toNumber('1.234,5', { locale: 'de' }) // => 1234.5
|
|
17
|
+
* @example toNumber('12abc') // => undefined
|
|
18
|
+
*/
|
|
19
|
+
export declare function toNumber(value: unknown, options?: ToNumberOptions): number | undefined;
|
|
20
|
+
/** How `toInteger` treats fractions. `'none'` rejects them; `'round'` rounds half away from zero. */
|
|
21
|
+
export type IntegerRounding = 'none' | 'trunc' | 'floor' | 'ceil' | 'round' | 'half-even';
|
|
22
|
+
export interface ToIntegerOptions extends ToNumberOptions {
|
|
23
|
+
/** Default `'none'`. */
|
|
24
|
+
readonly rounding?: IntegerRounding;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Strict integer conversion with an explicit rounding mode.
|
|
28
|
+
* @example toInteger('42') // => 42
|
|
29
|
+
* @example toInteger('2.5', { rounding: 'half-even' }) // => 2
|
|
30
|
+
* @example toInteger(1.5) // => undefined // rounding 'none'
|
|
31
|
+
*/
|
|
32
|
+
export declare function toInteger(value: unknown, options?: ToIntegerOptions): number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Like `toInteger` but also requires `Number.MIN_SAFE_INTEGER..MAX_SAFE_INTEGER`.
|
|
35
|
+
* @example toSafeInteger('9007199254740993') // => undefined
|
|
36
|
+
*/
|
|
37
|
+
export declare function toSafeInteger(value: unknown, options?: ToIntegerOptions): number | undefined;
|
|
38
|
+
/**
|
|
39
|
+
* Converts bigints, integer numbers and decimal integer strings (trimmed, up to 10,000 digits) to `bigint`.
|
|
40
|
+
* @example toBigInt('-12345678901234567890') // => -12345678901234567890n
|
|
41
|
+
*/
|
|
42
|
+
export declare function toBigInt(value: unknown): bigint | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Boolean conversion via `parseBoolean` (true/false/yes/no/y/n/on/off/1/0).
|
|
45
|
+
* @example toBoolean('off') // => false
|
|
46
|
+
*/
|
|
47
|
+
export declare function toBoolean(value: unknown, options?: ParseBooleanOptions): boolean | undefined;
|
|
48
|
+
/**
|
|
49
|
+
* Strict date conversion: valid `Date` (copied), epoch milliseconds, or ISO 8601 text only -
|
|
50
|
+
* `YYYY-MM-DD` (UTC midnight) or `YYYY-MM-DDTHH:mm[:ss[.fff]]` with optional `Z`/`+/-HH:mm`
|
|
51
|
+
* (no zone = local time). Ambiguous forms like `'01/02/2026'` are rejected.
|
|
52
|
+
* @example toDate('2026-09-29T10:00:00Z')?.getTime() // => 1790676000000
|
|
53
|
+
* @example toDate('01/02/2026') // => undefined
|
|
54
|
+
*/
|
|
55
|
+
export declare function toDate(value: unknown): Date | undefined;
|
|
56
|
+
/**
|
|
57
|
+
* Human-safe string for any value; never `'[object Object]'`. Nullish -> `''`; dates -> ISO;
|
|
58
|
+
* errors -> `'Name: message'`; plain objects, arrays, maps and sets -> JSON (cycles as `'[Circular]'`,
|
|
59
|
+
* bigints as strings); objects with their own `toString` use it.
|
|
60
|
+
* @example toStringSafe({ a: 1n }) // => '{"a":"1"}'
|
|
61
|
+
* @example toStringSafe(Symbol('x')) // => 'Symbol(x)'
|
|
62
|
+
*/
|
|
63
|
+
export declare function toStringSafe(value: unknown): string;
|
|
64
|
+
/**
|
|
65
|
+
* Array from anything: nullish -> `[]`, arrays copied, iterables (Set, Map entries, generators) spread,
|
|
66
|
+
* strings and other values wrapped (`'ab'` -> `['ab']`).
|
|
67
|
+
* @example toArray(new Set([1, 2])) // => [1, 2]
|
|
68
|
+
* @example toArray(5) // => [5]
|
|
69
|
+
*/
|
|
70
|
+
export declare function toArray<T>(value: Iterable<T> | T | null | undefined): T[];
|
|
71
|
+
/**
|
|
72
|
+
* Set from anything, with `toArray` rules (nullish -> empty set).
|
|
73
|
+
* @example toSet([1, 1, 2]).size // => 2
|
|
74
|
+
*/
|
|
75
|
+
export declare function toSet<T>(value: Iterable<T> | T | null | undefined): Set<T>;
|
|
76
|
+
/**
|
|
77
|
+
* Map from a map (copied), an iterable of `[key, value]` pairs or a plain object; nullish -> empty map.
|
|
78
|
+
* Returns `undefined` for anything else.
|
|
79
|
+
* @example toMap({ a: 1 })?.get('a') // => 1
|
|
80
|
+
*/
|
|
81
|
+
export declare function toMap<K, V>(value: ReadonlyMap<K, V> | Iterable<readonly [K, V]>): Map<K, V> | undefined;
|
|
82
|
+
export declare function toMap<V>(value: Readonly<Record<string, V>>): Map<string, V> | undefined;
|
|
83
|
+
export declare function toMap(value: unknown): Map<unknown, unknown> | undefined;
|
|
84
|
+
/**
|
|
85
|
+
* Plain object from a plain object (shallow copy), class instance (own enumerable props), `Map`
|
|
86
|
+
* or iterable (including arrays) of `[key, value]` pairs with string/number keys. Unsafe keys (`__proto__`, ...) from maps/pairs -> `undefined`.
|
|
87
|
+
* @example toPlainObject(new Map([['a', 1]])) // => { a: 1 }
|
|
88
|
+
*/
|
|
89
|
+
export declare function toPlainObject(value: unknown): Record<string, unknown> | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* `toNumber` or throw `ValidationError` (`HLP_CONVERT_NUMBER`).
|
|
92
|
+
* @example toNumberOrThrow('3') // => 3
|
|
93
|
+
*/
|
|
94
|
+
export declare function toNumberOrThrow(value: unknown, options?: ToNumberOptions): number;
|
|
95
|
+
/**
|
|
96
|
+
* `toInteger` or throw `ValidationError` (`HLP_CONVERT_INTEGER`).
|
|
97
|
+
* @example toIntegerOrThrow('7') // => 7
|
|
98
|
+
*/
|
|
99
|
+
export declare function toIntegerOrThrow(value: unknown, options?: ToIntegerOptions): number;
|
|
100
|
+
/**
|
|
101
|
+
* `toDate` or throw `ValidationError` (`HLP_CONVERT_DATE`).
|
|
102
|
+
* @example toDateOrThrow('2026-01-01')
|
|
103
|
+
*/
|
|
104
|
+
export declare function toDateOrThrow(value: unknown): Date;
|
|
105
|
+
/**
|
|
106
|
+
* Strict integer parse for radix 2-36: optional sign, digits only (no whitespace, prefixes or
|
|
107
|
+
* trailing text); `undefined` when invalid or outside the safe-integer range.
|
|
108
|
+
* @example parseIntStrict('ff', 16) // => 255
|
|
109
|
+
* @example parseIntStrict('12px') // => undefined
|
|
110
|
+
*/
|
|
111
|
+
export declare function parseIntStrict(text: string, radix?: number): number | undefined;
|
|
112
|
+
/** Target types for `coerce`. */
|
|
113
|
+
export interface CoerceTypes {
|
|
114
|
+
string: string;
|
|
115
|
+
number: number;
|
|
116
|
+
integer: number;
|
|
117
|
+
'safe-integer': number;
|
|
118
|
+
bigint: bigint;
|
|
119
|
+
boolean: boolean;
|
|
120
|
+
date: Date;
|
|
121
|
+
array: unknown[];
|
|
122
|
+
}
|
|
123
|
+
export type CoerceKind = keyof CoerceTypes;
|
|
124
|
+
/**
|
|
125
|
+
* Converts `value` to the named kind with the strict `to*` rules; `undefined` on failure.
|
|
126
|
+
* @example coerce('42', 'integer') // => 42
|
|
127
|
+
*/
|
|
128
|
+
export declare function coerce<K extends CoerceKind>(value: unknown, kind: K): CoerceTypes[K] | undefined;
|
|
129
|
+
/** Field spec for `coerceFields`: a kind, or a kind with `optional`. */
|
|
130
|
+
export type FieldSpec = CoerceKind | {
|
|
131
|
+
readonly kind: CoerceKind;
|
|
132
|
+
readonly optional?: boolean;
|
|
133
|
+
};
|
|
134
|
+
type SpecKind<S> = S extends CoerceKind ? S : S extends {
|
|
135
|
+
readonly kind: infer K extends CoerceKind;
|
|
136
|
+
} ? K : never;
|
|
137
|
+
/** Result shape of `coerceFields`. */
|
|
138
|
+
export type Coerced<S extends Readonly<Record<string, FieldSpec>>> = {
|
|
139
|
+
-readonly [P in keyof S]: S[P] extends {
|
|
140
|
+
readonly optional: true;
|
|
141
|
+
} ? CoerceTypes[SpecKind<S[P]>] | undefined : CoerceTypes[SpecKind<S[P]>];
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* Coerces a record (e.g. form or query values) by a schema. Missing, `null` and blank values fail
|
|
145
|
+
* as required unless `optional`. Errors come back as one `ValidationError` (`HLP_CONVERT_FIELDS`)
|
|
146
|
+
* whose `fields` maps each bad key to a message.
|
|
147
|
+
* @example
|
|
148
|
+
* coerceFields({ age: '42', active: 'yes' }, { age: 'integer', active: 'boolean' });
|
|
149
|
+
* // ok({ age: 42, active: true })
|
|
150
|
+
*/
|
|
151
|
+
export declare function coerceFields<S extends Readonly<Record<string, FieldSpec>>>(input: unknown, schema: S): Result<Coerced<S>, ValidationError>;
|
|
152
|
+
export {};
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as g,err as j,ok as F}from"../error/index.js";import{isPlainObject as x}from"../is/index.js";import{assertSafeKey as V,hasOwn as B,isUnsafeKey as L}from"../internal/keys.js";import{daysInMonth as $}from"../date/plain-date.js";import{parseBoolean as H}from"../boolean/index.js";const C=1e3,U=/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i,k=/[\u061c\u200e\u200f]/g,b=new Map;function G(n){let e=b.get(n);if(e)return e;const t=new Intl.NumberFormat(n,{useGrouping:!0}).formatToParts(-12345.6),o=(s,u)=>(t.find(d=>d.type===s)?.value??u).replace(k,""),r=new Intl.NumberFormat(n,{useGrouping:!1}),i=new Map;for(let s=0;s<=9;s++)i.set(r.format(s).replace(k,""),String(s));return e={group:o("group",","),decimal:o("decimal","."),minus:o("minusSign","-"),digits:i},b.size>=32&&b.clear(),b.set(n,e),e}const E=new Set([" ","\xA0","\u202F","\u2009"]);function X(n,e){const{group:t,decimal:o,minus:r,digits:i}=G(e),s=E.has(t);let u="";for(const d of n.replace(k,"")){const f=i.get(d);if(f!==void 0)u+=f;else if(d===o)u+=".";else{if(d===t||s&&E.has(d))continue;d===r||d==="\u2212"?u+="-":u+=d}}return u}function S(n,e={}){if(typeof n=="number")return Number.isFinite(n)?n:void 0;if(typeof n=="bigint"){const r=Number(n);return Number.isSafeInteger(r)?r:void 0}if(typeof n!="string"||n.length>C)return;let t=n.trim();if(e.locale!==void 0?t=X(t,e.locale):t.startsWith("\u2212")&&(t=`-${t.slice(1)}`),!U.test(t))return;const o=Number(t);return Number.isFinite(o)?o:void 0}function W(n,e){switch(e){case"none":return Number.isInteger(n)?n:void 0;case"trunc":return Math.trunc(n);case"floor":return Math.floor(n);case"ceil":return Math.ceil(n);case"round":return Math.sign(n)*Math.round(Math.abs(n));case"half-even":{const t=Math.floor(n),o=n-t;return o!==.5?o<.5?t:t+1:t%2===0?t:t+1}}}function N(n,e={}){const t=S(n,e);if(t===void 0)return;const o=W(t,e.rounding??"none");return o===void 0?void 0:o+0}function z(n,e={}){const t=N(n,e);return t!==void 0&&Number.isSafeInteger(t)?t:void 0}const Y=/^[+-]?\d+$/;function Z(n){if(typeof n=="bigint")return n;if(typeof n=="number")return Number.isInteger(n)?BigInt(n):void 0;if(typeof n!="string"||n.length>10001)return;const e=n.trim();return Y.test(e)?BigInt(e):void 0}function q(n,e={}){return H(n,e)}const J=864e13,Q=/^([+-]\d{6}|\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,9}))?)?(Z|[+-]\d{2}:\d{2})?)?$/;function v(n){if(n.length<10||n.length>40)return;const e=Q.exec(n);if(!e)return;const[,t="",o="",r="",i,s="0",u="0",d="",f]=e;if(t==="-000000")return;const c=Number(t),a=Number(o),m=Number(r),y=Number(i??"0"),l=Number(s),w=Number(u),h=Math.floor(+`0.${d||"0"}`*1e3);if(a<1||a>12||m<1||m>$(c,a)||y>23||l>59||w>59)return;const p=new Date(0);if(i!==void 0&&f===void 0)p.setFullYear(c,a-1,m),p.setHours(y,l,w,h);else{let M=0;if(f!==void 0&&f!=="Z"){const O=Number(f.slice(1,3)),R=Number(f.slice(4,6));if(O>23||R>59)return;M=(f.startsWith("-")?-1:1)*(O*60+R)}p.setUTCFullYear(c,a-1,m),p.setUTCHours(y,l-M,w,h)}const I=p.getTime();return Number.isNaN(I)?void 0:I}function K(n){if(n instanceof Date)return Number.isNaN(n.getTime())?void 0:new Date(n.getTime());if(typeof n=="number")return Number.isFinite(n)&&Math.abs(n)<=J?new Date(n):void 0;if(typeof n!="string")return;const e=v(n.trim());return e===void 0?void 0:new Date(e)}function _(n,e,t){e==="__proto__"?Object.defineProperty(n,e,{value:t,writable:!0,enumerable:!0,configurable:!0}):n[e]=t}function A(n){const e=new Set,t=r=>{if(typeof r=="bigint"||typeof r=="symbol")return r.toString();if(typeof r!="object"||r===null)return r;if(r instanceof Date)return Number.isNaN(r.getTime())?null:r.toISOString();if(e.has(r))return"[Circular]";e.add(r);let i;if(Array.isArray(r))i=r.map(t);else if(r instanceof Map)i=[...r].map(([s,u])=>[t(s),t(u)]);else if(r instanceof Set)i=[...r].map(t);else{const s={};for(const u of Object.keys(r))_(s,u,t(r[u]));i=s}return e.delete(r),i};return JSON.stringify(t(n))??""}function nn(n){switch(typeof n){case"string":return n;case"number":return Object.is(n,-0)?"0":String(n);case"bigint":case"boolean":return String(n);case"symbol":return n.toString();case"undefined":return"";case"function":return n.name?`[Function: ${n.name}]`:"[Function]";default:break}if(n===null)return"";if(n instanceof Date)return Number.isNaN(n.getTime())?"":n.toISOString();if(n instanceof Error)return n.message?`${n.name}: ${n.message}`:n.name;if(n instanceof RegExp)return n.toString();if(Array.isArray(n)||x(n)||n instanceof Map||n instanceof Set)return A(n);const e=n.toString;if(typeof e=="function"&&e!==Object.prototype.toString){const t=e.call(n);if(typeof t=="string")return t}return A(n)}const T=n=>typeof n=="object"&&n!==null&&typeof n[Symbol.iterator]=="function";function D(n){return n==null?[]:Array.isArray(n)?n.slice():T(n)?Array.from(n):[n]}function un(n){return new Set(D(n))}function fn(n){if(n==null)return new Map;if(n instanceof Map)return new Map(n);if(x(n))return new Map(Object.entries(n));if(T(n)&&typeof n!="string"){const e=new Map;for(const t of n){if(!Array.isArray(t)||t.length!==2)return;e.set(t[0],t[1])}return e}}function dn(n){if(typeof n!="object"||n===null)return;const e={};if(n instanceof Map||T(n)){const t=(n instanceof Map,n);for(const o of t){if(!Array.isArray(o)||o.length!==2)return;const[r,i]=o;if(typeof r!="string"&&typeof r!="number")return;const s=String(r);if(L(s))return;e[s]=i}return e}for(const t of Object.keys(n))_(e,t,n[t]);return e}function cn(n,e={}){const t=S(n,e);if(t===void 0)throw new g("HLP_CONVERT_NUMBER","Expected a number.");return t}function an(n,e={}){const t=N(n,e);if(t===void 0)throw new g("HLP_CONVERT_INTEGER","Expected an integer.");return t}function pn(n){const e=K(n);if(e===void 0)throw new g("HLP_CONVERT_DATE","Expected an ISO 8601 date.");return e}function gn(n,e=10){if(!Number.isInteger(e)||e<2||e>36)throw new g("HLP_CONVERT_RADIX","The radix must be an integer from 2 to 36.");if(typeof n!="string"||n.length===0||n.length>C)return;const t=n.startsWith("-")||n.startsWith("+")?1:0;if(t===n.length)return;for(let r=t;r<n.length;r++){const i=n.charCodeAt(r),s=i|32;if((i>=48&&i<=57?i-48:s>=97&&s<=122?s-87:99)>=e)return}const o=Number.parseInt(n,e);return Number.isSafeInteger(o)?o+0:void 0}const P={string:n=>typeof n=="string"?n:typeof n=="number"||typeof n=="bigint"||typeof n=="boolean"||n instanceof Date?nn(n):void 0,number:n=>S(n),integer:n=>N(n),"safe-integer":n=>z(n),bigint:Z,boolean:n=>q(n),date:K,array:n=>D(n)};function mn(n,e){return P[e](n)}function bn(n,e){const t=typeof n=="object"&&n!==null?n:{},o={},r={};for(const[i,s]of Object.entries(e)){V(i);const u=typeof s=="string"?s:s.kind,d=typeof s=="string"?!1:s.optional===!0,f=B(t,i)?t[i]:void 0;if(f==null||typeof f=="string"&&f.trim()===""){d?o[i]=void 0:r[i]="Required.";continue}const c=P[u](f);c===void 0?r[i]=`Expected ${u}.`:o[i]=c}return Object.keys(r).length?j(new g("HLP_CONVERT_FIELDS","One or more fields are invalid.",{fields:r})):F(o)}export{mn as coerce,bn as coerceFields,gn as parseIntStrict,D as toArray,Z as toBigInt,q as toBoolean,K as toDate,pn as toDateOrThrow,N as toInteger,an as toIntegerOrThrow,fn as toMap,S as toNumber,cn as toNumberOrThrow,dn as toPlainObject,z as toSafeInteger,un as toSet,nn as toStringSafe};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSV: RFC 4180 parsing (one-shot and streaming), delimiter detection, and writing with
|
|
3
|
+
* CSV-injection neutralization (docs/PLAN-HELPERS.md section 2, section 5).
|
|
4
|
+
*/
|
|
5
|
+
export { parseCsv, createCsvParser, detectDelimiter, type CsvParseOptions, type CsvResult, type CsvError, type CsvStreamParser } from './parse.js';
|
|
6
|
+
export { stringifyCsv, escapeCsvCell, isFormulaLike, type CsvStringifyOptions, type CsvColumn, type EscapeCsvCellOptions } from './stringify.js';
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{parseCsv as t,createCsvParser as r,detectDelimiter as p}from"./parse.js";import{stringifyCsv as i,escapeCsvCell as v,isFormulaLike as o}from"./stringify.js";export{r as createCsvParser,p as detectDelimiter,v as escapeCsvCell,o as isFormulaLike,t as parseCsv,i as stringifyCsv};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** A problem found while parsing. `row` is the 1-based record number (the header is row 1). */
|
|
2
|
+
export interface CsvError {
|
|
3
|
+
readonly row: number;
|
|
4
|
+
/** 1-based line where the record starts. */
|
|
5
|
+
readonly line: number;
|
|
6
|
+
readonly code: 'HLP_CSV_UNCLOSED_QUOTE' | 'HLP_CSV_UNEXPECTED_QUOTE' | 'HLP_CSV_FIELD_COUNT' | 'HLP_CSV_UNSAFE_HEADER' | 'HLP_CSV_DUPLICATE_HEADER';
|
|
7
|
+
}
|
|
8
|
+
export interface CsvParseOptions {
|
|
9
|
+
/** Field delimiter (one character) or `'auto'` to detect among `, ; \t |`. Default `'auto'`. */
|
|
10
|
+
readonly delimiter?: string;
|
|
11
|
+
/** Quote character. Default `"`. */
|
|
12
|
+
readonly quote?: string;
|
|
13
|
+
/** Treat the first record as column names and return objects. Default false. */
|
|
14
|
+
readonly header?: boolean;
|
|
15
|
+
/** Trim whitespace around unquoted fields and outside quotes. Default false. */
|
|
16
|
+
readonly trim?: boolean;
|
|
17
|
+
/** Skip records that are completely empty (a blank line). Default true. */
|
|
18
|
+
readonly skipEmptyLines?: boolean;
|
|
19
|
+
/** Lines starting with this character are ignored. Default: none. */
|
|
20
|
+
readonly comment?: string;
|
|
21
|
+
/** Maximum data rows; more throws `HLP_CSV_TOO_MANY_ROWS`. Default 1 000 000. */
|
|
22
|
+
readonly maxRows?: number;
|
|
23
|
+
/** Maximum characters per field; longer throws `HLP_CSV_FIELD_TOO_LONG`. Default 1 000 000. */
|
|
24
|
+
readonly maxFieldLength?: number;
|
|
25
|
+
/** Maximum fields per record; more throws `HLP_CSV_TOO_MANY_COLUMNS`. Default 10 000. */
|
|
26
|
+
readonly maxColumns?: number;
|
|
27
|
+
}
|
|
28
|
+
export interface CsvResult<R> {
|
|
29
|
+
readonly rows: R[];
|
|
30
|
+
/** Column names (after renaming unsafe/duplicate/empty names); empty without `header`. */
|
|
31
|
+
readonly headers: string[];
|
|
32
|
+
readonly errors: CsvError[];
|
|
33
|
+
/** Delimiter used (detected or given). */
|
|
34
|
+
readonly delimiter: string;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detects the delimiter from a sample by counting candidates outside quotes on the first
|
|
38
|
+
* lines and preferring the most consistent, then most frequent. Defaults to `,`.
|
|
39
|
+
* @example detectDelimiter('a;b;c\n1;2;3') // => ';'
|
|
40
|
+
*/
|
|
41
|
+
export declare function detectDelimiter(sample: string, candidates?: readonly string[], quote?: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Parses CSV text (RFC 4180: quoted fields with delimiters and line breaks, `""` escapes,
|
|
44
|
+
* CRLF/LF/CR, BOM). With `header`, rows are objects keyed by column name; unsafe names such as
|
|
45
|
+
* `__proto__` are renamed (`column_N`) and reported. Malformed input is reported in `errors`,
|
|
46
|
+
* never thrown; limits throw `LimitError`.
|
|
47
|
+
* @example parseCsv('name,age\r\n"Doe, Jane",42', { header: true }).rows // => [{ name: 'Doe, Jane', age: '42' }]
|
|
48
|
+
*/
|
|
49
|
+
export declare function parseCsv(text: string, options: CsvParseOptions & {
|
|
50
|
+
readonly header: true;
|
|
51
|
+
}): CsvResult<Record<string, string>>;
|
|
52
|
+
export declare function parseCsv(text: string, options?: CsvParseOptions & {
|
|
53
|
+
readonly header?: false;
|
|
54
|
+
}): CsvResult<string[]>;
|
|
55
|
+
export declare function parseCsv(text: string, options?: CsvParseOptions): CsvResult<Record<string, string> | string[]>;
|
|
56
|
+
/** Streaming parser handle returned by {@link createCsvParser}. */
|
|
57
|
+
export interface CsvStreamParser<R> {
|
|
58
|
+
/** Feeds a chunk (any split point) and returns the rows completed by it. */
|
|
59
|
+
push(chunk: string): R[];
|
|
60
|
+
/** Flushes the final record and returns the remaining rows. */
|
|
61
|
+
end(): R[];
|
|
62
|
+
/** Column names once the header row has been read. */
|
|
63
|
+
readonly headers: readonly string[];
|
|
64
|
+
/** Errors so far. */
|
|
65
|
+
readonly errors: readonly CsvError[];
|
|
66
|
+
/** Delimiter in use (after auto-detection). */
|
|
67
|
+
readonly delimiter: string | undefined;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Incremental CSV parser for large files: feed string chunks (for example from
|
|
71
|
+
* `TextDecoderStream`) and collect rows as they complete. Quotes and CRLF split across chunks
|
|
72
|
+
* are handled. With `delimiter: 'auto'`, the first 64 KiB (or 10 lines) are buffered for detection.
|
|
73
|
+
* @example
|
|
74
|
+
* const p = createCsvParser({ header: true, delimiter: ',' });
|
|
75
|
+
* p.push('name,dept\nAda,Eng'); // => []
|
|
76
|
+
* p.push('\nGrace,Ops\n'); // => [{ name: 'Ada', dept: 'Eng' }, { name: 'Grace', dept: 'Ops' }]
|
|
77
|
+
* p.end(); // => []
|
|
78
|
+
*/
|
|
79
|
+
export declare function createCsvParser(options: CsvParseOptions & {
|
|
80
|
+
readonly header: true;
|
|
81
|
+
}): CsvStreamParser<Record<string, string>>;
|
|
82
|
+
export declare function createCsvParser(options?: CsvParseOptions & {
|
|
83
|
+
readonly header?: false;
|
|
84
|
+
}): CsvStreamParser<string[]>;
|
|
85
|
+
export declare function createCsvParser(options?: CsvParseOptions): CsvStreamParser<Record<string, string> | string[]>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{LimitError as _,ValidationError as y}from"../error/index.js";import{isUnsafeKey as x}from"../internal/keys.js";const E=[",",";"," ","|"];function S(h,t=E,o='"'){const i=h.length>65536?h.slice(0,65536):h,a=t.map(()=>[]);let s=t.map(()=>0),r=!1,u=0;for(let d=0;d<i.length&&u<10;d++){const c=i.charAt(d);if(c===o)r=!r;else if(!r&&(c===`
|
|
3
|
+
`||c==="\r"))c==="\r"&&i.charAt(d+1)===`
|
|
4
|
+
`&&d++,a.forEach((f,g)=>f.push(s[g]??0)),s=t.map(()=>0),u++;else if(!r){const f=t.indexOf(c);f>=0&&(s[f]=(s[f]??0)+1)}}u<10&&s.some(d=>d>0)&&a.forEach((d,c)=>d.push(s[c]??0));let n=",",e=-1;return t.forEach((d,c)=>{const f=(a[c]??[]).filter((m,p,k)=>m>0||p<k.length-1);if(f.length===0||f.every(m=>m===0))return;const g=new Map;for(const m of f)g.set(m,(g.get(m)??0)+1);let C=0,v=0;for(const[m,p]of g)m>0&&(p>C||p===C&&m>v)&&([v,C]=[m,p]);const L=C/f.length*1e3+Math.min(v,999);v>0&&L>e&&([n,e]=[d,L])}),n}const l={FieldStart:0,Unquoted:1,Quoted:2,QuoteInQuoted:3,AfterQuoted:4,Comment:5};class P{state=l.FieldStart;lastWasCr=!1;recordErrors=[];field="";record=[];anyQuoted=!1;skipLf=!1;line=1;recordLine=1;started=!1;delimiter;quote;trim;comment;limits;onRecord;constructor(t,o,i,a,s,r){this.delimiter=t,this.quote=o,this.trim=i,this.comment=a,this.limits=s,this.onRecord=r}onError(t){this.recordErrors.push(t)}checkField(t){if(this.field.length+t>this.limits.maxFieldLength)throw new _("HLP_CSV_FIELD_TOO_LONG","A CSV field exceeds the length limit.",{details:{maxFieldLength:this.limits.maxFieldLength}})}endField(){if(this.checkField(0),this.record.push(this.state===l.Unquoted&&this.trim?this.field.trimEnd():this.field),this.record.length>this.limits.maxColumns)throw new _("HLP_CSV_TOO_MANY_COLUMNS","A CSV record has too many fields.",{details:{maxColumns:this.limits.maxColumns}});this.field=""}endRecord(){const t=this.record,o=!this.anyQuoted&&t.length===1&&t[0]==="",i=this.recordErrors;this.record=[],this.recordErrors=[],this.anyQuoted=!1,this.onRecord(t,{line:this.recordLine,blank:o,errors:i})}push(t,o){let i=t;!this.started&&i.length>0&&(this.started=!0,i.charCodeAt(0)===65279&&(i=i.slice(1)));const{delimiter:a,quote:s}=this;let r=-1;const u=n=>{r>=0&&(this.checkField(n-r),this.field+=i.slice(r,n),r=-1)};for(let n=0;n<i.length;n++){const e=i.charAt(n);if(!(this.skipLf&&(this.skipLf=!1,e===`
|
|
5
|
+
`)))switch(this.state){case l.FieldStart:if(this.record.length===0&&this.comment!==void 0&&e===this.comment)this.state=l.Comment;else if(e===s)this.state=l.Quoted,this.anyQuoted=!0;else if(e===a){if(this.record.push(""),this.record.length>this.limits.maxColumns)throw new _("HLP_CSV_TOO_MANY_COLUMNS","A CSV record has too many fields.",{details:{maxColumns:this.limits.maxColumns}})}else e===`
|
|
6
|
+
`||e==="\r"?(this.record.push(""),this.newline(e)):this.trim&&(e===" "||e===" ")||(this.state=l.Unquoted,r=n);break;case l.Unquoted:e===a?(u(n),this.endField(),this.state=l.FieldStart):e===`
|
|
7
|
+
`||e==="\r"?(u(n),this.endField(),this.state=l.FieldStart,this.newline(e)):r<0&&(r=n);break;case l.Quoted:e===s?(u(n),this.lastWasCr=!1,this.state=l.QuoteInQuoted):((e==="\r"||e===`
|
|
8
|
+
`&&!this.lastWasCr)&&this.line++,this.lastWasCr=e==="\r",r<0&&(r=n));break;case l.QuoteInQuoted:e===s?(this.checkField(1),this.field+=s,this.state=l.Quoted):e===a?(this.endField(),this.state=l.FieldStart):e===`
|
|
9
|
+
`||e==="\r"?(this.endField(),this.state=l.FieldStart,this.newline(e)):this.trim&&(e===" "||e===" ")?this.state=l.AfterQuoted:(this.onError("HLP_CSV_UNEXPECTED_QUOTE"),this.state=l.Unquoted,r=n);break;case l.AfterQuoted:e===a?(this.endField(),this.state=l.FieldStart):e===`
|
|
10
|
+
`||e==="\r"?(this.endField(),this.state=l.FieldStart,this.newline(e)):e!==" "&&e!==" "&&(this.onError("HLP_CSV_UNEXPECTED_QUOTE"),this.state=l.Unquoted,r=n);break;case l.Comment:(e===`
|
|
11
|
+
`||e==="\r")&&(e==="\r"&&(this.skipLf=!0),this.line++,this.recordLine=this.line,this.state=l.FieldStart);break}}u(i.length),o&&this.finish()}newline(t){t==="\r"&&(this.skipLf=!0),this.endRecord(),this.line++,this.recordLine=this.line}finish(){switch(this.state){case l.Comment:return;case l.FieldStart:if(this.record.length===0)return;this.record.push("");break;case l.Quoted:this.onError("HLP_CSV_UNCLOSED_QUOTE"),this.endField();break;default:this.endField()}this.state=l.FieldStart,this.endRecord()}}function O(h,t,o){const i=new Set;return h.map((a,s)=>{let r=a;if(x(r)&&(t.push({row:1,line:o,code:"HLP_CSV_UNSAFE_HEADER"}),r=""),r===""&&(r=`column_${s+1}`),i.has(r)){t.push({row:1,line:o,code:"HLP_CSV_DUPLICATE_HEADER"});let u=2;for(;i.has(`${r}_${u}`);)u++;r=`${r}_${u}`}return i.add(r),r})}function R(h,t,o){const i=[],a=[];let s=0,r=0,u=-1;return{headers:i,errors:a,record(n,e){if(e.blank&&t)return;s++;for(const c of e.errors)a.push({row:s,line:e.line,code:c});if(h&&s===1){i.push(...O(n,a,e.line)),u=i.length;return}if(r++,r>o)throw new _("HLP_CSV_TOO_MANY_ROWS","The CSV has too many rows.",{details:{maxRows:o}});if(u<0?u=n.length:n.length!==u&&a.push({row:s,line:e.line,code:"HLP_CSV_FIELD_COUNT"}),!h)return n;const d={};for(let c=0;c<i.length;c++)d[i[c]??""]=n[c]??"";return d}}}function w(h){const{quote:t='"',trim:o=!1,comment:i,skipEmptyLines:a=!0,maxRows:s=1e6,maxFieldLength:r=1e6,maxColumns:u=1e4}=h;if(t.length!==1)throw new y("HLP_CSV_OPTION","The quote must be a single character.");if(i!==void 0&&i.length!==1)throw new y("HLP_CSV_OPTION","The comment marker must be a single character.");return{quote:t,trim:o,comment:i,skipEmpty:a,maxRows:s,limits:{maxFieldLength:r,maxColumns:u}}}function b(h,t){if(h.length!==1||h===t||h===`
|
|
12
|
+
`||h==="\r")throw new y("HLP_CSV_OPTION","The delimiter must be a single character other than the quote or a line break.")}function A(h,t={}){const o=w(t),i=t.delimiter===void 0||t.delimiter==="auto"?S(h,E,o.quote):t.delimiter;b(i,o.quote);const a=R(t.header===!0,o.skipEmpty,o.maxRows),s=[];return new P(i,o.quote,o.trim,o.comment,o.limits,(u,n)=>{const e=a.record(u,n);e!==void 0&&s.push(e)}).push(h,!0),{rows:s,headers:a.headers,errors:a.errors,delimiter:i}}function U(h={}){const t=w(h),o=R(h.header===!0,t.skipEmpty,t.maxRows);let i=h.delimiter===void 0||h.delimiter==="auto"?void 0:h.delimiter;i!==void 0&&b(i,t.quote);let a=[],s="",r;const u=d=>(b(d,t.quote),new P(d,t.quote,t.trim,t.comment,t.limits,(c,f)=>{const g=o.record(c,f);g!==void 0&&a.push(g)})),n=()=>{const d=a;return a=[],d},e=d=>{let c=0;for(let f=0;f<d.length&&c<10;f++)d.charCodeAt(f)===10&&c++;return c};return{push(d){if(!r){if(i===void 0){if(s+=d,s.length<65536&&e(s)<10)return[];i=S(s,E,t.quote)}r=u(i);const c=s===""?d:s;return s="",r.push(c,!1),n()}return r.push(d,!1),n()},end(){return r?(r.push("",!0),n()):(i??=S(s,E,t.quote),r=u(i),r.push(s,!0),s="",n())},get headers(){return o.headers},get errors(){return o.errors},get delimiter(){return i}}}export{U as createCsvParser,S as detectDelimiter,A as parseCsv};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface EscapeCsvCellOptions {
|
|
2
|
+
/** Default `,`. */
|
|
3
|
+
readonly delimiter?: string;
|
|
4
|
+
/** `'minimal'` (default) quotes only when needed; `'all'` quotes every cell. */
|
|
5
|
+
readonly quote?: 'minimal' | 'all';
|
|
6
|
+
/**
|
|
7
|
+
* Prefix cells that start with `=`, `+`, `-`, `@`, tab or CR (and their full-width forms)
|
|
8
|
+
* with `'` so spreadsheets do not evaluate them as formulas. Default true.
|
|
9
|
+
*/
|
|
10
|
+
readonly injectionProtection?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/** True when a spreadsheet could interpret the cell as a formula. @example isFormulaLike('=1+1') // => true */
|
|
13
|
+
export declare function isFormulaLike(cell: string): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Escapes one cell: quotes it when it contains the delimiter, a quote, CR/LF, or leading or
|
|
16
|
+
* trailing spaces, doubling inner quotes; neutralizes formula-like text by default.
|
|
17
|
+
* @example escapeCsvCell('say "hi"') // => '"say ""hi"""'
|
|
18
|
+
* @example escapeCsvCell('=SUM(A1)') // => "'=SUM(A1)"
|
|
19
|
+
*/
|
|
20
|
+
export declare function escapeCsvCell(value: string, options?: EscapeCsvCellOptions): string;
|
|
21
|
+
/** A column for object rows. */
|
|
22
|
+
export interface CsvColumn<T> {
|
|
23
|
+
/** Property to read. */
|
|
24
|
+
readonly key: string;
|
|
25
|
+
/** Header text. Default: the key. */
|
|
26
|
+
readonly header?: string;
|
|
27
|
+
/** Converts the value before writing. */
|
|
28
|
+
readonly format?: (value: unknown, row: T) => unknown;
|
|
29
|
+
}
|
|
30
|
+
export interface CsvStringifyOptions<T> extends EscapeCsvCellOptions {
|
|
31
|
+
/** Columns for object rows (default: keys in first-seen order), or header names for array rows. */
|
|
32
|
+
readonly columns?: readonly (string | CsvColumn<T>)[];
|
|
33
|
+
/** Write a header row. Default true for object rows (and array rows with `columns`). */
|
|
34
|
+
readonly header?: boolean;
|
|
35
|
+
/** Line terminator. Default `\r\n` (RFC 4180). */
|
|
36
|
+
readonly eol?: '\r\n' | '\n';
|
|
37
|
+
/** Prepend a UTF-8 BOM so Excel detects the encoding. Default false. */
|
|
38
|
+
readonly bom?: boolean;
|
|
39
|
+
/** End the output with a line terminator. Default true. */
|
|
40
|
+
readonly trailingEol?: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Writes rows (arrays or objects) as CSV. Numbers, booleans and dates are never prefixed by
|
|
44
|
+
* injection protection (a negative number stays numeric); strings are.
|
|
45
|
+
* @example stringifyCsv([{ name: 'Ada', score: 1 }]) // => 'name,score\r\nAda,1\r\n'
|
|
46
|
+
* @example stringifyCsv([['a', 'b'], ['1', '2']], { eol: '\n' }) // => 'a,b\n1,2\n'
|
|
47
|
+
*/
|
|
48
|
+
export declare function stringifyCsv<T extends object>(rows: readonly T[] | readonly (readonly unknown[])[], options?: CsvStringifyOptions<T>): string;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*! AbsoluteUI @absoluteui/helpers v0.13.2 | (c) Kasadara Technology Solutions Pvt Ltd | Apache-2.0 | https://aui.kasadara.com/license/ */
|
|
2
|
+
import{ValidationError as x}from"../error/index.js";const w=new Set([61,43,45,64,9,13,65309,65291,65293,65312]);function T(n){return n.length>0&&w.has(n.charCodeAt(0))}function C(n,t={}){const{delimiter:s=",",quote:a="minimal",injectionProtection:c=!0}=t,r=c&&T(n)?`'${n}`:n;return a==="all"||r.includes(s)||r.includes('"')||r.includes(`
|
|
3
|
+
`)||r.includes("\r")||r.length>0&&(r.charCodeAt(0)===32||r.charCodeAt(r.length-1)===32)?`"${r.replaceAll('"','""')}"`:r}function O(n){if(n==null)return"";if(typeof n=="string")return n;if(typeof n=="number"||typeof n=="boolean"||typeof n=="bigint")return String(n);if(n instanceof Date)return Number.isNaN(n.getTime())?"":n.toISOString();if(typeof n=="symbol"||typeof n=="function")return"";try{const t=JSON.stringify(n,(s,a)=>typeof a=="bigint"?a.toString():a);return typeof t=="string"?t:""}catch{return""}}function A(n,t={}){const{delimiter:s=",",quote:a="minimal",injectionProtection:c=!0,eol:r=`\r
|
|
4
|
+
`,bom:y=!1,trailingEol:b=!0}=t;if(s.length!==1||s==='"'||s===`
|
|
5
|
+
`||s==="\r")throw new x("HLP_CSV_OPTION","The delimiter must be a single character other than the quote or a line break.");const g=e=>C(O(e),{delimiter:s,quote:a,injectionProtection:c&&typeof e=="string"}),m=e=>C(e,{delimiter:s,quote:a,injectionProtection:c}),l=[],u=e=>e.length===1&&e[0]===""?'""':e.join(s),p=n[0];if(p===void 0?t.columns===void 0||t.columns.every(e=>typeof e=="string"):Array.isArray(p)){const e=(t.columns??[]).map(i=>typeof i=="string"?i:i.header??i.key);e.length>0&&t.header!==!1&&l.push(u(e.map(m)));for(const i of n)l.push(u(i.map(g)))}else{const e=n;let i;if(t.columns)i=t.columns.map(o=>typeof o=="string"?{key:o}:o);else{const o=new Set;for(const f of e)for(const d of Object.keys(f))o.add(d);i=[...o].map(f=>({key:f}))}t.header!==!1&&l.push(u(i.map(o=>m(o.header??o.key))));for(const o of e){const f=o;l.push(u(i.map(d=>{const h=Object.prototype.hasOwnProperty.call(f,d.key)?f[d.key]:void 0;return g(d.format?d.format(h,o):h)})))}}const k=l.join(r);return(y?"\uFEFF":"")+k+(b&&l.length>0?r:"")}export{C as escapeCsvCell,T as isFormulaLike,A as stringifyCsv};
|