df-script 1.4.0 → 1.6.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 (142) hide show
  1. package/README.md +203 -38
  2. package/dist/api.d.ts +16 -8
  3. package/dist/columnExpressions/ColumnExpr.d.ts +26 -364
  4. package/dist/columnExpressions/ExprBase.d.ts +8 -11
  5. package/dist/columnExpressions/constants.d.ts +2 -0
  6. package/dist/columnExpressions/functions/coalesce.d.ts +2 -2
  7. package/dist/columnExpressions/functions/element.d.ts +5 -0
  8. package/dist/columnExpressions/functions/implode.d.ts +3 -0
  9. package/dist/columnExpressions/functions/lit.d.ts +3 -1
  10. package/dist/columnExpressions/functions/seq_range.d.ts +31 -0
  11. package/dist/columnExpressions/functions/when.d.ts +2 -2
  12. package/dist/columnExpressions/index.d.ts +6 -3
  13. package/dist/columnExpressions/mixins/AggregationExpr.d.ts +25 -50
  14. package/dist/columnExpressions/mixins/ArithmeticExpr.d.ts +43 -67
  15. package/dist/columnExpressions/mixins/ArrayExpr.d.ts +39 -0
  16. package/dist/columnExpressions/mixins/ComparisonExpr.d.ts +31 -60
  17. package/dist/columnExpressions/mixins/ListExpr.d.ts +16 -40
  18. package/dist/columnExpressions/mixins/LogicalExpr.d.ts +7 -33
  19. package/dist/columnExpressions/mixins/ManipulationExpr.d.ts +6 -31
  20. package/dist/columnExpressions/mixins/StringExpr.d.ts +7 -32
  21. package/dist/columnExpressions/mixins/StructExpr.d.ts +16 -0
  22. package/dist/columnExpressions/mixins/TemporalExpr.d.ts +4 -30
  23. package/dist/columnExpressions/mixins/WindowExpr.d.ts +27 -49
  24. package/dist/columnExpressions/types.d.ts +1 -0
  25. package/dist/columnExpressions/utils.d.ts +4 -0
  26. package/dist/constants.d.ts +11 -0
  27. package/dist/dataframe/constants.d.ts +3 -0
  28. package/dist/dataframe/dataframe.d.ts +28 -11
  29. package/dist/dataframe/grouped/grouped.d.ts +2 -3
  30. package/dist/dataframe/types.d.ts +65 -1
  31. package/dist/dataframe/utils.d.ts +11 -3
  32. package/dist/datatypes/DataType.d.ts +2 -1
  33. package/dist/datatypes/index.d.ts +4 -3
  34. package/dist/datatypes/types.d.ts +42 -41
  35. package/dist/exceptions/index.d.ts +2 -0
  36. package/dist/exceptions/utils.d.ts +1 -0
  37. package/dist/functions/concat.d.ts +1 -2
  38. package/dist/functions/index.d.ts +3 -1
  39. package/dist/functions/read_csv.d.ts +8 -0
  40. package/dist/functions/read_json.d.ts +10 -0
  41. package/dist/index.js +6 -1
  42. package/dist/types.d.ts +34 -6
  43. package/dist/utils/array.d.ts +217 -0
  44. package/dist/utils/binary.d.ts +3 -0
  45. package/dist/utils/csv.d.ts +77 -0
  46. package/dist/utils/date.d.ts +21 -35
  47. package/dist/utils/guards.d.ts +11 -12
  48. package/dist/utils/index.d.ts +5 -2
  49. package/dist/utils/json.d.ts +120 -2
  50. package/dist/utils/list.d.ts +196 -2
  51. package/dist/utils/number.d.ts +47 -29
  52. package/dist/utils/object.d.ts +26 -0
  53. package/dist/utils/string.d.ts +7 -4
  54. package/package.json +6 -2
  55. package/dist/api.js +0 -18
  56. package/dist/bundle.min.js +0 -1
  57. package/dist/columnExpressions/ColumnExpr.js +0 -23
  58. package/dist/columnExpressions/ExprBase.js +0 -133
  59. package/dist/columnExpressions/constants.js +0 -5
  60. package/dist/columnExpressions/functions/all.js +0 -11
  61. package/dist/columnExpressions/functions/coalesce.js +0 -40
  62. package/dist/columnExpressions/functions/exclude.js +0 -13
  63. package/dist/columnExpressions/functions/lit.js +0 -22
  64. package/dist/columnExpressions/functions/when.js +0 -81
  65. package/dist/columnExpressions/index.js +0 -81
  66. package/dist/columnExpressions/mixins/AggregationExpr.js +0 -172
  67. package/dist/columnExpressions/mixins/ArithmeticExpr.js +0 -143
  68. package/dist/columnExpressions/mixins/ComparisonExpr.js +0 -389
  69. package/dist/columnExpressions/mixins/ListExpr.js +0 -248
  70. package/dist/columnExpressions/mixins/LogicalExpr.js +0 -54
  71. package/dist/columnExpressions/mixins/ManipulationExpr.js +0 -35
  72. package/dist/columnExpressions/mixins/StringExpr.js +0 -249
  73. package/dist/columnExpressions/mixins/TemporalExpr.js +0 -127
  74. package/dist/columnExpressions/mixins/WindowExpr.js +0 -281
  75. package/dist/columnExpressions/types.js +0 -2
  76. package/dist/dataframe/constants.js +0 -4
  77. package/dist/dataframe/dataframe.js +0 -749
  78. package/dist/dataframe/grouped/grouped.js +0 -113
  79. package/dist/dataframe/index.js +0 -20
  80. package/dist/dataframe/types.js +0 -2
  81. package/dist/dataframe/utils.js +0 -215
  82. package/dist/datatypes/DataType.js +0 -47
  83. package/dist/datatypes/index.js +0 -46
  84. package/dist/datatypes/types/Binary.d.ts +0 -9
  85. package/dist/datatypes/types/Binary.js +0 -18
  86. package/dist/datatypes/types/Boolean.d.ts +0 -9
  87. package/dist/datatypes/types/Boolean.js +0 -19
  88. package/dist/datatypes/types/Date.d.ts +0 -8
  89. package/dist/datatypes/types/Date.js +0 -21
  90. package/dist/datatypes/types/Datetime.d.ts +0 -8
  91. package/dist/datatypes/types/Datetime.js +0 -17
  92. package/dist/datatypes/types/Decimal.d.ts +0 -10
  93. package/dist/datatypes/types/Decimal.js +0 -28
  94. package/dist/datatypes/types/Duration.d.ts +0 -8
  95. package/dist/datatypes/types/Duration.js +0 -17
  96. package/dist/datatypes/types/Float32.d.ts +0 -8
  97. package/dist/datatypes/types/Float32.js +0 -17
  98. package/dist/datatypes/types/Float64.d.ts +0 -8
  99. package/dist/datatypes/types/Float64.js +0 -17
  100. package/dist/datatypes/types/Int16.d.ts +0 -8
  101. package/dist/datatypes/types/Int16.js +0 -17
  102. package/dist/datatypes/types/Int32.d.ts +0 -8
  103. package/dist/datatypes/types/Int32.js +0 -17
  104. package/dist/datatypes/types/Int64.d.ts +0 -8
  105. package/dist/datatypes/types/Int64.js +0 -17
  106. package/dist/datatypes/types/Int8.d.ts +0 -8
  107. package/dist/datatypes/types/Int8.js +0 -17
  108. package/dist/datatypes/types/List.d.ts +0 -10
  109. package/dist/datatypes/types/List.js +0 -31
  110. package/dist/datatypes/types/Null.d.ts +0 -9
  111. package/dist/datatypes/types/Null.js +0 -17
  112. package/dist/datatypes/types/Object.d.ts +0 -9
  113. package/dist/datatypes/types/Object.js +0 -17
  114. package/dist/datatypes/types/Struct.d.ts +0 -14
  115. package/dist/datatypes/types/Struct.js +0 -39
  116. package/dist/datatypes/types/Time.d.ts +0 -8
  117. package/dist/datatypes/types/Time.js +0 -29
  118. package/dist/datatypes/types/UInt16.d.ts +0 -8
  119. package/dist/datatypes/types/UInt16.js +0 -17
  120. package/dist/datatypes/types/UInt32.d.ts +0 -8
  121. package/dist/datatypes/types/UInt32.js +0 -17
  122. package/dist/datatypes/types/UInt64.d.ts +0 -8
  123. package/dist/datatypes/types/UInt64.js +0 -17
  124. package/dist/datatypes/types/UInt8.d.ts +0 -8
  125. package/dist/datatypes/types/UInt8.js +0 -17
  126. package/dist/datatypes/types/Utf8.d.ts +0 -10
  127. package/dist/datatypes/types/Utf8.js +0 -20
  128. package/dist/datatypes/types.js +0 -286
  129. package/dist/exceptions/index.js +0 -43
  130. package/dist/exceptions/utils.js +0 -9
  131. package/dist/functions/concat.js +0 -248
  132. package/dist/functions/index.js +0 -17
  133. package/dist/types.js +0 -2
  134. package/dist/utils/boolean.d.ts +0 -1
  135. package/dist/utils/boolean.js +0 -18
  136. package/dist/utils/date.js +0 -349
  137. package/dist/utils/guards.js +0 -143
  138. package/dist/utils/index.js +0 -21
  139. package/dist/utils/json.js +0 -33
  140. package/dist/utils/list.js +0 -128
  141. package/dist/utils/number.js +0 -223
  142. package/dist/utils/string.js +0 -120
@@ -1,223 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BIGINT_RANGES = exports.INT_RANGES = exports.FLOAT_RANGES = exports.FLOAT_32_BOUNDARY = void 0;
4
- exports.isValidNumber = isValidNumber;
5
- exports.toValidNumber = toValidNumber;
6
- exports.clamp = clamp;
7
- exports.isValidFloat = isValidFloat;
8
- exports.toValidFloat = toValidFloat;
9
- exports.isValidInt = isValidInt;
10
- exports.isValidBigInt = isValidBigInt;
11
- exports.toValidInt = toValidInt;
12
- exports.toValidBigInt = toValidBigInt;
13
- exports.isValidDecimal = isValidDecimal;
14
- exports.toValidDecimal = toValidDecimal;
15
- exports.mulberry32 = mulberry32;
16
- const NUMERIC_CLEAN_REGEX = /[,\s_]/g;
17
- const VALID_DECIMAL_REGEX = /^[+-]?\d+(?:\.\d+)?$/;
18
- // ============================================================================
19
- // /** Generic Number Helpers */
20
- // ============================================================================
21
- function isValidNumber(v) {
22
- return typeof v === "number" && !Number.isNaN(v) && Number.isFinite(v);
23
- }
24
- function toValidNumber(v) {
25
- if (v == null)
26
- return null;
27
- if (typeof v === "symbol")
28
- return null;
29
- if (isValidNumber(v)) {
30
- return v;
31
- }
32
- if (typeof v === "boolean") {
33
- return v ? 1 : 0;
34
- }
35
- if (typeof v === "bigint") {
36
- const n = Number(v);
37
- return isValidNumber(n) ? n : null;
38
- }
39
- if (v instanceof Date) {
40
- const t = v.getTime();
41
- return isValidNumber(t) ? t : null;
42
- }
43
- if (typeof v === "string") {
44
- const clean = v.trim().replace(NUMERIC_CLEAN_REGEX, "");
45
- if (clean === "")
46
- return null;
47
- const n = Number(clean);
48
- return isValidNumber(n) ? n : null;
49
- }
50
- return null;
51
- }
52
- function clamp(opts) {
53
- const { val, min, max } = opts;
54
- if (val < min)
55
- return min;
56
- if (val > max)
57
- return max;
58
- return val;
59
- }
60
- exports.FLOAT_32_BOUNDARY = 3.4028234663852886e+38;
61
- exports.FLOAT_RANGES = {
62
- Float32: { min: -exports.FLOAT_32_BOUNDARY, max: exports.FLOAT_32_BOUNDARY },
63
- Float64: { min: -Number.MAX_VALUE, max: Number.MAX_VALUE }
64
- };
65
- function isValidFloat(v, precision) {
66
- if (!isValidNumber(v))
67
- return false;
68
- if (precision) {
69
- const limits = exports.FLOAT_RANGES[precision];
70
- return v >= limits.min && v <= limits.max;
71
- }
72
- return true;
73
- }
74
- function toValidFloat(v, precision = "Float64") {
75
- const num = toValidNumber(v);
76
- if (num === null)
77
- return null;
78
- return precision === "Float32" ? Math.fround(num) : num;
79
- }
80
- // ============================================================================
81
- // /** Integer & BigInt Functions */
82
- // ============================================================================
83
- exports.INT_RANGES = {
84
- Int8: { min: -128, max: 127 },
85
- Int16: { min: -32768, max: 32767 },
86
- Int32: { min: -2147483648, max: 2147483647 },
87
- UInt8: { min: 0, max: 255 },
88
- UInt16: { min: 0, max: 65535 },
89
- UInt32: { min: 0, max: 4294967295 }
90
- };
91
- exports.BIGINT_RANGES = {
92
- Int64: { min: -9223372036854775808n, max: 9223372036854775807n },
93
- UInt64: { min: 0n, max: 18446744073709551615n }
94
- };
95
- function isValidInt(v, range) {
96
- if (!isValidNumber(v))
97
- return false;
98
- if (!Number.isInteger(v))
99
- return false;
100
- if (!range)
101
- return true;
102
- const limits = typeof range === "string" ? exports.INT_RANGES[range] : range;
103
- return v >= limits.min && v <= limits.max;
104
- }
105
- function isValidBigInt(v, range) {
106
- if (typeof v !== "bigint")
107
- return false;
108
- if (!range)
109
- return true;
110
- const limits = typeof range === "string" ? exports.BIGINT_RANGES[range] : range;
111
- return v >= limits.min && v <= limits.max;
112
- }
113
- function toValidInt(v, range = "Int32", opts = {}) {
114
- const num = toValidNumber(v);
115
- if (num === null)
116
- return null;
117
- let n = num;
118
- const coerce = opts.coerce || "truncate";
119
- switch (coerce) {
120
- case "round":
121
- n = Math.round(n);
122
- break;
123
- case "floor":
124
- n = Math.floor(n);
125
- break;
126
- case "ceil":
127
- n = Math.ceil(n);
128
- break;
129
- case "truncate":
130
- n = Math.trunc(n);
131
- break;
132
- }
133
- const limits = typeof range === "string" ? exports.INT_RANGES[range] : range;
134
- return clamp({ val: n, min: limits.min, max: limits.max });
135
- }
136
- function toValidBigInt(v, range = "Int64") {
137
- if (v == null)
138
- return null;
139
- if (typeof v === "symbol")
140
- return null;
141
- let bigintVal = null;
142
- if (typeof v === "bigint") {
143
- bigintVal = v;
144
- }
145
- else if (typeof v === "boolean") {
146
- bigintVal = v ? 1n : 0n;
147
- }
148
- else if (typeof v === "string") {
149
- const clean = v.trim().replace(NUMERIC_CLEAN_REGEX, "");
150
- if (clean === "")
151
- return null;
152
- if (!VALID_DECIMAL_REGEX.test(clean)) {
153
- const num = toValidNumber(v);
154
- if (num === null)
155
- return null;
156
- bigintVal = BigInt(Math.trunc(num));
157
- }
158
- else {
159
- bigintVal = BigInt(clean.split(".")[0]);
160
- }
161
- }
162
- else {
163
- const num = toValidNumber(v);
164
- if (num === null)
165
- return null;
166
- bigintVal = BigInt(Math.trunc(num));
167
- }
168
- const limits = typeof range === "string" ? exports.BIGINT_RANGES[range] : range;
169
- return clamp({ val: bigintVal, min: limits.min, max: limits.max });
170
- }
171
- function isValidDecimal(v, opts = {}) {
172
- if (!isValidNumber(v))
173
- return false;
174
- const { precision, scale = 0 } = opts;
175
- if (precision !== undefined) {
176
- const integerDigits = precision - scale;
177
- const maxVal = Math.pow(10, integerDigits) - Math.pow(10, -scale);
178
- if (integerDigits > 0 && Math.abs(v) > maxVal) {
179
- return false;
180
- }
181
- }
182
- if (scale !== undefined) {
183
- const str = v.toString();
184
- const dotIdx = str.indexOf(".");
185
- if (dotIdx !== -1 && str.slice(dotIdx + 1).length > scale) {
186
- return false;
187
- }
188
- }
189
- return true;
190
- }
191
- function toValidDecimal(v, opts = {}) {
192
- const num = toValidNumber(v);
193
- if (num === null)
194
- return null;
195
- const { precision, scale } = opts;
196
- let n = num;
197
- if (scale !== undefined) {
198
- const multiplier = Math.pow(10, scale);
199
- n = Math.round(n * multiplier) / multiplier;
200
- }
201
- if (precision !== undefined) {
202
- const scaleVal = scale || 0;
203
- const integerDigits = precision - scaleVal;
204
- if (integerDigits > 0) {
205
- const maxVal = Math.pow(10, integerDigits) - Math.pow(10, -scaleVal);
206
- n = clamp({ val: n, min: -maxVal, max: maxVal });
207
- }
208
- }
209
- return n;
210
- }
211
- /**
212
- * Creates a seedable pseudo-random number generator using the Mulberry32 PRNG algorithm.
213
- * Returns a function that generates a pseudo-random float in the range [0, 1).
214
- */
215
- function mulberry32(seed) {
216
- let s = seed | 0;
217
- return function () {
218
- let t = s = (s + 0x6D2B79F5) | 0;
219
- t = Math.imul(t ^ (t >>> 15), t | 1);
220
- t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
221
- return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
222
- };
223
- }
@@ -1,120 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripChars = stripChars;
4
- /**
5
- * Strips characters from the start, end, or both ends of a string.
6
- */
7
- function stripChars(str, characters = null, { mode = "both", returnStringOnNull = false, maxScanStart = 1, maxScanEnd = 1, maxMatchesStart = 1, maxMatchesEnd = 1, trimFirst = false, stringOptions: { literal = false, caseInsensitive = false } = {} } = {}) {
8
- if (str == null) {
9
- return returnStringOnNull ? "" : null;
10
- }
11
- const trimString = (s, m = "both") => {
12
- if (m === "start")
13
- return s.trimStart();
14
- if (m === "end")
15
- return s.trimEnd();
16
- return s.trim();
17
- };
18
- let workStr = str;
19
- if (trimFirst && characters != null) {
20
- workStr = trimString(str, mode);
21
- }
22
- if (characters == null) {
23
- const result = trimString(workStr, mode);
24
- return (returnStringOnNull || result !== "") ? result : null;
25
- }
26
- const matches = characters instanceof RegExp
27
- ? (char) => characters.test(char)
28
- : (() => {
29
- const targetSet = new Set(caseInsensitive ? characters.toLowerCase() : characters);
30
- return (char) => targetSet.has(caseInsensitive ? char.toLowerCase() : char);
31
- })();
32
- const len = workStr.length;
33
- const stripped = new Uint8Array(len);
34
- const scanNonLiteral = ({ isStart, limit, maxMatches }) => {
35
- if (len === 0 || maxMatches === 0) {
36
- return;
37
- }
38
- const start = isStart ? 0 : len - 1;
39
- const end = isStart ? len : -1;
40
- const step = isStart ? 1 : -1;
41
- let inBlock = false;
42
- let matchesFound = 0;
43
- let totalSkipped = 0;
44
- for (let i = start; i !== end; i += step) {
45
- if (matches(workStr[i])) {
46
- if (!inBlock) {
47
- if (limit !== null && limit >= 0 && totalSkipped >= limit) {
48
- break;
49
- }
50
- if (maxMatches !== null && maxMatches >= 0 && matchesFound >= maxMatches) {
51
- break;
52
- }
53
- inBlock = true;
54
- matchesFound++;
55
- }
56
- stripped[i] = 1;
57
- }
58
- else {
59
- inBlock = false;
60
- totalSkipped++;
61
- }
62
- }
63
- };
64
- const scanLiteral = ({ isStart, limit, maxMatches }) => {
65
- if (len === 0 || maxMatches === 0) {
66
- return;
67
- }
68
- const patLen = characters.length;
69
- if (patLen === 0) {
70
- return;
71
- }
72
- const searchStr = caseInsensitive ? workStr.toLowerCase() : workStr;
73
- const patStr = caseInsensitive ? characters.toLowerCase() : characters;
74
- let currentIdx = isStart ? 0 : len - 1;
75
- let matchesFound = 0;
76
- let totalSkipped = 0;
77
- while (currentIdx >= 0 && currentIdx < len) {
78
- if (maxMatches !== null && maxMatches >= 0 && matchesFound >= maxMatches) {
79
- break;
80
- }
81
- const searchStart = isStart ? currentIdx : (currentIdx - patLen + 1);
82
- if (!isStart && searchStart < 0) {
83
- break;
84
- }
85
- const matchIdx = isStart
86
- ? searchStr.indexOf(patStr, searchStart)
87
- : searchStr.lastIndexOf(patStr, searchStart);
88
- if (matchIdx === -1) {
89
- break;
90
- }
91
- const skippedInThisStep = isStart
92
- ? (matchIdx - currentIdx)
93
- : (currentIdx - (matchIdx + patLen - 1));
94
- totalSkipped += skippedInThisStep;
95
- if (limit !== null && limit >= 0 && totalSkipped >= limit) {
96
- break;
97
- }
98
- for (let i = 0; i < patLen; i++) {
99
- stripped[matchIdx + i] = 1;
100
- }
101
- matchesFound++;
102
- currentIdx = isStart ? (matchIdx + patLen) : (matchIdx - 1);
103
- }
104
- };
105
- const isLiteral = literal && typeof characters === "string";
106
- const scan = isLiteral ? scanLiteral : scanNonLiteral;
107
- if (mode === "both" || mode === "start") {
108
- scan({ isStart: true, limit: maxScanStart, maxMatches: maxMatchesStart });
109
- }
110
- if (mode === "both" || mode === "end") {
111
- scan({ isStart: false, limit: maxScanEnd, maxMatches: maxMatchesEnd });
112
- }
113
- let result = "";
114
- for (let i = 0; i < len; i++) {
115
- if (stripped[i] === 0) {
116
- result += workStr[i];
117
- }
118
- }
119
- return (returnStringOnNull || result !== "") ? result : null;
120
- }