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
@@ -0,0 +1,217 @@
1
+ import type { AnyTypedArray } from "../types";
2
+ export declare function isTypedArray(v: unknown): v is AnyTypedArray;
3
+ export declare function isArrayOrTypedArray(v: unknown): v is any[] | AnyTypedArray;
4
+ export type ArrayItemType = "string" | "number" | "boolean" | "bigint" | "object" | "plainObject" | "date" | "any" | "null" | "undefined" | "nullish" | (new (...args: any[]) => any) | ((v: unknown) => boolean);
5
+ export type ArrayCheckMode = "every" | "some";
6
+ export type IsArrayOfTypeOptionsParams = {
7
+ mode?: ArrayCheckMode;
8
+ allowNulls?: boolean;
9
+ allowEmpty?: boolean;
10
+ };
11
+ export declare function toValidArray<T>(val: T | T[] | null | undefined): T[];
12
+ export declare function toValidStringArray(val: unknown): string[];
13
+ export declare function isArrayOfType(arr: unknown, type: ArrayItemType, { mode, allowNulls, allowEmpty }?: IsArrayOfTypeOptionsParams): boolean;
14
+ export interface SortArrayOptions {
15
+ descending?: boolean;
16
+ nullsLast?: boolean;
17
+ }
18
+ export declare function sortArray(arr: unknown, { descending, nullsLast }?: SortArrayOptions): any[];
19
+ export declare function getArrayStats(arr: unknown): {
20
+ sum: number | null;
21
+ count: number;
22
+ min: any;
23
+ max: any;
24
+ mean: number | null;
25
+ variance: number;
26
+ std: number;
27
+ nullCount: number;
28
+ len: number;
29
+ hasNulls: boolean;
30
+ isNumeric: boolean;
31
+ };
32
+ /**
33
+ * Options configuration for the `getUniqueArrayStats` utility.
34
+ */
35
+ export interface UniqueArrayStatsOptions {
36
+ /**
37
+ * If true, uses strict serialization comparison (via keySelector or toCanonicalString)
38
+ * to group complex nested types (like Arrays, Sets, Maps, and Dates) by value instead of reference.
39
+ * @default false
40
+ */
41
+ strict?: boolean;
42
+ /**
43
+ * Custom function to extract a unique comparison key from each element.
44
+ * If strict is true and no selector is provided, falls back to `toCanonicalString`.
45
+ */
46
+ keySelector?: (val: any) => any;
47
+ }
48
+ export declare function getUniqueArrayStats(arr: ArrayLike<any>, { strict, keySelector }?: UniqueArrayStatsOptions): {
49
+ values: any[];
50
+ count: number;
51
+ frequencies: Map<any, number>;
52
+ };
53
+ /**
54
+ * Options configuration for the `stepSliceArray` utility.
55
+ */
56
+ export interface StepSliceArrayOptions {
57
+ /**
58
+ * The step size to slice the array by. Cannot be zero.
59
+ * Positive values slice forward (left-to-right), negative values slice backward (right-to-left).
60
+ * @default 1
61
+ */
62
+ step?: number;
63
+ /**
64
+ * The index to start slicing from (inclusive).
65
+ * Supports negative values to start relative to the end of the array.
66
+ * @default 0
67
+ */
68
+ offsetStart?: number;
69
+ /**
70
+ * The index to end slicing at (exclusive).
71
+ * Supports negative values to end relative to the end of the array.
72
+ * Defaults to the end of the array (if step > 0) or -1 (if step < 0).
73
+ */
74
+ offsetEnd?: number;
75
+ /**
76
+ * Caps the maximum number of items gathered in the sliced result array.
77
+ * If specified, the slicing process stops once this limit is reached.
78
+ */
79
+ maxItemsGathered?: number;
80
+ /**
81
+ * If true, returns null when the starting offset is out of bounds.
82
+ * If false, throws an error when the starting offset is out of bounds.
83
+ * @default true
84
+ */
85
+ null_on_oob?: boolean;
86
+ }
87
+ export declare function stepSliceArray<T>(arr: ArrayLike<T>, { step, offsetStart, offsetEnd, maxItemsGathered, null_on_oob }?: StepSliceArrayOptions): T[] | null;
88
+ /**
89
+ * Options configuration for the `joinArray` utility.
90
+ */
91
+ export interface JoinArrayOptions {
92
+ /**
93
+ * If true, nullish elements (null and undefined) are completely ignored during joining.
94
+ * If false (default), nullish elements are serialized as empty strings or custom `nullValue`.
95
+ * @default false
96
+ */
97
+ ignoreNulls?: boolean;
98
+ /**
99
+ * Custom string representation for nullish values.
100
+ * Only applied if `ignoreNulls` is false.
101
+ * @default ""
102
+ */
103
+ nullValue?: string;
104
+ /**
105
+ * Optional prefix string prepended to the final joined result.
106
+ * @default ""
107
+ */
108
+ prefix?: string;
109
+ /**
110
+ * Optional suffix string appended to the final joined result.
111
+ * @default ""
112
+ */
113
+ suffix?: string;
114
+ /**
115
+ * Maximum number of array elements to join.
116
+ * If specified, elements beyond this limit are omitted and `truncationMarker` is appended.
117
+ */
118
+ limit?: number;
119
+ /**
120
+ * Custom placeholder string appended to the joined string when limit truncation occurs.
121
+ * Only applied if `limit` is specified and the array length exceeds it.
122
+ * @default "..."
123
+ */
124
+ truncationMarker?: string;
125
+ /**
126
+ * Callback function used to format each individual non-null element to a custom string representation.
127
+ */
128
+ valueFormatter?: (val: any, index: number) => string;
129
+ }
130
+ /**
131
+ * Joins the elements of an array-like structure into a string using a separator.
132
+ * Excludes nullish checks and formats nested arrays cleanly.
133
+ */
134
+ export declare function joinArray(arr: ArrayLike<any>, separator?: string, { ignoreNulls, nullValue, prefix, suffix, limit, truncationMarker, valueFormatter }?: JoinArrayOptions): string;
135
+ export interface FillSeqBaseOptions {
136
+ /**
137
+ * Type coercion helper applied to each generated value before writing.
138
+ *
139
+ * @param v The newly generated candidate value.
140
+ * @returns The coerced value to write to the array.
141
+ */
142
+ coerce?: (v: any) => any;
143
+ /**
144
+ * Conditional predicate determining if a value should be replaced at a given index.
145
+ *
146
+ * @param v The original/current value at the target index.
147
+ * @param index The absolute index of the current element.
148
+ * @param array The entire target array.
149
+ * @returns True if the candidate value should overwrite the original value, false otherwise.
150
+ */
151
+ condition?: (v: any, index: number, array: any[]) => boolean;
152
+ /**
153
+ * If true, iterates and populates in reverse (from startIndex down to endIndex).
154
+ * @default false
155
+ */
156
+ reverse?: boolean;
157
+ /**
158
+ * The index at which array iteration and writing begins.
159
+ * @default reverse ? length - 1 : 0
160
+ */
161
+ startIndex?: number;
162
+ /**
163
+ * The exclusive boundary index at which iteration and writing stops.
164
+ * @default reverse ? -1 : length
165
+ */
166
+ endIndex?: number;
167
+ }
168
+ export interface CumulativeStepContext {
169
+ /** The accumulated value returned by the step function from the previous stepped index. */
170
+ prev: any;
171
+ /** The relative iteration counter of the stepping process (starts at 1). */
172
+ index: number;
173
+ /** The original value at the current index in the target array. */
174
+ originalValue: any;
175
+ /** The absolute index of the current element in the parent array. */
176
+ absoluteIndex: number;
177
+ /** The entire target array being populated/modified. */
178
+ targetArray: any;
179
+ }
180
+ export interface IndependentStepContext {
181
+ /** The relative iteration counter of the generation process (starts at 0). */
182
+ index: number;
183
+ /** The static starting value passed to the sequence generator. */
184
+ initialValue: any;
185
+ /** The original value at the current index in the target array. */
186
+ originalValue: any;
187
+ /** The absolute index of the current element in the parent array. */
188
+ absoluteIndex: number;
189
+ /** The entire target array being populated/modified. */
190
+ targetArray: any;
191
+ }
192
+ export type FillSeqOptions = FillSeqBaseOptions & ({
193
+ mode: "constant";
194
+ step?: never;
195
+ } | {
196
+ mode?: "cumulative";
197
+ step?: number | ((context: CumulativeStepContext) => any);
198
+ } | {
199
+ mode: "independent";
200
+ step?: number | ((context: IndependentStepContext) => any);
201
+ });
202
+ export declare function fillSequence(targetArray: any, initialValue: any, options?: FillSeqOptions): void;
203
+ /**
204
+ * Computes the median of a numeric array, filtering out non-numeric and NaN values.
205
+ * Returns null if no valid numbers remain.
206
+ */
207
+ export declare function computeMedian(values: ArrayLike<any>): number | null;
208
+ /**
209
+ * Computes the quantile of a numeric array using linear interpolation, filtering out non-numeric and NaN values.
210
+ * q must be in [0, 1]. Returns null if no valid numbers remain or q is out of bounds.
211
+ */
212
+ export declare function computeQuantile(values: ArrayLike<any>, q: number): number | null;
213
+ /**
214
+ * Computes the mode(s) of an array, filtering out null/undefined values.
215
+ * Returns an array of the most frequent values, sorted, or null if empty/no mode.
216
+ */
217
+ export declare function computeMode(values: ArrayLike<any>): any[] | null;
@@ -0,0 +1,3 @@
1
+ import type { AnyTypedArray } from "../types";
2
+ export declare function isValidBinary(v: unknown): v is string | any[] | AnyTypedArray;
3
+ export declare function toValidBinary(v: unknown): Uint8Array | null;
@@ -0,0 +1,77 @@
1
+ import type { ColumnDict } from "../types";
2
+ import { type SafeJsonReplacerOptions } from "./json";
3
+ import { type NumericFormatOptions } from "./number";
4
+ import { DataType } from "../datatypes";
5
+ import type { ReadCSVOptions } from "../dataframe/types";
6
+ export interface FormatCSVValueOptions {
7
+ /**
8
+ * The string representation to use for null/missing values.
9
+ * @default ""
10
+ */
11
+ nullValue?: string;
12
+ /**
13
+ * Custom format string for Date values (e.g. "%Y-%m-%d").
14
+ */
15
+ dateFormat?: string;
16
+ /**
17
+ * Custom format string for Time values (e.g. "%H:%M:%S").
18
+ */
19
+ timeFormat?: string;
20
+ /**
21
+ * Custom format string for Datetime values (e.g. "%Y-%m-%d %H:%M:%S").
22
+ */
23
+ datetimeFormat?: string;
24
+ /**
25
+ * Options for numeric formatting (floats, ints, bigints).
26
+ */
27
+ numericFormatOptions?: NumericFormatOptions;
28
+ /**
29
+ * Options for the safe JSON replacer used when formatting objects/arrays.
30
+ */
31
+ replacerOptions?: SafeJsonReplacerOptions;
32
+ }
33
+ export interface WriteCSVOptions extends FormatCSVValueOptions {
34
+ /**
35
+ * Whether to write the header row.
36
+ * @default true
37
+ */
38
+ includeHeader?: boolean;
39
+ /**
40
+ * Character that separates fields.
41
+ * @default ","
42
+ */
43
+ separator?: string;
44
+ /**
45
+ * The string used to end each row.
46
+ * @default "\n"
47
+ */
48
+ lineTerminator?: string;
49
+ /**
50
+ * The character used for quoting fields.
51
+ * @default '"'
52
+ */
53
+ quoteChar?: string;
54
+ /**
55
+ * Defines when to use quotes.
56
+ * - "necessary": Quotes only when required (e.g., value contains separator, quote_char, or newlines).
57
+ * - "always": Quotes every field.
58
+ * - "never": Never quotes fields.
59
+ * - "non_numeric": Quotes all fields that are non-numeric.
60
+ * @default "necessary"
61
+ */
62
+ quoteStyle?: "necessary" | "always" | "never" | "non_numeric";
63
+ /**
64
+ * Whether to include a Byte Order Mark (BOM) at the start of the file.
65
+ * @default false
66
+ */
67
+ includeBom?: boolean;
68
+ }
69
+ export declare function formatCsvValue(options?: FormatCSVValueOptions): (val: any) => string;
70
+ export declare function stringifyCSV(columns: ColumnDict, height: number, options?: WriteCSVOptions & {
71
+ onRow?: (rowStr: string) => void;
72
+ }): string;
73
+ export declare function parseCSV(content: string, options?: ReadCSVOptions): string[][];
74
+ export declare function inferAndCoerceCSVColumn(values: string[], options?: ReadCSVOptions): {
75
+ type: DataType;
76
+ values: any[];
77
+ };
@@ -5,7 +5,7 @@ import type { TimeUnit } from "../types";
5
5
  * - "12:34" (matches "12:34")
6
6
  * - "10:37:16.123" (matches "10:37")
7
7
  * - "2026-05-25" (does not match)
8
- */
8
+ * */
9
9
  export declare const TIME_PREFIX_REGEX: RegExp;
10
10
  /**
11
11
  * Matches timezone offset indicators at the end of a string.
@@ -18,40 +18,26 @@ export declare const TIME_PREFIX_REGEX: RegExp;
18
18
  */
19
19
  export declare const ZONE_OFFSET_REGEX: RegExp;
20
20
  /**
21
- * Matches only UTC offset indicators at the end of a string.
21
+ * Matches strict ISO 8601 date-only format (YYYY-MM-DD).
22
22
  * Examples:
23
- * - "12:34:56Z" (matches "Z")
24
- * - "12:34:56+00:00" (matches "+00:00")
25
- * - "12:34:56-0000" (matches "-0000")
26
- * - "12:34:56+02:00" (does not match)
23
+ * - "2026-05-25" (matches)
24
+ * - "2026-05-25T10:37:16Z" (does not match)
27
25
  */
28
- export declare const UTC_INDICATOR_REGEX: RegExp;
29
- export declare const MS_PER_SECOND = 1000;
30
- export declare const MS_PER_MINUTE = 60000;
31
- export declare const MS_PER_HOUR = 3600000;
32
- export declare const MS_PER_DAY = 86400000;
33
- export declare const US_PER_MS = 1000;
34
- export declare const NS_PER_MS = 1000000;
35
- export interface UtcOffsetResult {
36
- timeZoneTime: Date;
37
- utcTime: Date;
38
- offset: number;
39
- formatted: string;
40
- }
41
- export declare function toEpoch(d: Date, unit?: TimeUnit): number;
42
- export declare function getCentury(d: Date): number;
43
- export declare function getISOWeek(d: Date): number;
44
- export declare function getMillennium(d: Date): number;
45
- export declare function getMonthOffset(d: Date, monthOffset: number, day?: number): Date;
46
- export declare function getOrdinalDay(d: Date): number;
47
- export declare function getQuarter(d: Date): number;
48
- export declare function getUtcOffset(timeZone: string): UtcOffsetResult;
26
+ export declare const ISO_DATE_ONLY_REGEX: RegExp;
27
+ export declare function toValidDate(input: unknown, options?: {
28
+ dateOnly?: boolean;
29
+ }): Date | null;
30
+ export declare function toValidTime(val: unknown): string | null;
31
+ export declare function toEpoch(d: Date, unit?: TimeUnit): number | bigint;
32
+ export declare function normalizeEpochToMs(n: number | bigint): number;
33
+ export declare function getCentury(d: Date): number | null;
34
+ export declare function getISOWeek(d: Date): number | null;
35
+ export declare function getMillennium(d: Date): number | null;
36
+ export declare function getMonthOffset(d: Date, monthOffset: number, day?: number): Date | null;
37
+ export declare function getOrdinalDay(d: Date): number | null;
38
+ export declare function getQuarter(d: Date): number | null;
49
39
  export declare function isLeapYear(yOrDate: number | Date): boolean;
50
- export declare function isUtcString(timestamp: string | null | undefined): boolean;
51
- export declare function isValidDate(v: unknown): v is string | number | bigint | Date;
52
- export declare function isValidDateObj(d: unknown): d is Date;
53
- export declare function normalizeEpochToMs(n: number): number;
54
- export declare const STRFTIME_DIRECTIVES: readonly ["%ms", "%f", "%Y", "%y", "%m", "%d", "%e", "%H", "%I", "%p", "%M", "%S", "%A", "%a", "%B", "%b", "%h", "%j", "%u", "%w", "%Z", "%z"];
55
- export declare function strftime(d: Date, format: string, locale?: string): string;
56
- export declare function strptime(str: string, format: string, strict?: boolean): Date | null;
57
- export declare function toValidDate(input: unknown): Date | null;
40
+ export declare const FORMAT_REGEX: RegExp;
41
+ export declare function expandFormatShorthands(format: string): string;
42
+ export declare function strftime(d: Date, format: string, locale?: string, timeZone?: string): string;
43
+ export declare function strptime(str: string, format: string, strict?: boolean, defaultTimeZone?: string): Date | null;
@@ -1,14 +1,13 @@
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>;
1
+ import type { ValidScalarTypes } from "../types";
2
+ /** Array Guards **/
3
+ export type AnyTypedArray = ArrayBufferView & ArrayLike<number | bigint> & Iterable<number | bigint>;
4
+ export declare function isTypedArray(v: unknown): v is AnyTypedArray;
5
+ export declare function isArrayOrTypedArray(v: unknown): v is any[] | AnyTypedArray;
6
+ export declare function isObj(v: unknown): v is Record<PropertyKey, unknown>;
7
+ export declare function isPlainObj(v: unknown): v is Record<PropertyKey, unknown>;
8
+ /** Class Guards **/
8
9
  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>;
10
+ /** Scalar & Conversion Guards **/
11
+ export declare function isScalar<V>(v: V): v is Extract<V, Exclude<ValidScalarTypes, null | undefined>>;
12
+ export declare function isValidBinary(v: unknown): v is string | any[] | AnyTypedArray;
11
13
  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;
@@ -1,5 +1,8 @@
1
- export * from "./guards";
1
+ export * from "./object";
2
2
  export * from "./number";
3
3
  export * from "./date";
4
- export * from "./list";
4
+ export * from "./array";
5
5
  export * from "./string";
6
+ export * from "./json";
7
+ export * from "./csv";
8
+ export * from "./binary";
@@ -1,2 +1,120 @@
1
- export declare function isJsonString(input: unknown, allowPrimitives?: boolean): input is string;
2
- export declare function safeJsonParse(input: unknown): unknown;
1
+ import type { JSONFormat } from "../types";
2
+ export interface NDJSONParseOptions {
3
+ /**
4
+ * Skip malformed or invalid lines instead of failing the entire parse.
5
+ * @default false
6
+ */
7
+ skipInvalidLines?: boolean;
8
+ /**
9
+ * Maximum number of non-empty lines to validate or parse. Lines beyond this limit are ignored.
10
+ */
11
+ maxLines?: number;
12
+ /**
13
+ * Number of non-empty lines to skip at the beginning of the content.
14
+ * @default 0
15
+ */
16
+ skipLines?: number;
17
+ }
18
+ export interface JSONParseOptions {
19
+ /**
20
+ * The format of the JSON content, either "json" (standard JSON) or "ndjson" (Newline Delimited JSON).
21
+ * @default "json"
22
+ */
23
+ format?: JSONFormat;
24
+ /**
25
+ * Whether to allow JSON primitives (like numbers, booleans, strings, or null) instead of requiring wrapped arrays/objects.
26
+ * @default false
27
+ */
28
+ allowPrimitives?: boolean;
29
+ /**
30
+ * Whether to trim leading and trailing whitespace from the outermost input before validating/parsing.
31
+ * @default false
32
+ */
33
+ trimBeforeParse?: boolean;
34
+ /**
35
+ * A reviver function passed directly to JSON.parse for custom value transformation.
36
+ */
37
+ reviver?: Parameters<typeof JSON.parse>[1];
38
+ /**
39
+ * Options specific to NDJSON parsing. Only applicable when format is "ndjson".
40
+ */
41
+ ndjson?: NDJSONParseOptions;
42
+ }
43
+ export type SafeJsonParseOptions<T = unknown, F = T> = JSONParseOptions & {
44
+ /**
45
+ * A guard function to validate the shape of the parsed result. If the guard returns false,
46
+ * `onError` is called and the fallback (or original input) is returned.
47
+ */
48
+ guard?: ((value: unknown) => value is T) | ((value: unknown) => boolean);
49
+ /**
50
+ * Called when parsing succeeds but the guard check fails.
51
+ */
52
+ onError?: (err: unknown) => void;
53
+ /**
54
+ * A fallback value to return if parsing fails or the guard check fails.
55
+ * If not specified, the original input is returned.
56
+ */
57
+ fallback?: F;
58
+ };
59
+ /**
60
+ * Validates whether the given value is a valid JSON or NDJSON string.
61
+ * Leverages single-pass parsing under the hood to ensure zero duplicate loops.
62
+ *
63
+ * @param input - The value to check.
64
+ * @param options - Configuration options for validation.
65
+ * @returns `true` if the input is a valid JSON or NDJSON string; `false` otherwise.
66
+ */
67
+ export declare function isJsonString(input: unknown, options?: JSONParseOptions): input is string;
68
+ /**
69
+ * Safely parses a string containing JSON or NDJSON content in a single pass, returning the parsed value if successful
70
+ * and passing the guard validation. If parsing or validation fails, returns the fallback value (if provided)
71
+ * or the original input.
72
+ *
73
+ * @param input - The value to parse.
74
+ * @param options - Configuration options for parsing and validation.
75
+ * @returns The parsed value, the fallback, or the original input.
76
+ */
77
+ export declare function safeJsonParse<T = unknown, I = unknown, F = T>(input: I, { format, allowPrimitives, trimBeforeParse, reviver, ndjson: { skipInvalidLines, maxLines, skipLines }, guard, onError, fallback }?: SafeJsonParseOptions<T, F>): T | I | F;
78
+ export interface SafeJsonReplacerOptions {
79
+ /** Custom formatter function for Date objects. Ignored if onDate is specified. */
80
+ formatDate?: (v: Date) => string;
81
+ /** Convert BigInts to numeric strings ("123") or numbers if safe. Defaults to "string". */
82
+ bigintStrategy?: "string" | "number";
83
+ /** Custom serialization override for BigInt values. */
84
+ onBigInt?: (v: bigint) => any;
85
+ /** Custom serialization override for TypedArray values. */
86
+ onTypedArray?: (v: any) => any;
87
+ /** Custom serialization override for Set objects. */
88
+ onSet?: (v: Set<any>) => any;
89
+ /** Custom serialization override for Map objects. */
90
+ onMap?: (v: Map<any, any>) => any;
91
+ /** Custom serialization override for RegExp objects. */
92
+ onRegExp?: (v: RegExp) => any;
93
+ /** Custom serialization override for Date objects. Takes precedence over formatDate. */
94
+ onDate?: (v: Date) => any;
95
+ /** Custom serialization override for Error objects. Prevents empty {} strings. */
96
+ onError?: (v: Error) => any;
97
+ /** Custom serialization override for URLSearchParams objects. */
98
+ onURLSearchParams?: (v: URLSearchParams) => any;
99
+ /** Catch-all serialization override for custom types. Runs after native type checks. */
100
+ onCustom?: (this: any, k: string, v: any) => any;
101
+ /** If true, handles circular references by replacing them with a string/override instead of throwing. */
102
+ handleCircular?: boolean;
103
+ /** Custom fallback string or value when a circular reference is found. Defaults to "[Circular]" */
104
+ onCircular?: (this: any, k: string, v: any) => any;
105
+ /** If true, disables/voids the default safe serialization for BigInt values. */
106
+ voidBigIntReplacement?: boolean;
107
+ /** If true, disables/voids the default safe serialization for TypedArray values. */
108
+ voidTypedArrayReplacement?: boolean;
109
+ /** If true, disables/voids the default safe serialization for Set objects. */
110
+ voidSetReplacement?: boolean;
111
+ /** If true, disables/voids the default safe serialization for Map objects. */
112
+ voidMapReplacement?: boolean;
113
+ /** If true, disables/voids the default safe serialization for RegExp objects. */
114
+ voidRegExpReplacement?: boolean;
115
+ /** If true, disables/voids the default safe serialization for Date objects. */
116
+ voidDateReplacement?: boolean;
117
+ /** A custom replacer function or array whitelist that runs first for pre-processing keys/values. */
118
+ replacer?: ((this: any, k: string, v: any) => any) | (string | number)[] | null;
119
+ }
120
+ export declare function createSafeJsonReplacer(options?: SafeJsonReplacerOptions): (this: any, k: string, v: any) => any;