df-script 1.5.0 → 1.7.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.
Files changed (159) hide show
  1. package/README.md +125 -9
  2. package/dist/api.d.ts +3 -2
  3. package/dist/assets/index-DBhGK6Tp.css +1 -0
  4. package/dist/assets/index-DEJEV_tU.js +195 -0
  5. package/dist/columnExpressions/ColumnExpr.d.ts +14 -7
  6. package/dist/columnExpressions/ExprBase.d.ts +26 -12
  7. package/dist/columnExpressions/constants.d.ts +1 -0
  8. package/dist/columnExpressions/functions/all.d.ts +23 -0
  9. package/dist/columnExpressions/functions/coalesce.d.ts +31 -2
  10. package/dist/columnExpressions/functions/element.d.ts +26 -1
  11. package/dist/columnExpressions/functions/exclude.d.ts +24 -0
  12. package/dist/columnExpressions/functions/implode.d.ts +28 -0
  13. package/dist/columnExpressions/functions/lit.d.ts +27 -0
  14. package/dist/columnExpressions/functions/seq_range.d.ts +36 -0
  15. package/dist/columnExpressions/functions/struct.d.ts +31 -0
  16. package/dist/columnExpressions/functions/when.d.ts +38 -8
  17. package/dist/columnExpressions/index.d.ts +2 -1
  18. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +336 -2
  19. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +620 -10
  20. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +567 -0
  21. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +353 -0
  22. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +82 -0
  23. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +40 -0
  24. package/dist/columnExpressions/mixins/StringExpr.d.ts +658 -5
  25. package/dist/columnExpressions/mixins/StructExpr.d.ts +70 -0
  26. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +530 -4
  27. package/dist/columnExpressions/mixins/WindowExpr.d.ts +313 -2
  28. package/dist/columnExpressions/types.d.ts +2 -0
  29. package/dist/constants.d.ts +11 -0
  30. package/dist/dataframe/dataframe.d.ts +933 -3
  31. package/dist/dataframe/grouped/grouped.d.ts +41 -6
  32. package/dist/dataframe/types.d.ts +1 -0
  33. package/dist/dataframe/utils.d.ts +1 -0
  34. package/dist/datatypes/index.d.ts +3 -2
  35. package/dist/datatypes/types.d.ts +52 -7
  36. package/dist/exceptions/index.d.ts +23 -0
  37. package/dist/functions/concat.d.ts +50 -0
  38. package/dist/functions/read_csv.d.ts +9 -0
  39. package/dist/functions/read_json.d.ts +7 -2
  40. package/dist/index.html +17 -0
  41. package/dist/index.js +6 -6
  42. package/dist/index.mjs +6 -0
  43. package/dist/types.d.ts +51 -16
  44. package/dist/utils/{list.d.ts → array.d.ts} +68 -15
  45. package/dist/utils/binary.d.ts +3 -0
  46. package/dist/utils/csv.d.ts +1 -0
  47. package/dist/utils/date.d.ts +23 -54
  48. package/dist/utils/index.d.ts +3 -2
  49. package/dist/utils/json.d.ts +1 -0
  50. package/dist/utils/number.d.ts +15 -29
  51. package/dist/utils/object.d.ts +27 -0
  52. package/dist/utils/string.d.ts +15 -5
  53. package/package.json +18 -4
  54. package/dist/api.js +0 -26
  55. package/dist/bundle.min.js +0 -1
  56. package/dist/columnExpressions/ColumnExpr.js +0 -219
  57. package/dist/columnExpressions/ExprBase.js +0 -92
  58. package/dist/columnExpressions/constants.js +0 -7
  59. package/dist/columnExpressions/functions/all.js +0 -11
  60. package/dist/columnExpressions/functions/coalesce.js +0 -44
  61. package/dist/columnExpressions/functions/element.js +0 -11
  62. package/dist/columnExpressions/functions/exclude.js +0 -13
  63. package/dist/columnExpressions/functions/implode.js +0 -7
  64. package/dist/columnExpressions/functions/lit.js +0 -17
  65. package/dist/columnExpressions/functions/repeat.d.ts +0 -47
  66. package/dist/columnExpressions/functions/repeat.js +0 -131
  67. package/dist/columnExpressions/functions/seq_range.js +0 -91
  68. package/dist/columnExpressions/functions/when.js +0 -85
  69. package/dist/columnExpressions/index.js +0 -38
  70. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -76
  71. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -131
  72. package/dist/columnExpressions/mixins/BooleanExpr.d.ts +0 -40
  73. package/dist/columnExpressions/mixins/BooleanExpr.js +0 -67
  74. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -250
  75. package/dist/columnExpressions/mixins/ListExpr.d.ts +0 -39
  76. package/dist/columnExpressions/mixins/ListExpr.js +0 -224
  77. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -53
  78. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -71
  79. package/dist/columnExpressions/mixins/NumericExpr.d.ts +0 -92
  80. package/dist/columnExpressions/mixins/NumericExpr.js +0 -259
  81. package/dist/columnExpressions/mixins/StringExpr.js +0 -237
  82. package/dist/columnExpressions/mixins/StructExpr.js +0 -139
  83. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -126
  84. package/dist/columnExpressions/mixins/WindowExpr.js +0 -151
  85. package/dist/columnExpressions/types.js +0 -2
  86. package/dist/columnExpressions/utils.js +0 -45
  87. package/dist/dataframe/constants.js +0 -7
  88. package/dist/dataframe/dataframe.js +0 -990
  89. package/dist/dataframe/grouped/grouped.js +0 -114
  90. package/dist/dataframe/index.js +0 -20
  91. package/dist/dataframe/types.js +0 -2
  92. package/dist/dataframe/utils.js +0 -307
  93. package/dist/datatypes/DataType.js +0 -76
  94. package/dist/datatypes/index.js +0 -46
  95. package/dist/datatypes/types/Binary.d.ts +0 -9
  96. package/dist/datatypes/types/Binary.js +0 -18
  97. package/dist/datatypes/types/Boolean.d.ts +0 -9
  98. package/dist/datatypes/types/Boolean.js +0 -19
  99. package/dist/datatypes/types/Date.d.ts +0 -8
  100. package/dist/datatypes/types/Date.js +0 -21
  101. package/dist/datatypes/types/Datetime.d.ts +0 -8
  102. package/dist/datatypes/types/Datetime.js +0 -17
  103. package/dist/datatypes/types/Decimal.d.ts +0 -10
  104. package/dist/datatypes/types/Decimal.js +0 -28
  105. package/dist/datatypes/types/Duration.d.ts +0 -8
  106. package/dist/datatypes/types/Duration.js +0 -17
  107. package/dist/datatypes/types/Float32.d.ts +0 -8
  108. package/dist/datatypes/types/Float32.js +0 -17
  109. package/dist/datatypes/types/Float64.d.ts +0 -8
  110. package/dist/datatypes/types/Float64.js +0 -17
  111. package/dist/datatypes/types/Int16.d.ts +0 -8
  112. package/dist/datatypes/types/Int16.js +0 -17
  113. package/dist/datatypes/types/Int32.d.ts +0 -8
  114. package/dist/datatypes/types/Int32.js +0 -17
  115. package/dist/datatypes/types/Int64.d.ts +0 -8
  116. package/dist/datatypes/types/Int64.js +0 -17
  117. package/dist/datatypes/types/Int8.d.ts +0 -8
  118. package/dist/datatypes/types/Int8.js +0 -17
  119. package/dist/datatypes/types/List.d.ts +0 -10
  120. package/dist/datatypes/types/List.js +0 -31
  121. package/dist/datatypes/types/Null.d.ts +0 -9
  122. package/dist/datatypes/types/Null.js +0 -17
  123. package/dist/datatypes/types/Object.d.ts +0 -9
  124. package/dist/datatypes/types/Object.js +0 -17
  125. package/dist/datatypes/types/Struct.d.ts +0 -14
  126. package/dist/datatypes/types/Struct.js +0 -39
  127. package/dist/datatypes/types/Time.d.ts +0 -8
  128. package/dist/datatypes/types/Time.js +0 -29
  129. package/dist/datatypes/types/UInt16.d.ts +0 -8
  130. package/dist/datatypes/types/UInt16.js +0 -17
  131. package/dist/datatypes/types/UInt32.d.ts +0 -8
  132. package/dist/datatypes/types/UInt32.js +0 -17
  133. package/dist/datatypes/types/UInt64.d.ts +0 -8
  134. package/dist/datatypes/types/UInt64.js +0 -17
  135. package/dist/datatypes/types/UInt8.d.ts +0 -8
  136. package/dist/datatypes/types/UInt8.js +0 -17
  137. package/dist/datatypes/types/Utf8.d.ts +0 -10
  138. package/dist/datatypes/types/Utf8.js +0 -20
  139. package/dist/datatypes/types.js +0 -290
  140. package/dist/exceptions/index.js +0 -46
  141. package/dist/exceptions/utils.js +0 -28
  142. package/dist/functions/concat.js +0 -260
  143. package/dist/functions/index.js +0 -9
  144. package/dist/functions/read_csv.js +0 -53
  145. package/dist/functions/read_json.js +0 -21
  146. package/dist/functions/transpose.d.ts +0 -7
  147. package/dist/functions/transpose.js +0 -84
  148. package/dist/types.js +0 -2
  149. package/dist/utils/boolean.d.ts +0 -1
  150. package/dist/utils/boolean.js +0 -18
  151. package/dist/utils/csv.js +0 -313
  152. package/dist/utils/date.js +0 -348
  153. package/dist/utils/guards.d.ts +0 -12
  154. package/dist/utils/guards.js +0 -112
  155. package/dist/utils/index.js +0 -23
  156. package/dist/utils/json.js +0 -217
  157. package/dist/utils/list.js +0 -361
  158. package/dist/utils/number.js +0 -401
  159. package/dist/utils/string.js +0 -209
@@ -1,217 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isJsonString = isJsonString;
4
- exports.safeJsonParse = safeJsonParse;
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)
13
- return false;
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++;
23
- }
24
- let last = len - 1;
25
- while (last >= first && /\s/.test(str[last])) {
26
- last--;
27
- }
28
- if (first >= last)
29
- return false;
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 = {}) {
43
- if (typeof input !== "string")
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;
71
- try {
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
- }
122
- }
123
- catch (err) {
124
- onError?.(err);
125
- return fallback !== NO_FALLBACK ? fallback : input;
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
- };
217
- }
@@ -1,361 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toValidArray = toValidArray;
4
- exports.toValidStringArray = toValidStringArray;
5
- exports.isArrayOfType = isArrayOfType;
6
- exports.sortList = sortList;
7
- exports.getListStats = getListStats;
8
- exports.getUniqueListStats = getUniqueListStats;
9
- exports.stepSliceList = stepSliceList;
10
- exports.joinList = joinList;
11
- exports.fillSequence = fillSequence;
12
- const guards_1 = require("./guards");
13
- const date_1 = require("./date");
14
- const number_1 = require("./number");
15
- const string_1 = require("./string");
16
- function toValidArray(val) {
17
- if (val == null)
18
- return [];
19
- if (Array.isArray(val))
20
- return [...val];
21
- if ((0, guards_1.isTypedArray)(val))
22
- return Array.from(val);
23
- return [val];
24
- }
25
- function toValidStringArray(val) {
26
- const arr = toValidArray(val);
27
- const len = arr.length;
28
- const res = new Array(len);
29
- for (let i = 0; i < len; i++) {
30
- res[i] = String(arr[i]);
31
- }
32
- return res;
33
- }
34
- function isArrayOfType(arr, type, { mode = "every", allowNulls = false, allowEmpty = true } = {}) {
35
- if (!(0, guards_1.isArrayOrTypedArray)(arr))
36
- return false;
37
- const len = arr.length;
38
- if (len === 0) {
39
- if (!allowEmpty)
40
- return false;
41
- return mode === "every";
42
- }
43
- const list = arr;
44
- let check;
45
- if (typeof type === "function") {
46
- const isC = (0, guards_1.isClass)(type);
47
- check = isC
48
- ? (v) => v instanceof type
49
- : type;
50
- }
51
- else {
52
- switch (type) {
53
- case "null":
54
- check = (v) => v === null;
55
- break;
56
- case "undefined":
57
- check = (v) => v === undefined;
58
- break;
59
- case "nullish":
60
- check = (v) => v == null;
61
- break;
62
- case "any":
63
- check = () => true;
64
- break;
65
- case "date":
66
- check = date_1.isValidDateObj;
67
- break;
68
- case "object":
69
- check = guards_1.isObj;
70
- break;
71
- case "plainObject":
72
- check = guards_1.isPlainObj;
73
- break;
74
- case "number":
75
- check = number_1.isValidNumber;
76
- break;
77
- default:
78
- check = (v) => typeof v === type;
79
- break;
80
- }
81
- }
82
- if (allowNulls) {
83
- const baseCheck = check;
84
- check = (v) => v == null || baseCheck(v);
85
- }
86
- if (mode === "every") {
87
- for (let i = 0; i < len; i++) {
88
- if (!check(list[i]))
89
- return false;
90
- }
91
- return true;
92
- }
93
- else {
94
- for (let i = 0; i < len; i++) {
95
- if (check(list[i]))
96
- return true;
97
- }
98
- return false;
99
- }
100
- }
101
- function sortList(arr, descending = false) {
102
- if (!(0, guards_1.isArrayOrTypedArray)(arr))
103
- return [];
104
- const list = Array.from(arr);
105
- list.sort((a, b) => {
106
- if (a == null && b == null)
107
- return 0;
108
- if (a == null)
109
- return 1;
110
- if (b == null)
111
- return -1;
112
- if (a < b)
113
- return descending ? 1 : -1;
114
- if (a > b)
115
- return descending ? -1 : 1;
116
- return 0;
117
- });
118
- return list;
119
- }
120
- const DEFAULT_STATS = { sum: null, count: 0, min: null, max: null, mean: null, variance: 0, std: 0, nullCount: 0, len: 0, hasNulls: false, isNumeric: false };
121
- function getListStats(arr) {
122
- if (!(0, guards_1.isArrayOrTypedArray)(arr)) {
123
- return { ...DEFAULT_STATS };
124
- }
125
- const len = arr.length;
126
- if (len === 0) {
127
- return { ...DEFAULT_STATS };
128
- }
129
- let minVal = null;
130
- let maxVal = null;
131
- let count = 0;
132
- let nullCount = 0;
133
- let total = 0;
134
- let sumCompensation = 0;
135
- let mean = 0;
136
- let M2 = 0;
137
- for (let i = 0; i < len; i++) {
138
- const val = arr[i];
139
- if (val == null) {
140
- nullCount++;
141
- continue;
142
- }
143
- if (minVal == null || val < minVal)
144
- minVal = val;
145
- if (maxVal == null || val > maxVal)
146
- maxVal = val;
147
- const n = (0, number_1.toValidNumber)(val);
148
- if (n !== null) {
149
- // Neumaier sum
150
- const t = total + n;
151
- if (Math.abs(total) >= Math.abs(n)) {
152
- sumCompensation += (total - t) + n;
153
- }
154
- else {
155
- sumCompensation += (n - t) + total;
156
- }
157
- total = t;
158
- count++;
159
- const delta = n - mean;
160
- mean += delta / count;
161
- const delta2 = n - mean;
162
- M2 += delta * delta2;
163
- }
164
- }
165
- const variance = count > 1 ? M2 / (count - 1) : 0;
166
- return {
167
- sum: count > 0 ? total + sumCompensation : null,
168
- count,
169
- min: minVal,
170
- max: maxVal,
171
- mean: count > 0 ? (total + sumCompensation) / count : null,
172
- variance,
173
- std: Math.sqrt(variance),
174
- nullCount,
175
- len,
176
- hasNulls: nullCount > 0,
177
- isNumeric: count > 0 && count === (len - nullCount)
178
- };
179
- }
180
- function getUniqueListStats(arr, { strict = false, keySelector } = {}) {
181
- const list = Array.from(arr);
182
- const frequencies = new Map();
183
- if (strict) {
184
- const selector = keySelector ?? string_1.toCanonicalString;
185
- const seen = new Map();
186
- const len = list.length;
187
- for (let i = 0; i < len; i++) {
188
- const val = list[i];
189
- const key = selector(val);
190
- const entry = seen.get(key);
191
- if (entry === undefined) {
192
- seen.set(key, { val, count: 1 });
193
- }
194
- else {
195
- entry.count++;
196
- }
197
- }
198
- const values = [];
199
- for (const entry of seen.values()) {
200
- values.push(entry.val);
201
- }
202
- for (let i = 0; i < len; i++) {
203
- const val = list[i];
204
- const key = selector(val);
205
- const entry = seen.get(key);
206
- frequencies.set(val, entry.count);
207
- }
208
- return {
209
- values,
210
- count: values.length,
211
- frequencies
212
- };
213
- }
214
- const len = list.length;
215
- for (let i = 0; i < len; i++) {
216
- const val = list[i];
217
- frequencies.set(val, (frequencies.get(val) ?? 0) + 1);
218
- }
219
- return {
220
- values: Array.from(frequencies.keys()),
221
- count: frequencies.size,
222
- frequencies
223
- };
224
- }
225
- function stepSliceList(arr, { step = 1, offsetStart = 0, offsetEnd, maxItemsGathered, null_on_oob = true } = {}) {
226
- if (arr == null) {
227
- return null;
228
- }
229
- if (maxItemsGathered !== undefined && maxItemsGathered <= 0) {
230
- return [];
231
- }
232
- if (step === 0) {
233
- throw new Error("Step size step cannot be zero");
234
- }
235
- const len = arr.length;
236
- const isOob = len === 0
237
- ? (offsetStart !== 0)
238
- : (offsetStart >= len || offsetStart < -len);
239
- if (isOob) {
240
- if (!null_on_oob) {
241
- throw new Error(`Start offset ${offsetStart} is out of bounds for list of length ${len}`);
242
- }
243
- return null;
244
- }
245
- const start = offsetStart < 0 ? len + offsetStart : offsetStart;
246
- const end = offsetEnd !== undefined
247
- ? (offsetEnd < 0 ? len + offsetEnd : offsetEnd)
248
- : (step > 0 ? len : -1);
249
- const res = [];
250
- if (step > 0) {
251
- for (let i = start; i < end && i < len; i += step) {
252
- if (i >= 0) {
253
- res.push(arr[i]);
254
- if (maxItemsGathered !== undefined && res.length >= maxItemsGathered) {
255
- break;
256
- }
257
- }
258
- }
259
- }
260
- else {
261
- for (let i = start; i > end && i >= 0; i += step) {
262
- if (i < len) {
263
- res.push(arr[i]);
264
- if (maxItemsGathered !== undefined && res.length >= maxItemsGathered) {
265
- break;
266
- }
267
- }
268
- }
269
- }
270
- return res;
271
- }
272
- /**
273
- * Joins the elements of an array-like structure into a string using a separator.
274
- * Excludes nullish checks and formats nested arrays cleanly.
275
- */
276
- function joinList(arr, separator = ",", { ignoreNulls = false, nullValue = "", prefix = "", suffix = "", limit, truncationMarker = "...", valueFormatter } = {}) {
277
- const len = arr.length;
278
- const strList = [];
279
- const maxLimit = limit !== undefined ? Math.max(0, limit) : len;
280
- let truncated = false;
281
- for (let i = 0; i < len; i++) {
282
- if (strList.length >= maxLimit) {
283
- truncated = true;
284
- break;
285
- }
286
- const x = arr[i];
287
- if (x != null) {
288
- strList.push(valueFormatter ? valueFormatter(x, i) : String(x));
289
- }
290
- else if (!ignoreNulls) {
291
- strList.push(nullValue);
292
- }
293
- }
294
- return prefix + strList.join(separator) + (truncated ? truncationMarker : "") + suffix;
295
- }
296
- function fillSequence(targetArray, initialValue, options = {}) {
297
- const len = targetArray.length;
298
- const { mode = "cumulative", step = 1, coerce = (v) => v, condition, reverse = false, startIndex = reverse ? len - 1 : 0, endIndex = reverse ? -1 : len } = options;
299
- const increment = reverse ? -1 : 1;
300
- const start = startIndex;
301
- const end = endIndex;
302
- const writeVal = (idx, val) => {
303
- if (!condition || condition(targetArray[idx], idx, targetArray)) {
304
- targetArray[idx] = coerce(val);
305
- }
306
- };
307
- if (mode === "constant") {
308
- const finalVal = coerce(initialValue);
309
- for (let i = start; reverse ? i > end : i < end; i += increment) {
310
- writeVal(i, finalVal);
311
- }
312
- }
313
- else if (mode === "independent") {
314
- if (typeof step === "function") {
315
- let relativeIdx = 0;
316
- for (let i = start; reverse ? i > end : i < end; i += increment) {
317
- writeVal(i, step({
318
- index: relativeIdx,
319
- initialValue,
320
- originalValue: targetArray[i],
321
- absoluteIndex: i,
322
- targetArray
323
- }));
324
- relativeIdx++;
325
- }
326
- }
327
- else {
328
- for (let i = start; reverse ? i > end : i < end; i += increment) {
329
- writeVal(i, initialValue + i * step);
330
- }
331
- }
332
- }
333
- else {
334
- // cumulative mode
335
- let current = initialValue;
336
- let isFirst = true;
337
- let relativeIdx = 0;
338
- for (let i = start; reverse ? i > end : i < end; i += increment) {
339
- if (isFirst) {
340
- writeVal(i, current);
341
- isFirst = false;
342
- }
343
- else {
344
- if (typeof step === "function") {
345
- current = step({
346
- prev: current,
347
- index: relativeIdx,
348
- originalValue: targetArray[i],
349
- absoluteIndex: i,
350
- targetArray
351
- });
352
- }
353
- else {
354
- current = current + step;
355
- }
356
- writeVal(i, current);
357
- }
358
- relativeIdx++;
359
- }
360
- }
361
- }