df-script 1.4.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 (134) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +269 -0
  3. package/dist/api.d.ts +39 -0
  4. package/dist/api.js +18 -0
  5. package/dist/bundle.min.js +1 -0
  6. package/dist/columnExpressions/ColumnExpr.d.ts +368 -0
  7. package/dist/columnExpressions/ColumnExpr.js +23 -0
  8. package/dist/columnExpressions/ExprBase.d.ts +24 -0
  9. package/dist/columnExpressions/ExprBase.js +133 -0
  10. package/dist/columnExpressions/constants.d.ts +2 -0
  11. package/dist/columnExpressions/constants.js +5 -0
  12. package/dist/columnExpressions/functions/all.d.ts +5 -0
  13. package/dist/columnExpressions/functions/all.js +11 -0
  14. package/dist/columnExpressions/functions/coalesce.d.ts +3 -0
  15. package/dist/columnExpressions/functions/coalesce.js +40 -0
  16. package/dist/columnExpressions/functions/exclude.d.ts +5 -0
  17. package/dist/columnExpressions/functions/exclude.js +13 -0
  18. package/dist/columnExpressions/functions/lit.d.ts +5 -0
  19. package/dist/columnExpressions/functions/lit.js +22 -0
  20. package/dist/columnExpressions/functions/when.d.ts +24 -0
  21. package/dist/columnExpressions/functions/when.js +81 -0
  22. package/dist/columnExpressions/index.d.ts +19 -0
  23. package/dist/columnExpressions/index.js +81 -0
  24. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +50 -0
  25. package/dist/columnExpressions/mixins/AggregationExpr.js +172 -0
  26. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +67 -0
  27. package/dist/columnExpressions/mixins/ArithmeticExpr.js +143 -0
  28. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +60 -0
  29. package/dist/columnExpressions/mixins/ComparisonExpr.js +389 -0
  30. package/dist/columnExpressions/mixins/ListExpr.d.ts +63 -0
  31. package/dist/columnExpressions/mixins/ListExpr.js +248 -0
  32. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +33 -0
  33. package/dist/columnExpressions/mixins/LogicalExpr.js +54 -0
  34. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +31 -0
  35. package/dist/columnExpressions/mixins/ManipulationExpr.js +35 -0
  36. package/dist/columnExpressions/mixins/StringExpr.d.ts +79 -0
  37. package/dist/columnExpressions/mixins/StringExpr.js +249 -0
  38. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +69 -0
  39. package/dist/columnExpressions/mixins/TemporalExpr.js +127 -0
  40. package/dist/columnExpressions/mixins/WindowExpr.d.ts +50 -0
  41. package/dist/columnExpressions/mixins/WindowExpr.js +281 -0
  42. package/dist/columnExpressions/types.d.ts +7 -0
  43. package/dist/columnExpressions/types.js +2 -0
  44. package/dist/dataframe/constants.d.ts +1 -0
  45. package/dist/dataframe/constants.js +4 -0
  46. package/dist/dataframe/dataframe.d.ts +42 -0
  47. package/dist/dataframe/dataframe.js +749 -0
  48. package/dist/dataframe/grouped/grouped.d.ts +15 -0
  49. package/dist/dataframe/grouped/grouped.js +113 -0
  50. package/dist/dataframe/index.d.ts +4 -0
  51. package/dist/dataframe/index.js +20 -0
  52. package/dist/dataframe/types.d.ts +33 -0
  53. package/dist/dataframe/types.js +2 -0
  54. package/dist/dataframe/utils.d.ts +11 -0
  55. package/dist/dataframe/utils.js +215 -0
  56. package/dist/datatypes/DataType.d.ts +40 -0
  57. package/dist/datatypes/DataType.js +47 -0
  58. package/dist/datatypes/index.d.ts +29 -0
  59. package/dist/datatypes/index.js +46 -0
  60. package/dist/datatypes/types/Binary.d.ts +9 -0
  61. package/dist/datatypes/types/Binary.js +18 -0
  62. package/dist/datatypes/types/Boolean.d.ts +9 -0
  63. package/dist/datatypes/types/Boolean.js +19 -0
  64. package/dist/datatypes/types/Date.d.ts +8 -0
  65. package/dist/datatypes/types/Date.js +21 -0
  66. package/dist/datatypes/types/Datetime.d.ts +8 -0
  67. package/dist/datatypes/types/Datetime.js +17 -0
  68. package/dist/datatypes/types/Decimal.d.ts +10 -0
  69. package/dist/datatypes/types/Decimal.js +28 -0
  70. package/dist/datatypes/types/Duration.d.ts +8 -0
  71. package/dist/datatypes/types/Duration.js +17 -0
  72. package/dist/datatypes/types/Float32.d.ts +8 -0
  73. package/dist/datatypes/types/Float32.js +17 -0
  74. package/dist/datatypes/types/Float64.d.ts +8 -0
  75. package/dist/datatypes/types/Float64.js +17 -0
  76. package/dist/datatypes/types/Int16.d.ts +8 -0
  77. package/dist/datatypes/types/Int16.js +17 -0
  78. package/dist/datatypes/types/Int32.d.ts +8 -0
  79. package/dist/datatypes/types/Int32.js +17 -0
  80. package/dist/datatypes/types/Int64.d.ts +8 -0
  81. package/dist/datatypes/types/Int64.js +17 -0
  82. package/dist/datatypes/types/Int8.d.ts +8 -0
  83. package/dist/datatypes/types/Int8.js +17 -0
  84. package/dist/datatypes/types/List.d.ts +10 -0
  85. package/dist/datatypes/types/List.js +31 -0
  86. package/dist/datatypes/types/Null.d.ts +9 -0
  87. package/dist/datatypes/types/Null.js +17 -0
  88. package/dist/datatypes/types/Object.d.ts +9 -0
  89. package/dist/datatypes/types/Object.js +17 -0
  90. package/dist/datatypes/types/Struct.d.ts +14 -0
  91. package/dist/datatypes/types/Struct.js +39 -0
  92. package/dist/datatypes/types/Time.d.ts +8 -0
  93. package/dist/datatypes/types/Time.js +29 -0
  94. package/dist/datatypes/types/UInt16.d.ts +8 -0
  95. package/dist/datatypes/types/UInt16.js +17 -0
  96. package/dist/datatypes/types/UInt32.d.ts +8 -0
  97. package/dist/datatypes/types/UInt32.js +17 -0
  98. package/dist/datatypes/types/UInt64.d.ts +8 -0
  99. package/dist/datatypes/types/UInt64.js +17 -0
  100. package/dist/datatypes/types/UInt8.d.ts +8 -0
  101. package/dist/datatypes/types/UInt8.js +17 -0
  102. package/dist/datatypes/types/Utf8.d.ts +10 -0
  103. package/dist/datatypes/types/Utf8.js +20 -0
  104. package/dist/datatypes/types.d.ts +172 -0
  105. package/dist/datatypes/types.js +286 -0
  106. package/dist/exceptions/index.d.ts +13 -0
  107. package/dist/exceptions/index.js +43 -0
  108. package/dist/exceptions/utils.d.ts +2 -0
  109. package/dist/exceptions/utils.js +9 -0
  110. package/dist/functions/concat.d.ts +4 -0
  111. package/dist/functions/concat.js +248 -0
  112. package/dist/functions/index.d.ts +1 -0
  113. package/dist/functions/index.js +17 -0
  114. package/dist/index.d.ts +7 -0
  115. package/dist/index.js +1 -0
  116. package/dist/types.d.ts +47 -0
  117. package/dist/types.js +2 -0
  118. package/dist/utils/boolean.d.ts +1 -0
  119. package/dist/utils/boolean.js +18 -0
  120. package/dist/utils/date.d.ts +57 -0
  121. package/dist/utils/date.js +349 -0
  122. package/dist/utils/guards.d.ts +14 -0
  123. package/dist/utils/guards.js +143 -0
  124. package/dist/utils/index.d.ts +5 -0
  125. package/dist/utils/index.js +21 -0
  126. package/dist/utils/json.d.ts +2 -0
  127. package/dist/utils/json.js +33 -0
  128. package/dist/utils/list.d.ts +23 -0
  129. package/dist/utils/list.js +128 -0
  130. package/dist/utils/number.d.ts +86 -0
  131. package/dist/utils/number.js +223 -0
  132. package/dist/utils/string.d.ts +52 -0
  133. package/dist/utils/string.js +120 -0
  134. package/package.json +34 -0
@@ -0,0 +1,349 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STRFTIME_DIRECTIVES = exports.NS_PER_MS = exports.US_PER_MS = exports.MS_PER_DAY = exports.MS_PER_HOUR = exports.MS_PER_MINUTE = exports.MS_PER_SECOND = exports.UTC_INDICATOR_REGEX = exports.ZONE_OFFSET_REGEX = exports.TIME_PREFIX_REGEX = void 0;
4
+ exports.toEpoch = toEpoch;
5
+ exports.getCentury = getCentury;
6
+ exports.getISOWeek = getISOWeek;
7
+ exports.getMillennium = getMillennium;
8
+ exports.getMonthOffset = getMonthOffset;
9
+ exports.getOrdinalDay = getOrdinalDay;
10
+ exports.getQuarter = getQuarter;
11
+ exports.getUtcOffset = getUtcOffset;
12
+ exports.isLeapYear = isLeapYear;
13
+ exports.isUtcString = isUtcString;
14
+ exports.isValidDate = isValidDate;
15
+ exports.isValidDateObj = isValidDateObj;
16
+ exports.normalizeEpochToMs = normalizeEpochToMs;
17
+ exports.strftime = strftime;
18
+ exports.strptime = strptime;
19
+ exports.toValidDate = toValidDate;
20
+ const number_1 = require("./number");
21
+ /**
22
+ * Matches string values beginning with standard hour-and-minute formatting.
23
+ * Examples:
24
+ * - "12:34" (matches "12:34")
25
+ * - "10:37:16.123" (matches "10:37")
26
+ * - "2026-05-25" (does not match)
27
+ */
28
+ exports.TIME_PREFIX_REGEX = /^\d{2}:\d{2}/;
29
+ /**
30
+ * Matches timezone offset indicators at the end of a string.
31
+ * Examples:
32
+ * - "12:34:56Z" (matches "Z")
33
+ * - "12:34:56+02:00" (matches "+02:00")
34
+ * - "12:34:56-0500" (matches "-0500")
35
+ * - "12:34:56-05" (matches "-05")
36
+ * - "12:34:56" (does not match)
37
+ */
38
+ exports.ZONE_OFFSET_REGEX = /(?:Z|[+-]\d{2}(?::?\d{2})?)$/i;
39
+ /**
40
+ * Matches only UTC offset indicators at the end of a string.
41
+ * Examples:
42
+ * - "12:34:56Z" (matches "Z")
43
+ * - "12:34:56+00:00" (matches "+00:00")
44
+ * - "12:34:56-0000" (matches "-0000")
45
+ * - "12:34:56+02:00" (does not match)
46
+ */
47
+ exports.UTC_INDICATOR_REGEX = /(?:Z|[+-]00:00|[+-]0000|[+-]00)$/i;
48
+ exports.MS_PER_SECOND = 1000;
49
+ exports.MS_PER_MINUTE = 60_000;
50
+ exports.MS_PER_HOUR = 3_600_000;
51
+ exports.MS_PER_DAY = 86_400_000;
52
+ exports.US_PER_MS = 1000;
53
+ exports.NS_PER_MS = 1_000_000;
54
+ function toEpoch(d, unit = "ms") {
55
+ const ms = d.getTime();
56
+ switch (unit) {
57
+ case "s": return Math.floor(ms / exports.MS_PER_SECOND);
58
+ case "ms": return ms;
59
+ case "us": return ms * exports.US_PER_MS;
60
+ case "ns": return ms * exports.NS_PER_MS;
61
+ }
62
+ }
63
+ function getCentury(d) {
64
+ const y = d.getUTCFullYear();
65
+ return Math.floor((y - 1) / 100) + 1;
66
+ }
67
+ function getISOWeek(d) {
68
+ const date = new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDate()));
69
+ const dayNum = date.getUTCDay() || 7;
70
+ date.setUTCDate(date.getUTCDate() + 4 - dayNum);
71
+ const yearStart = new Date(Date.UTC(date.getUTCFullYear(), 0, 1));
72
+ return Math.ceil((((date.getTime() - yearStart.getTime()) / exports.MS_PER_DAY) + 1) / 7);
73
+ }
74
+ function getMillennium(d) {
75
+ const y = d.getUTCFullYear();
76
+ return Math.floor((y - 1) / 1000) + 1;
77
+ }
78
+ function getMonthOffset(d, monthOffset, day = 1) {
79
+ return new Date(Date.UTC(d.getUTCFullYear(), d.getUTCMonth() + monthOffset, day, 0, 0, 0, 0));
80
+ }
81
+ function getOrdinalDay(d) {
82
+ const start = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
83
+ const diff = d.getTime() - start.getTime();
84
+ return Math.floor(diff / exports.MS_PER_DAY) + 1;
85
+ }
86
+ function getQuarter(d) {
87
+ return Math.floor(d.getUTCMonth() / 3) + 1;
88
+ }
89
+ function getUtcOffset(timeZone) {
90
+ const now = new Date();
91
+ const utcMs = now.getTime() + now.getTimezoneOffset() * 60_000;
92
+ const tzTime = new Date(now.toLocaleString('en-US', { timeZone }));
93
+ const tzMs = tzTime.getTime();
94
+ const offsetMin = Math.round((tzMs - utcMs) / 60_000);
95
+ const sign = offsetMin >= 0 ? "+" : "\u2212";
96
+ const h = Math.floor(Math.abs(offsetMin) / 60);
97
+ const m = Math.abs(offsetMin) % 60;
98
+ const formatted = `UTC${sign}${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}`;
99
+ return {
100
+ timeZoneTime: tzTime,
101
+ utcTime: now,
102
+ offset: offsetMin,
103
+ formatted
104
+ };
105
+ }
106
+ function isLeapYear(yOrDate) {
107
+ const y = yOrDate instanceof Date ? yOrDate.getUTCFullYear() : yOrDate;
108
+ return (y % 4 === 0 && y % 100 !== 0) || y % 400 === 0;
109
+ }
110
+ function isUtcString(timestamp) {
111
+ if (!timestamp)
112
+ return false;
113
+ const trimmed = timestamp.trim();
114
+ if (!trimmed)
115
+ return false;
116
+ return exports.UTC_INDICATOR_REGEX.test(trimmed);
117
+ }
118
+ function isValidDate(v) {
119
+ if (v == null)
120
+ return false;
121
+ if (v instanceof Date)
122
+ return isValidDateObj(v);
123
+ if (typeof v === "number") {
124
+ if (!(0, number_1.isValidNumber)(v))
125
+ return false;
126
+ return isValidDateObj(new Date(normalizeEpochToMs(v)));
127
+ }
128
+ if (typeof v === "bigint") {
129
+ return isValidDateObj(new Date(normalizeEpochToMs(Number(v))));
130
+ }
131
+ if (typeof v === "string") {
132
+ const s = v.trim();
133
+ if (s === "")
134
+ return false;
135
+ return isValidDateObj(new Date(s));
136
+ }
137
+ return false;
138
+ }
139
+ function isValidDateObj(d) {
140
+ return d instanceof Date && !Number.isNaN(d.getTime());
141
+ }
142
+ function normalizeEpochToMs(n) {
143
+ const abs = Math.abs(n);
144
+ if (abs >= 1e12)
145
+ return n;
146
+ if (abs <= 1e10)
147
+ return n * 1000;
148
+ return n;
149
+ }
150
+ exports.STRFTIME_DIRECTIVES = [
151
+ "%ms", "%f", "%Y", "%y", "%m", "%d", "%e", "%H", "%I", "%p", "%M", "%S", "%A", "%a", "%B", "%b", "%h", "%j", "%u", "%w", "%Z", "%z"
152
+ ];
153
+ function strftime(d, format, locale) {
154
+ let result = format;
155
+ // 1. Literal %% escaping
156
+ result = result.replace(/%%/g, "\0");
157
+ // 2. High-level shorthand formats
158
+ result = result.replace(/%F/g, "%Y-%m-%d");
159
+ result = result.replace(/%T/g, "%H:%M:%S");
160
+ result = result.replace(/%R/g, "%H:%M");
161
+ result = result.replace(/%D/g, "%m/%d/%y");
162
+ // 3. Directives replacements with lazy getters
163
+ const replacements = {
164
+ get "%Y"() { return String(d.getUTCFullYear()); },
165
+ get "%y"() { return String(d.getUTCFullYear() % 100).padStart(2, "0"); },
166
+ get "%m"() { return String(d.getUTCMonth() + 1).padStart(2, "0"); },
167
+ get "%d"() { return String(d.getUTCDate()).padStart(2, "0"); },
168
+ get "%e"() { return String(d.getUTCDate()).padStart(2, " "); },
169
+ get "%H"() { return String(d.getUTCHours()).padStart(2, "0"); },
170
+ get "%I"() { return String(d.getUTCHours() % 12 || 12).padStart(2, "0"); },
171
+ get "%p"() { return d.getUTCHours() >= 12 ? "PM" : "AM"; },
172
+ get "%M"() { return String(d.getUTCMinutes()).padStart(2, "0"); },
173
+ get "%S"() { return String(d.getUTCSeconds()).padStart(2, "0"); },
174
+ get "%A"() { return d.toLocaleDateString(locale, { weekday: "long", timeZone: "UTC" }); },
175
+ get "%a"() { return d.toLocaleDateString(locale, { weekday: "short", timeZone: "UTC" }); },
176
+ get "%B"() { return d.toLocaleDateString(locale, { month: "long", timeZone: "UTC" }); },
177
+ get "%b"() { return d.toLocaleDateString(locale, { month: "short", timeZone: "UTC" }); },
178
+ get "%h"() { return d.toLocaleDateString(locale, { month: "short", timeZone: "UTC" }); },
179
+ get "%j"() {
180
+ const start = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
181
+ const diff = d.getTime() - start.getTime();
182
+ const dayOfYear = Math.floor(diff / exports.MS_PER_DAY) + 1;
183
+ return String(dayOfYear).padStart(3, "0");
184
+ },
185
+ get "%u"() { return String(d.getUTCDay() || 7); },
186
+ get "%w"() { return String(d.getUTCDay()); },
187
+ get "%Z"() { return "UTC"; },
188
+ get "%z"() { return "+0000"; },
189
+ get "%ms"() { return String(d.getUTCMilliseconds()).padStart(3, "0"); },
190
+ get "%f"() { return String(d.getUTCMilliseconds() * 1000).padStart(6, "0"); }
191
+ };
192
+ for (const directive of exports.STRFTIME_DIRECTIVES) {
193
+ if (result.includes(directive)) {
194
+ result = result.replaceAll(directive, replacements[directive]);
195
+ }
196
+ }
197
+ // 4. Restore literal percent symbols
198
+ return result.replace(/\0/g, "%");
199
+ }
200
+ function strptime(str, format, strict = true) {
201
+ if (typeof str !== "string" || typeof format !== "string")
202
+ return null;
203
+ const placeholders = [];
204
+ let groupIndex = 1;
205
+ let regexStr = "";
206
+ let i = 0;
207
+ while (i < format.length) {
208
+ const char = format[i];
209
+ if (char === "%") {
210
+ if (i + 1 < format.length) {
211
+ const nextChar = format[i + 1];
212
+ if (nextChar === "%") {
213
+ regexStr += "%";
214
+ i += 2;
215
+ }
216
+ else if (format.slice(i, i + 3) === "%ms") {
217
+ placeholders.push({ name: "ms", index: groupIndex++ });
218
+ regexStr += "(\\d{1,3})";
219
+ i += 3;
220
+ }
221
+ else {
222
+ switch (nextChar) {
223
+ case "Y":
224
+ placeholders.push({ name: "year", index: groupIndex++ });
225
+ regexStr += "(\\d{4})";
226
+ break;
227
+ case "y":
228
+ placeholders.push({ name: "year_short", index: groupIndex++ });
229
+ regexStr += "(\\d{2})";
230
+ break;
231
+ case "m":
232
+ placeholders.push({ name: "month", index: groupIndex++ });
233
+ regexStr += "(\\d{1,2})";
234
+ break;
235
+ case "d":
236
+ case "e":
237
+ placeholders.push({ name: "day", index: groupIndex++ });
238
+ regexStr += "(\\d{1,2})";
239
+ break;
240
+ case "H":
241
+ case "I":
242
+ placeholders.push({ name: "hour", index: groupIndex++ });
243
+ regexStr += "(\\d{1,2})";
244
+ break;
245
+ case "M":
246
+ placeholders.push({ name: "minute", index: groupIndex++ });
247
+ regexStr += "(\\d{1,2})";
248
+ break;
249
+ case "S":
250
+ placeholders.push({ name: "second", index: groupIndex++ });
251
+ regexStr += "(\\d{1,2})";
252
+ break;
253
+ case "f":
254
+ placeholders.push({ name: "fractional", index: groupIndex++ });
255
+ regexStr += "(\\d{1,6})";
256
+ break;
257
+ default:
258
+ regexStr += char + nextChar;
259
+ }
260
+ i += 2;
261
+ }
262
+ }
263
+ else {
264
+ regexStr += char;
265
+ i++;
266
+ }
267
+ }
268
+ else {
269
+ if ("\\^$*+?.()|[]{}".indexOf(char) !== -1) {
270
+ regexStr += "\\" + char;
271
+ }
272
+ else {
273
+ regexStr += char;
274
+ }
275
+ i++;
276
+ }
277
+ }
278
+ const regex = new RegExp("^" + regexStr + "$");
279
+ const match = str.match(regex);
280
+ if (!match) {
281
+ if (strict)
282
+ return null;
283
+ const parsed = new Date(str);
284
+ return isValidDateObj(parsed) ? parsed : null;
285
+ }
286
+ let year = 1970;
287
+ let month = 1;
288
+ let day = 1;
289
+ let hour = 0;
290
+ let minute = 0;
291
+ let second = 0;
292
+ let ms = 0;
293
+ for (const p of placeholders) {
294
+ const valStr = match[p.index];
295
+ const val = parseInt(valStr, 10);
296
+ switch (p.name) {
297
+ case "year":
298
+ year = val;
299
+ break;
300
+ case "year_short":
301
+ year = val + (val >= 69 ? 1900 : 2000);
302
+ break;
303
+ case "month":
304
+ month = val;
305
+ break;
306
+ case "day":
307
+ day = val;
308
+ break;
309
+ case "hour":
310
+ hour = val;
311
+ break;
312
+ case "minute":
313
+ minute = val;
314
+ break;
315
+ case "second":
316
+ second = val;
317
+ break;
318
+ case "ms":
319
+ ms = parseInt(valStr.padEnd(3, "0").slice(0, 3), 10);
320
+ break;
321
+ case "fractional":
322
+ ms = parseInt(valStr.padEnd(6, "0").slice(0, 3), 10);
323
+ break;
324
+ }
325
+ }
326
+ const d = new Date(Date.UTC(year, month - 1, day, hour, minute, second, ms));
327
+ return isValidDateObj(d) ? d : null;
328
+ }
329
+ function toValidDate(input) {
330
+ if (input instanceof Date) {
331
+ return isValidDateObj(input) ? input : null;
332
+ }
333
+ if (typeof input === "number") {
334
+ const d = new Date(normalizeEpochToMs(input));
335
+ return isValidDateObj(d) ? d : null;
336
+ }
337
+ if (typeof input === "bigint") {
338
+ const d = new Date(normalizeEpochToMs(Number(input)));
339
+ return isValidDateObj(d) ? d : null;
340
+ }
341
+ if (typeof input === "string") {
342
+ const s = input.trim();
343
+ if (s === "")
344
+ return null;
345
+ const d = new Date(s);
346
+ return isValidDateObj(d) ? d : null;
347
+ }
348
+ return null;
349
+ }
@@ -0,0 +1,14 @@
1
+ export declare function isTypedArray(v: unknown): v is ArrayBufferView;
2
+ export declare function isArrayOrTypedArray(v: unknown): v is ArrayLike<any> & Iterable<any>;
3
+ export declare function isNonEmptyArray<T = unknown>(arr: unknown): arr is ArrayLike<T>;
4
+ export declare function isNonEmptyArrayObjs<T extends object>(arr: unknown): arr is T[];
5
+ export declare function isNonEmptyObj(v: unknown): v is Record<string, unknown>;
6
+ export declare function isObj(v: unknown): v is Record<string, unknown>;
7
+ export declare function isPlainObj(v: unknown): v is Record<string, unknown>;
8
+ export declare function isClass(v: unknown): v is new (...args: any[]) => any;
9
+ export declare function isScalar(v: unknown): v is string | number | boolean | bigint | Date | Uint8Array;
10
+ export declare function isValidBinary(v: unknown): v is Uint8Array | string | ArrayLike<any>;
11
+ export declare function toValidBinary(v: unknown): Uint8Array | null;
12
+ export declare function tryParseBoolean(v: unknown): boolean | undefined;
13
+ export declare function isJsonString(input: unknown, allowPrimitives?: boolean): input is string;
14
+ export declare function safeJsonParse(input: unknown): unknown;
@@ -0,0 +1,143 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isTypedArray = isTypedArray;
4
+ exports.isArrayOrTypedArray = isArrayOrTypedArray;
5
+ exports.isNonEmptyArray = isNonEmptyArray;
6
+ exports.isNonEmptyArrayObjs = isNonEmptyArrayObjs;
7
+ exports.isNonEmptyObj = isNonEmptyObj;
8
+ exports.isObj = isObj;
9
+ exports.isPlainObj = isPlainObj;
10
+ exports.isClass = isClass;
11
+ exports.isScalar = isScalar;
12
+ exports.isValidBinary = isValidBinary;
13
+ exports.toValidBinary = toValidBinary;
14
+ exports.tryParseBoolean = tryParseBoolean;
15
+ exports.isJsonString = isJsonString;
16
+ exports.safeJsonParse = safeJsonParse;
17
+ const date_1 = require("./date");
18
+ const number_1 = require("./number");
19
+ function isTypedArray(v) {
20
+ return ArrayBuffer.isView(v) && !(v instanceof DataView);
21
+ }
22
+ function isArrayOrTypedArray(v) {
23
+ return Array.isArray(v) || isTypedArray(v);
24
+ }
25
+ function isNonEmptyArray(arr) {
26
+ return isArrayOrTypedArray(arr) && arr.length > 0;
27
+ }
28
+ function isNonEmptyArrayObjs(arr) {
29
+ if (!isNonEmptyArray(arr))
30
+ return false;
31
+ const len = arr.length;
32
+ for (let i = 0; i < len; i++) {
33
+ if (!isObj(arr[i]))
34
+ return false;
35
+ }
36
+ return true;
37
+ }
38
+ function isNonEmptyObj(v) {
39
+ return isObj(v) && Object.keys(v).length > 0;
40
+ }
41
+ function isObj(v) {
42
+ return v !== null && typeof v === "object" && !Array.isArray(v);
43
+ }
44
+ function isPlainObj(v) {
45
+ if (!isObj(v))
46
+ return false;
47
+ const proto = Object.getPrototypeOf(v);
48
+ return proto === null || proto === Object.prototype;
49
+ }
50
+ function isClass(v) {
51
+ if (typeof v !== "function")
52
+ return false;
53
+ return (/^class\s/.test(Function.prototype.toString.call(v)) ||
54
+ (v.prototype !== undefined &&
55
+ v.prototype.constructor === v &&
56
+ Object.getOwnPropertyDescriptor(v, "prototype")?.writable === false));
57
+ }
58
+ function isScalar(v) {
59
+ return (typeof v === "string" ||
60
+ typeof v === "number" ||
61
+ typeof v === "boolean" ||
62
+ typeof v === "bigint" ||
63
+ (0, date_1.isValidDateObj)(v) ||
64
+ v instanceof Uint8Array);
65
+ }
66
+ function isValidBinary(v) {
67
+ if (v == null)
68
+ return false;
69
+ if (v instanceof Uint8Array)
70
+ return true;
71
+ if (typeof v === "string")
72
+ return true;
73
+ if (Array.isArray(v)) {
74
+ const len = v.length;
75
+ for (let i = 0; i < len; i++) {
76
+ if (!(0, number_1.isValidInt)(v[i], { min: -128, max: 255 })) {
77
+ return false;
78
+ }
79
+ }
80
+ return true;
81
+ }
82
+ if (isTypedArray(v)) {
83
+ return true;
84
+ }
85
+ return false;
86
+ }
87
+ function toValidBinary(v) {
88
+ if (!isValidBinary(v))
89
+ return null;
90
+ if (v instanceof Uint8Array)
91
+ return v;
92
+ if (typeof v === "string") {
93
+ return new TextEncoder().encode(v);
94
+ }
95
+ if (ArrayBuffer.isView(v)) {
96
+ return new Uint8Array(v.buffer, v.byteOffset, v.byteLength);
97
+ }
98
+ return new Uint8Array(v);
99
+ }
100
+ const boolMap = {
101
+ true: true, "1": true, yes: true, y: true, on: true,
102
+ false: false, "0": false, no: false, n: false, off: false
103
+ };
104
+ function tryParseBoolean(v) {
105
+ if (typeof v === "boolean")
106
+ return v;
107
+ if (v === 1)
108
+ return true;
109
+ if (v === 0)
110
+ return false;
111
+ if (typeof v !== "string")
112
+ return undefined;
113
+ return boolMap[v.trim().toLowerCase()];
114
+ }
115
+ function isJsonString(input, allowPrimitives = false) {
116
+ if (typeof input !== "string")
117
+ return false;
118
+ const s = input.trim();
119
+ if (s === "")
120
+ return false;
121
+ if (!allowPrimitives) {
122
+ const isWrapped = (s.startsWith("{") && s.endsWith("}")) || (s.startsWith("[") && s.endsWith("]"));
123
+ if (!isWrapped)
124
+ return false;
125
+ }
126
+ try {
127
+ JSON.parse(s);
128
+ return true;
129
+ }
130
+ catch {
131
+ return false;
132
+ }
133
+ }
134
+ function safeJsonParse(input) {
135
+ if (typeof input !== "string")
136
+ return input;
137
+ try {
138
+ return JSON.parse(input);
139
+ }
140
+ catch {
141
+ return input;
142
+ }
143
+ }
@@ -0,0 +1,5 @@
1
+ export * from "./guards";
2
+ export * from "./number";
3
+ export * from "./date";
4
+ export * from "./list";
5
+ export * from "./string";
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./guards"), exports);
18
+ __exportStar(require("./number"), exports);
19
+ __exportStar(require("./date"), exports);
20
+ __exportStar(require("./list"), exports);
21
+ __exportStar(require("./string"), exports);
@@ -0,0 +1,2 @@
1
+ export declare function isJsonString(input: unknown, allowPrimitives?: boolean): input is string;
2
+ export declare function safeJsonParse(input: unknown): unknown;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isJsonString = isJsonString;
4
+ exports.safeJsonParse = safeJsonParse;
5
+ function isJsonString(input, allowPrimitives = false) {
6
+ if (typeof input !== "string")
7
+ return false;
8
+ const s = input.trim();
9
+ if (s === "")
10
+ return false;
11
+ if (!allowPrimitives) {
12
+ const isWrapped = (s.startsWith("{") && s.endsWith("}")) || (s.startsWith("[") && s.endsWith("]"));
13
+ if (!isWrapped)
14
+ return false;
15
+ }
16
+ try {
17
+ JSON.parse(s);
18
+ return true;
19
+ }
20
+ catch {
21
+ return false;
22
+ }
23
+ }
24
+ function safeJsonParse(input) {
25
+ if (typeof input !== "string")
26
+ return input;
27
+ try {
28
+ return JSON.parse(input);
29
+ }
30
+ catch {
31
+ return input;
32
+ }
33
+ }
@@ -0,0 +1,23 @@
1
+ export type ArrayItemType = "string" | "number" | "boolean" | "bigint" | "object" | "plainObject" | "date" | (new (...args: any[]) => any) | ((v: unknown) => boolean);
2
+ export type ArrayCheckMode = "every" | "some";
3
+ export type IsArrayOfTypeOptionsParams = {
4
+ mode?: ArrayCheckMode;
5
+ allowNulls?: boolean;
6
+ allowEmpty?: boolean;
7
+ };
8
+ export declare function toValidArray<T>(val: T | T[] | null | undefined): T[];
9
+ export declare function isArrayOfType(arr: unknown, type: ArrayItemType, { mode, allowNulls, allowEmpty }?: IsArrayOfTypeOptionsParams): boolean;
10
+ export declare function sortList(arr: unknown, descending?: boolean): any[];
11
+ export declare function getListStats(arr: unknown): {
12
+ sum: number | null;
13
+ count: number;
14
+ min: any;
15
+ max: any;
16
+ mean: number | null;
17
+ variance: number;
18
+ std: number;
19
+ nullCount: number;
20
+ len: number;
21
+ hasNulls: boolean;
22
+ isNumeric: boolean;
23
+ };