df-script 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +83 -34
- package/dist/api.d.ts +16 -8
- package/dist/api.js +11 -3
- package/dist/columnExpressions/ColumnExpr.d.ts +26 -364
- package/dist/columnExpressions/ColumnExpr.js +199 -3
- package/dist/columnExpressions/ExprBase.d.ts +8 -11
- package/dist/columnExpressions/ExprBase.js +20 -61
- package/dist/columnExpressions/constants.d.ts +2 -0
- package/dist/columnExpressions/constants.js +3 -1
- package/dist/columnExpressions/functions/coalesce.js +8 -4
- package/dist/columnExpressions/functions/element.d.ts +5 -0
- package/dist/columnExpressions/functions/element.js +11 -0
- package/dist/columnExpressions/functions/implode.d.ts +3 -0
- package/dist/columnExpressions/functions/implode.js +7 -0
- package/dist/columnExpressions/functions/lit.d.ts +3 -1
- package/dist/columnExpressions/functions/lit.js +8 -13
- package/dist/columnExpressions/functions/repeat.d.ts +47 -0
- package/dist/columnExpressions/functions/repeat.js +131 -0
- package/dist/columnExpressions/functions/seq_range.d.ts +31 -0
- package/dist/columnExpressions/functions/seq_range.js +91 -0
- package/dist/columnExpressions/functions/when.js +8 -4
- package/dist/columnExpressions/index.d.ts +5 -2
- package/dist/columnExpressions/index.js +5 -48
- package/dist/columnExpressions/mixins/AggregationExpr.d.ts +25 -50
- package/dist/columnExpressions/mixins/AggregationExpr.js +69 -165
- package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +41 -66
- package/dist/columnExpressions/mixins/ArithmeticExpr.js +126 -138
- package/dist/columnExpressions/mixins/BooleanExpr.d.ts +40 -0
- package/dist/columnExpressions/mixins/BooleanExpr.js +67 -0
- package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +31 -60
- package/dist/columnExpressions/mixins/ComparisonExpr.js +231 -370
- package/dist/columnExpressions/mixins/ListExpr.d.ts +15 -39
- package/dist/columnExpressions/mixins/ListExpr.js +124 -148
- package/dist/columnExpressions/mixins/LogicalExpr.d.ts +7 -33
- package/dist/columnExpressions/mixins/LogicalExpr.js +48 -49
- package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +6 -31
- package/dist/columnExpressions/mixins/ManipulationExpr.js +61 -25
- package/dist/columnExpressions/mixins/NumericExpr.d.ts +92 -0
- package/dist/columnExpressions/mixins/NumericExpr.js +259 -0
- package/dist/columnExpressions/mixins/StringExpr.d.ts +5 -30
- package/dist/columnExpressions/mixins/StringExpr.js +37 -49
- package/dist/columnExpressions/mixins/StructExpr.d.ts +16 -0
- package/dist/columnExpressions/mixins/StructExpr.js +139 -0
- package/dist/columnExpressions/mixins/TemporalExpr.d.ts +4 -30
- package/dist/columnExpressions/mixins/TemporalExpr.js +28 -29
- package/dist/columnExpressions/mixins/WindowExpr.d.ts +27 -49
- package/dist/columnExpressions/mixins/WindowExpr.js +144 -274
- package/dist/columnExpressions/utils.d.ts +4 -0
- package/dist/columnExpressions/utils.js +45 -0
- package/dist/dataframe/constants.d.ts +3 -0
- package/dist/dataframe/constants.js +4 -1
- package/dist/dataframe/dataframe.d.ts +27 -10
- package/dist/dataframe/dataframe.js +461 -220
- package/dist/dataframe/grouped/grouped.d.ts +2 -3
- package/dist/dataframe/grouped/grouped.js +17 -16
- package/dist/dataframe/types.d.ts +65 -1
- package/dist/dataframe/utils.d.ts +11 -3
- package/dist/dataframe/utils.js +101 -9
- package/dist/datatypes/DataType.d.ts +2 -1
- package/dist/datatypes/DataType.js +29 -0
- package/dist/datatypes/index.d.ts +2 -2
- package/dist/datatypes/types.d.ts +37 -36
- package/dist/datatypes/types.js +15 -11
- package/dist/exceptions/index.d.ts +2 -0
- package/dist/exceptions/index.js +4 -1
- package/dist/exceptions/utils.d.ts +1 -0
- package/dist/exceptions/utils.js +19 -0
- package/dist/functions/concat.d.ts +1 -2
- package/dist/functions/concat.js +24 -12
- package/dist/functions/index.d.ts +3 -1
- package/dist/functions/index.js +7 -15
- package/dist/functions/read_csv.d.ts +8 -0
- package/dist/functions/read_csv.js +53 -0
- package/dist/functions/read_json.d.ts +10 -0
- package/dist/functions/read_json.js +21 -0
- package/dist/functions/transpose.d.ts +7 -0
- package/dist/functions/transpose.js +84 -0
- package/dist/index.js +6 -1
- package/dist/types.d.ts +31 -5
- package/dist/utils/csv.d.ts +77 -0
- package/dist/utils/csv.js +313 -0
- package/dist/utils/date.js +5 -6
- package/dist/utils/guards.d.ts +0 -2
- package/dist/utils/guards.js +0 -31
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/json.d.ts +120 -2
- package/dist/utils/json.js +204 -20
- package/dist/utils/list.d.ts +173 -1
- package/dist/utils/list.js +255 -22
- package/dist/utils/number.d.ts +61 -28
- package/dist/utils/number.js +248 -70
- package/dist/utils/string.d.ts +5 -0
- package/dist/utils/string.js +89 -0
- package/package.json +5 -1
package/dist/utils/json.js
CHANGED
|
@@ -2,32 +2,216 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isJsonString = isJsonString;
|
|
4
4
|
exports.safeJsonParse = safeJsonParse;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
exports.createSafeJsonReplacer = createSafeJsonReplacer;
|
|
6
|
+
const guards_1 = require("./guards");
|
|
7
|
+
const date_1 = require("./date");
|
|
8
|
+
const NEWLINE_REGEX = /\r\n|\n|\r/g;
|
|
9
|
+
const NO_FALLBACK = Symbol("no_fallback");
|
|
10
|
+
const isWrapped = (str) => {
|
|
11
|
+
const len = str.length;
|
|
12
|
+
if (len < 2)
|
|
10
13
|
return false;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
const fChar = str[0];
|
|
15
|
+
const lChar = str[len - 1];
|
|
16
|
+
return (fChar === "{" && lChar === "}") || (fChar === "[" && lChar === "]");
|
|
17
|
+
};
|
|
18
|
+
const isWrappedUntrimmed = (str) => {
|
|
19
|
+
let first = 0;
|
|
20
|
+
const len = str.length;
|
|
21
|
+
while (first < len && /\s/.test(str[first])) {
|
|
22
|
+
first++;
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
let last = len - 1;
|
|
25
|
+
while (last >= first && /\s/.test(str[last])) {
|
|
26
|
+
last--;
|
|
19
27
|
}
|
|
20
|
-
|
|
28
|
+
if (first >= last)
|
|
21
29
|
return false;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
const fChar = str[first];
|
|
31
|
+
const lChar = str[last];
|
|
32
|
+
return (fChar === "{" && lChar === "}") || (fChar === "[" && lChar === "]");
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Validates whether the given value is a valid JSON or NDJSON string.
|
|
36
|
+
* Leverages single-pass parsing under the hood to ensure zero duplicate loops.
|
|
37
|
+
*
|
|
38
|
+
* @param input - The value to check.
|
|
39
|
+
* @param options - Configuration options for validation.
|
|
40
|
+
* @returns `true` if the input is a valid JSON or NDJSON string; `false` otherwise.
|
|
41
|
+
*/
|
|
42
|
+
function isJsonString(input, options = {}) {
|
|
25
43
|
if (typeof input !== "string")
|
|
26
|
-
return
|
|
44
|
+
return false;
|
|
45
|
+
const sentinel = Symbol("invalid");
|
|
46
|
+
const result = safeJsonParse(input, {
|
|
47
|
+
...options,
|
|
48
|
+
fallback: sentinel,
|
|
49
|
+
onError: () => { } // Silence errors during pure structural checking
|
|
50
|
+
});
|
|
51
|
+
return result !== sentinel;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Safely parses a string containing JSON or NDJSON content in a single pass, returning the parsed value if successful
|
|
55
|
+
* and passing the guard validation. If parsing or validation fails, returns the fallback value (if provided)
|
|
56
|
+
* or the original input.
|
|
57
|
+
*
|
|
58
|
+
* @param input - The value to parse.
|
|
59
|
+
* @param options - Configuration options for parsing and validation.
|
|
60
|
+
* @returns The parsed value, the fallback, or the original input.
|
|
61
|
+
*/
|
|
62
|
+
function safeJsonParse(input, { format = "json", allowPrimitives = false, trimBeforeParse = false, reviver, ndjson: { skipInvalidLines = false, maxLines, skipLines } = {}, guard, onError, fallback = NO_FALLBACK } = {}) {
|
|
63
|
+
if (typeof input !== "string") {
|
|
64
|
+
return fallback !== NO_FALLBACK ? fallback : input;
|
|
65
|
+
}
|
|
66
|
+
const s = trimBeforeParse ? input.trim() : input;
|
|
67
|
+
if (s === "") {
|
|
68
|
+
return fallback !== NO_FALLBACK ? fallback : input;
|
|
69
|
+
}
|
|
70
|
+
let result;
|
|
27
71
|
try {
|
|
28
|
-
|
|
72
|
+
if (format === "ndjson") {
|
|
73
|
+
const parsedData = [];
|
|
74
|
+
let nonEmptyCount = 0;
|
|
75
|
+
let parsedCount = 0;
|
|
76
|
+
let lastIndex = 0;
|
|
77
|
+
NEWLINE_REGEX.lastIndex = 0;
|
|
78
|
+
let match;
|
|
79
|
+
while (true) {
|
|
80
|
+
match = NEWLINE_REGEX.exec(s);
|
|
81
|
+
const line = match ? s.substring(lastIndex, match.index) : s.substring(lastIndex);
|
|
82
|
+
if (match) {
|
|
83
|
+
lastIndex = NEWLINE_REGEX.lastIndex;
|
|
84
|
+
}
|
|
85
|
+
const trimmedLine = line.trim();
|
|
86
|
+
if (trimmedLine !== "") {
|
|
87
|
+
nonEmptyCount++;
|
|
88
|
+
if (skipLines === undefined || nonEmptyCount > skipLines) {
|
|
89
|
+
if (!allowPrimitives && !isWrapped(trimmedLine)) {
|
|
90
|
+
if (!skipInvalidLines) {
|
|
91
|
+
throw new Error("NDJSON line is not wrapped and primitives are disallowed");
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
try {
|
|
96
|
+
parsedData.push(JSON.parse(trimmedLine, reviver));
|
|
97
|
+
parsedCount++;
|
|
98
|
+
if (maxLines !== undefined && parsedCount >= maxLines)
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (!skipInvalidLines)
|
|
103
|
+
throw err;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
if (!match)
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (parsedData.length === 0) {
|
|
112
|
+
throw new Error("No valid NDJSON lines processed");
|
|
113
|
+
}
|
|
114
|
+
result = parsedData;
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
if (!allowPrimitives && !isWrappedUntrimmed(s)) {
|
|
118
|
+
throw new Error("JSON string is not wrapped and primitives are disallowed");
|
|
119
|
+
}
|
|
120
|
+
result = JSON.parse(s, reviver);
|
|
121
|
+
}
|
|
29
122
|
}
|
|
30
|
-
catch {
|
|
31
|
-
|
|
123
|
+
catch (err) {
|
|
124
|
+
onError?.(err);
|
|
125
|
+
return fallback !== NO_FALLBACK ? fallback : input;
|
|
32
126
|
}
|
|
127
|
+
if (guard && !guard(result)) {
|
|
128
|
+
onError?.(new Error("Parsed value failed guard validation"));
|
|
129
|
+
return fallback !== NO_FALLBACK ? fallback : input;
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
function createSafeJsonReplacer(options = {}) {
|
|
134
|
+
const bigintStrat = options.bigintStrategy ?? "string";
|
|
135
|
+
let seen = options.handleCircular ? new WeakSet() : null;
|
|
136
|
+
const isArrayReplacer = Array.isArray(options.replacer);
|
|
137
|
+
const whitelist = isArrayReplacer ? options.replacer.map(String) : null;
|
|
138
|
+
const handleBigInt = (val) => {
|
|
139
|
+
if (bigintStrat === "number") {
|
|
140
|
+
return val <= BigInt(Number.MAX_SAFE_INTEGER) && val >= BigInt(Number.MIN_SAFE_INTEGER)
|
|
141
|
+
? Number(val)
|
|
142
|
+
: val.toString();
|
|
143
|
+
}
|
|
144
|
+
return val.toString();
|
|
145
|
+
};
|
|
146
|
+
return function replacer(k, v) {
|
|
147
|
+
let val = v;
|
|
148
|
+
if (typeof options.replacer === "function") {
|
|
149
|
+
val = options.replacer.call(this, k, v);
|
|
150
|
+
}
|
|
151
|
+
else if (whitelist) {
|
|
152
|
+
if (k !== "" && !Array.isArray(this) && !whitelist.includes(k)) {
|
|
153
|
+
return undefined;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (val === undefined)
|
|
157
|
+
return undefined;
|
|
158
|
+
const raw = (val === v && this != null) ? this[k] : val;
|
|
159
|
+
if (typeof options.onCustom === "function") {
|
|
160
|
+
const customVal = options.onCustom.call(this, k, raw);
|
|
161
|
+
if (customVal !== raw || (customVal === undefined && raw !== undefined)) {
|
|
162
|
+
return customVal;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (raw !== null && typeof raw !== "object" && typeof raw !== "bigint") {
|
|
166
|
+
return val;
|
|
167
|
+
}
|
|
168
|
+
if (seen && raw !== null && typeof raw === "object") {
|
|
169
|
+
if (k === "") {
|
|
170
|
+
seen = new WeakSet();
|
|
171
|
+
}
|
|
172
|
+
if (seen.has(raw)) {
|
|
173
|
+
return options.onCircular ? options.onCircular.call(this, k, raw) : "[Circular]";
|
|
174
|
+
}
|
|
175
|
+
seen.add(raw);
|
|
176
|
+
}
|
|
177
|
+
if (typeof raw === "bigint") {
|
|
178
|
+
if (options.voidBigIntReplacement)
|
|
179
|
+
return val;
|
|
180
|
+
return options.onBigInt ? options.onBigInt(raw) : handleBigInt(raw);
|
|
181
|
+
}
|
|
182
|
+
if ((0, guards_1.isTypedArray)(raw)) {
|
|
183
|
+
if (options.voidTypedArrayReplacement)
|
|
184
|
+
return val;
|
|
185
|
+
return options.onTypedArray ? options.onTypedArray(raw) : Array.from(raw);
|
|
186
|
+
}
|
|
187
|
+
if (raw instanceof Set) {
|
|
188
|
+
if (options.voidSetReplacement)
|
|
189
|
+
return val;
|
|
190
|
+
return options.onSet ? options.onSet(raw) : Array.from(raw);
|
|
191
|
+
}
|
|
192
|
+
if (raw instanceof Map) {
|
|
193
|
+
if (options.voidMapReplacement)
|
|
194
|
+
return val;
|
|
195
|
+
return options.onMap ? options.onMap(raw) : Array.from(raw.entries());
|
|
196
|
+
}
|
|
197
|
+
if (raw instanceof RegExp) {
|
|
198
|
+
if (options.voidRegExpReplacement)
|
|
199
|
+
return val;
|
|
200
|
+
return options.onRegExp ? options.onRegExp(raw) : raw.toString();
|
|
201
|
+
}
|
|
202
|
+
if ((0, date_1.isValidDateObj)(raw)) {
|
|
203
|
+
if (options.voidDateReplacement)
|
|
204
|
+
return val;
|
|
205
|
+
if (options.onDate)
|
|
206
|
+
return options.onDate(raw);
|
|
207
|
+
return options.formatDate ? options.formatDate(raw) : raw.toISOString();
|
|
208
|
+
}
|
|
209
|
+
if (raw instanceof Error) {
|
|
210
|
+
return options.onError ? options.onError(raw) : { name: raw.name, message: raw.message, stack: raw.stack };
|
|
211
|
+
}
|
|
212
|
+
if (raw instanceof URLSearchParams) {
|
|
213
|
+
return options.onURLSearchParams ? options.onURLSearchParams(raw) : raw.toString();
|
|
214
|
+
}
|
|
215
|
+
return val;
|
|
216
|
+
};
|
|
33
217
|
}
|
package/dist/utils/list.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type ArrayItemType = "string" | "number" | "boolean" | "bigint" | "object" | "plainObject" | "date" | (new (...args: any[]) => any) | ((v: unknown) => boolean);
|
|
1
|
+
export type ArrayItemType = "string" | "number" | "boolean" | "bigint" | "object" | "plainObject" | "date" | "any" | "null" | "undefined" | "nullish" | (new (...args: any[]) => any) | ((v: unknown) => boolean);
|
|
2
2
|
export type ArrayCheckMode = "every" | "some";
|
|
3
3
|
export type IsArrayOfTypeOptionsParams = {
|
|
4
4
|
mode?: ArrayCheckMode;
|
|
@@ -6,6 +6,7 @@ export type IsArrayOfTypeOptionsParams = {
|
|
|
6
6
|
allowEmpty?: boolean;
|
|
7
7
|
};
|
|
8
8
|
export declare function toValidArray<T>(val: T | T[] | null | undefined): T[];
|
|
9
|
+
export declare function toValidStringArray(val: unknown): string[];
|
|
9
10
|
export declare function isArrayOfType(arr: unknown, type: ArrayItemType, { mode, allowNulls, allowEmpty }?: IsArrayOfTypeOptionsParams): boolean;
|
|
10
11
|
export declare function sortList(arr: unknown, descending?: boolean): any[];
|
|
11
12
|
export declare function getListStats(arr: unknown): {
|
|
@@ -21,3 +22,174 @@ export declare function getListStats(arr: unknown): {
|
|
|
21
22
|
hasNulls: boolean;
|
|
22
23
|
isNumeric: boolean;
|
|
23
24
|
};
|
|
25
|
+
/**
|
|
26
|
+
* Options configuration for the `getUniqueListStats` utility.
|
|
27
|
+
*/
|
|
28
|
+
export interface UniqueListStatsOptions {
|
|
29
|
+
/**
|
|
30
|
+
* If true, uses strict serialization comparison (via keySelector or toCanonicalString)
|
|
31
|
+
* to group complex nested types (like Arrays, Sets, Maps, and Dates) by value instead of reference.
|
|
32
|
+
* @default false
|
|
33
|
+
*/
|
|
34
|
+
strict?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Custom function to extract a unique comparison key from each element.
|
|
37
|
+
* If strict is true and no selector is provided, falls back to `toCanonicalString`.
|
|
38
|
+
*/
|
|
39
|
+
keySelector?: (val: any) => any;
|
|
40
|
+
}
|
|
41
|
+
export declare function getUniqueListStats(arr: ArrayLike<any>, { strict, keySelector }?: UniqueListStatsOptions): {
|
|
42
|
+
values: any[];
|
|
43
|
+
count: number;
|
|
44
|
+
frequencies: Map<any, number>;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Options configuration for the `stepSliceList` utility.
|
|
48
|
+
*/
|
|
49
|
+
export interface StepSliceListOptions {
|
|
50
|
+
/**
|
|
51
|
+
* The step size to slice the list by. Cannot be zero.
|
|
52
|
+
* Positive values slice forward (left-to-right), negative values slice backward (right-to-left).
|
|
53
|
+
* @default 1
|
|
54
|
+
*/
|
|
55
|
+
step?: number;
|
|
56
|
+
/**
|
|
57
|
+
* The index to start slicing from (inclusive).
|
|
58
|
+
* Supports negative values to start relative to the end of the array.
|
|
59
|
+
* @default 0
|
|
60
|
+
*/
|
|
61
|
+
offsetStart?: number;
|
|
62
|
+
/**
|
|
63
|
+
* The index to end slicing at (exclusive).
|
|
64
|
+
* Supports negative values to end relative to the end of the array.
|
|
65
|
+
* Defaults to the end of the array (if step > 0) or -1 (if step < 0).
|
|
66
|
+
*/
|
|
67
|
+
offsetEnd?: number;
|
|
68
|
+
/**
|
|
69
|
+
* Caps the maximum number of items gathered in the sliced result list.
|
|
70
|
+
* If specified, the slicing process stops once this limit is reached.
|
|
71
|
+
*/
|
|
72
|
+
maxItemsGathered?: number;
|
|
73
|
+
/**
|
|
74
|
+
* If true, returns null when the starting offset is out of bounds.
|
|
75
|
+
* If false, throws an error when the starting offset is out of bounds.
|
|
76
|
+
* @default true
|
|
77
|
+
*/
|
|
78
|
+
null_on_oob?: boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare function stepSliceList<T>(arr: ArrayLike<T>, { step, offsetStart, offsetEnd, maxItemsGathered, null_on_oob }?: StepSliceListOptions): T[] | null;
|
|
81
|
+
/**
|
|
82
|
+
* Options configuration for the `joinList` utility.
|
|
83
|
+
*/
|
|
84
|
+
export interface JoinListOptions {
|
|
85
|
+
/**
|
|
86
|
+
* If true, nullish elements (null and undefined) are completely ignored during joining.
|
|
87
|
+
* If false (default), nullish elements are serialized as empty strings or custom `nullValue`.
|
|
88
|
+
* @default false
|
|
89
|
+
*/
|
|
90
|
+
ignoreNulls?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Custom string representation for nullish values.
|
|
93
|
+
* Only applied if `ignoreNulls` is false.
|
|
94
|
+
* @default ""
|
|
95
|
+
*/
|
|
96
|
+
nullValue?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Optional prefix string prepended to the final joined result.
|
|
99
|
+
* @default ""
|
|
100
|
+
*/
|
|
101
|
+
prefix?: string;
|
|
102
|
+
/**
|
|
103
|
+
* Optional suffix string appended to the final joined result.
|
|
104
|
+
* @default ""
|
|
105
|
+
*/
|
|
106
|
+
suffix?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Maximum number of list elements to join.
|
|
109
|
+
* If specified, elements beyond this limit are omitted and `truncationMarker` is appended.
|
|
110
|
+
*/
|
|
111
|
+
limit?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Custom placeholder string appended to the joined string when limit truncation occurs.
|
|
114
|
+
* Only applied if `limit` is specified and the list length exceeds it.
|
|
115
|
+
* @default "..."
|
|
116
|
+
*/
|
|
117
|
+
truncationMarker?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Callback function used to format each individual non-null element to a custom string representation.
|
|
120
|
+
*/
|
|
121
|
+
valueFormatter?: (val: any, index: number) => string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Joins the elements of an array-like structure into a string using a separator.
|
|
125
|
+
* Excludes nullish checks and formats nested arrays cleanly.
|
|
126
|
+
*/
|
|
127
|
+
export declare function joinList(arr: ArrayLike<any>, separator?: string, { ignoreNulls, nullValue, prefix, suffix, limit, truncationMarker, valueFormatter }?: JoinListOptions): string;
|
|
128
|
+
export interface FillSeqBaseOptions {
|
|
129
|
+
/**
|
|
130
|
+
* Type coercion helper applied to each generated value before writing.
|
|
131
|
+
*
|
|
132
|
+
* @param v The newly generated candidate value.
|
|
133
|
+
* @returns The coerced value to write to the array.
|
|
134
|
+
*/
|
|
135
|
+
coerce?: (v: any) => any;
|
|
136
|
+
/**
|
|
137
|
+
* Conditional predicate determining if a value should be replaced at a given index.
|
|
138
|
+
*
|
|
139
|
+
* @param v The original/current value at the target index.
|
|
140
|
+
* @param index The absolute index of the current element.
|
|
141
|
+
* @param array The entire target array.
|
|
142
|
+
* @returns True if the candidate value should overwrite the original value, false otherwise.
|
|
143
|
+
*/
|
|
144
|
+
condition?: (v: any, index: number, array: any[]) => boolean;
|
|
145
|
+
/**
|
|
146
|
+
* If true, iterates and populates in reverse (from startIndex down to endIndex).
|
|
147
|
+
* @default false
|
|
148
|
+
*/
|
|
149
|
+
reverse?: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* The index at which array iteration and writing begins.
|
|
152
|
+
* @default reverse ? length - 1 : 0
|
|
153
|
+
*/
|
|
154
|
+
startIndex?: number;
|
|
155
|
+
/**
|
|
156
|
+
* The exclusive boundary index at which iteration and writing stops.
|
|
157
|
+
* @default reverse ? -1 : length
|
|
158
|
+
*/
|
|
159
|
+
endIndex?: number;
|
|
160
|
+
}
|
|
161
|
+
export interface CumulativeStepContext {
|
|
162
|
+
/** The accumulated value returned by the step function from the previous stepped index. */
|
|
163
|
+
prev: any;
|
|
164
|
+
/** The relative iteration counter of the stepping process (starts at 1). */
|
|
165
|
+
index: number;
|
|
166
|
+
/** The original value at the current index in the target array. */
|
|
167
|
+
originalValue: any;
|
|
168
|
+
/** The absolute index of the current element in the parent array. */
|
|
169
|
+
absoluteIndex: number;
|
|
170
|
+
/** The entire target array being populated/modified. */
|
|
171
|
+
targetArray: any;
|
|
172
|
+
}
|
|
173
|
+
export interface IndependentStepContext {
|
|
174
|
+
/** The relative iteration counter of the generation process (starts at 0). */
|
|
175
|
+
index: number;
|
|
176
|
+
/** The static starting value passed to the sequence generator. */
|
|
177
|
+
initialValue: any;
|
|
178
|
+
/** The original value at the current index in the target array. */
|
|
179
|
+
originalValue: any;
|
|
180
|
+
/** The absolute index of the current element in the parent array. */
|
|
181
|
+
absoluteIndex: number;
|
|
182
|
+
/** The entire target array being populated/modified. */
|
|
183
|
+
targetArray: any;
|
|
184
|
+
}
|
|
185
|
+
export type FillSeqOptions = FillSeqBaseOptions & ({
|
|
186
|
+
mode: "constant";
|
|
187
|
+
step?: never;
|
|
188
|
+
} | {
|
|
189
|
+
mode?: "cumulative";
|
|
190
|
+
step?: number | ((context: CumulativeStepContext) => any);
|
|
191
|
+
} | {
|
|
192
|
+
mode: "independent";
|
|
193
|
+
step?: number | ((context: IndependentStepContext) => any);
|
|
194
|
+
});
|
|
195
|
+
export declare function fillSequence(targetArray: any, initialValue: any, options?: FillSeqOptions): void;
|