@nyaomaru/divider 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +14 -10
- package/dist/index.d.cts +83 -23
- package/dist/index.d.ts +83 -23
- package/dist/index.js +14 -10
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -348,6 +348,13 @@ function classifySeparators(args) {
|
|
|
348
348
|
);
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
+
// src/utils/transform-divider-input.ts
|
|
352
|
+
function transformDividerInput(input, transform, options) {
|
|
353
|
+
const result = isString(input) ? transform(input) : input.map(transform);
|
|
354
|
+
const resolvedOptions = options ?? {};
|
|
355
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
356
|
+
}
|
|
357
|
+
|
|
351
358
|
// src/core/divider.ts
|
|
352
359
|
function divider(input, ...args) {
|
|
353
360
|
if (!isValidInput(input)) {
|
|
@@ -364,8 +371,7 @@ function divider(input, ...args) {
|
|
|
364
371
|
const applyDivision = (str) => divideString(str, numSeparators, strSeparators, {
|
|
365
372
|
preserveEmpty: options.preserveEmpty
|
|
366
373
|
});
|
|
367
|
-
|
|
368
|
-
return applyDividerOptions(result, options);
|
|
374
|
+
return transformDividerInput(input, applyDivision, options);
|
|
369
375
|
}
|
|
370
376
|
|
|
371
377
|
// src/core/divider-first.ts
|
|
@@ -416,15 +422,15 @@ function dividerLoop(input, size, options) {
|
|
|
416
422
|
console.warn("dividerLoop: chunk size must be a positive number");
|
|
417
423
|
return [];
|
|
418
424
|
}
|
|
419
|
-
const resolvedOptions = options ?? {};
|
|
420
425
|
const {
|
|
421
426
|
startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
|
|
422
427
|
maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
|
|
423
|
-
} =
|
|
424
|
-
|
|
425
|
-
|
|
428
|
+
} = options ?? {};
|
|
429
|
+
return transformDividerInput(
|
|
430
|
+
input,
|
|
431
|
+
(str) => createChunksFromString(str, size, startOffset, maxChunks),
|
|
432
|
+
options
|
|
426
433
|
);
|
|
427
|
-
return applyDividerOptions(result, resolvedOptions);
|
|
428
434
|
}
|
|
429
435
|
|
|
430
436
|
// src/utils/divide.ts
|
|
@@ -434,9 +440,7 @@ function divideNumberString(str) {
|
|
|
434
440
|
|
|
435
441
|
// src/core/divider-number-string.ts
|
|
436
442
|
function dividerNumberString(input, options) {
|
|
437
|
-
|
|
438
|
-
const resolvedOptions = options ?? {};
|
|
439
|
-
return applyDividerOptions(result, resolvedOptions);
|
|
443
|
+
return transformDividerInput(input, divideNumberString, options);
|
|
440
444
|
}
|
|
441
445
|
|
|
442
446
|
// src/utils/quoted.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -21,21 +21,42 @@ declare const QUERY_DECODE_MODES: {
|
|
|
21
21
|
readonly RAW: "raw";
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Supported exclusion modes used to filter divider output.
|
|
26
|
+
*/
|
|
24
27
|
type DividerExcludeMode = (typeof DIVIDER_EXCLUDE_MODES)[keyof typeof DIVIDER_EXCLUDE_MODES];
|
|
28
|
+
/**
|
|
29
|
+
* Single string input accepted by divider functions.
|
|
30
|
+
*/
|
|
25
31
|
type StringInput = string;
|
|
32
|
+
/**
|
|
33
|
+
* Readonly string array input accepted by divider functions.
|
|
34
|
+
*/
|
|
26
35
|
type StringArrayInput = readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* Supported input shapes for divider functions.
|
|
38
|
+
*/
|
|
27
39
|
type DividerInput = StringInput | StringArrayInput;
|
|
40
|
+
/**
|
|
41
|
+
* Flat divider result.
|
|
42
|
+
*/
|
|
28
43
|
type DividerStringResult = string[];
|
|
44
|
+
/**
|
|
45
|
+
* Nested divider result for `string[]` inputs when `flatten` is not enabled.
|
|
46
|
+
*/
|
|
29
47
|
type DividerArrayResult = string[][];
|
|
48
|
+
/**
|
|
49
|
+
* Shared options supported by divider functions.
|
|
50
|
+
*/
|
|
30
51
|
type DividerOptions = {
|
|
31
52
|
/** If true, flattens nested arrays into a single array */
|
|
32
|
-
flatten?: boolean;
|
|
53
|
+
readonly flatten?: boolean;
|
|
33
54
|
/** If true, trims whitespace from each divided segment */
|
|
34
|
-
trim?: boolean;
|
|
55
|
+
readonly trim?: boolean;
|
|
35
56
|
/** If true, retains empty segments produced by division */
|
|
36
|
-
preserveEmpty?: boolean;
|
|
57
|
+
readonly preserveEmpty?: boolean;
|
|
37
58
|
/** Controls how empty or whitespace segments are handled */
|
|
38
|
-
exclude?: DividerExcludeMode;
|
|
59
|
+
readonly exclude?: DividerExcludeMode;
|
|
39
60
|
};
|
|
40
61
|
/**
|
|
41
62
|
* Represents the absence of user-specified divider options while retaining
|
|
@@ -52,37 +73,76 @@ type DividerEmptyOptions = {
|
|
|
52
73
|
readonly exclude?: never;
|
|
53
74
|
};
|
|
54
75
|
type DividerInferredOptions = DividerOptions | DividerEmptyOptions;
|
|
55
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Computes whether the provided options explicitly enable `flatten`.
|
|
78
|
+
*/
|
|
79
|
+
type IsFlattenEnabled<TOptions extends DividerInferredOptions> = TOptions extends {
|
|
56
80
|
readonly flatten?: infer Flag;
|
|
57
|
-
} ? Flag extends true ? true : false : false;
|
|
58
|
-
|
|
81
|
+
} ? [Flag] extends [true] ? true : false : false;
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the divider output shape from the input and options.
|
|
84
|
+
*/
|
|
85
|
+
type DividerResult<T extends DividerInput, TOptions extends DividerInferredOptions = DividerEmptyOptions> = T extends StringInput ? DividerStringResult : IsFlattenEnabled<TOptions> extends true ? DividerStringResult : DividerArrayResult;
|
|
86
|
+
/**
|
|
87
|
+
* Numeric separator interpreted as an index.
|
|
88
|
+
*/
|
|
89
|
+
type NumericSeparator = number;
|
|
90
|
+
/**
|
|
91
|
+
* String separator interpreted as a delimiter.
|
|
92
|
+
*/
|
|
93
|
+
type StringSeparator = string;
|
|
94
|
+
/**
|
|
95
|
+
* Any supported divider separator.
|
|
96
|
+
*/
|
|
97
|
+
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
98
|
+
/**
|
|
99
|
+
* A readonly list of separators without options.
|
|
100
|
+
*/
|
|
101
|
+
type DividerSeparators = readonly DividerSeparator[];
|
|
102
|
+
/**
|
|
103
|
+
* Any single divider argument.
|
|
104
|
+
*/
|
|
105
|
+
type DividerArg = DividerSeparator | DividerOptions;
|
|
106
|
+
/**
|
|
107
|
+
* Divider arguments with an optional trailing options object.
|
|
108
|
+
*
|
|
109
|
+
* WHY: Runtime only consumes options when they are passed last. This tuple
|
|
110
|
+
* shape keeps the public type contract aligned with that behavior.
|
|
111
|
+
*/
|
|
112
|
+
type DividerArgs = DividerSeparators | readonly [...DividerSeparator[], DividerOptions];
|
|
113
|
+
/**
|
|
114
|
+
* Extracts trailing divider options from a variadic argument tuple.
|
|
115
|
+
*/
|
|
116
|
+
type ExtractedDividerOptions<TArgs extends readonly unknown[]> = TArgs extends readonly [...unknown[], infer Last] ? Last extends DividerOptions ? Last : DividerEmptyOptions : DividerEmptyOptions;
|
|
59
117
|
/**
|
|
60
118
|
* Computes the divider return type based on the input and provided arguments.
|
|
61
119
|
*
|
|
62
120
|
* WHY: When no arguments are provided, divider returns the input as-is for
|
|
63
121
|
* string arrays. This type keeps the signature aligned with runtime behavior.
|
|
64
122
|
*/
|
|
65
|
-
type DividerReturn<T extends DividerInput, TArgs extends DividerArgs> = T extends StringInput ? DividerStringResult : TArgs['length'] extends 0 ? T :
|
|
66
|
-
|
|
123
|
+
type DividerReturn<T extends DividerInput, TArgs extends DividerArgs> = T extends StringInput ? DividerStringResult : TArgs['length'] extends 0 ? T : IsFlattenEnabled<ExtractedDividerOptions<TArgs>> extends true ? DividerStringResult : DividerArrayResult;
|
|
124
|
+
/**
|
|
125
|
+
* Additional options supported by `dividerLoop`.
|
|
126
|
+
*/
|
|
67
127
|
type DividerLoopOptions = DividerOptions & {
|
|
68
128
|
/** Starting position for the division (0-based) */
|
|
69
|
-
startOffset?: number;
|
|
129
|
+
readonly startOffset?: number;
|
|
70
130
|
/** Maximum number of chunks to produce */
|
|
71
|
-
maxChunks?: number;
|
|
131
|
+
readonly maxChunks?: number;
|
|
72
132
|
};
|
|
133
|
+
/**
|
|
134
|
+
* Represents the absence of loop-specific options while preserving inference.
|
|
135
|
+
*/
|
|
73
136
|
type DividerLoopEmptyOptions = DividerEmptyOptions & {
|
|
74
137
|
/** Placeholder to signal startOffset is intentionally absent */
|
|
75
138
|
readonly startOffset?: never;
|
|
76
139
|
/** Placeholder to signal maxChunks is intentionally absent */
|
|
77
140
|
readonly maxChunks?: never;
|
|
78
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Accepted option shapes for `dividerLoop`.
|
|
144
|
+
*/
|
|
79
145
|
type DividerLoopOptionsLike = DividerLoopOptions | DividerLoopEmptyOptions;
|
|
80
|
-
type NumericSeparator = number;
|
|
81
|
-
type StringSeparator = string;
|
|
82
|
-
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
83
|
-
type DividerSeparators = readonly DividerSeparator[];
|
|
84
|
-
type DividerArg = DividerSeparator | DividerOptions;
|
|
85
|
-
type DividerArgs = readonly DividerArg[];
|
|
86
146
|
|
|
87
147
|
/**
|
|
88
148
|
* Main divider function that splits input based on numeric positions or string delimiters.
|
|
@@ -96,7 +156,7 @@ type DividerArgs = readonly DividerArg[];
|
|
|
96
156
|
* @param args - Array of separators (numbers/strings) and optional options object
|
|
97
157
|
* @returns Divided string segments based on input type and options
|
|
98
158
|
*/
|
|
99
|
-
declare function divider<T extends DividerInput, const TArgs extends
|
|
159
|
+
declare function divider<T extends DividerInput, const TArgs extends DividerArgs>(input: T, ...args: TArgs): DividerReturn<T, TArgs>;
|
|
100
160
|
|
|
101
161
|
/**
|
|
102
162
|
* Extracts the first segment after dividing the input using specified separators.
|
|
@@ -160,22 +220,22 @@ declare function dividerNumberString<T extends DividerInput, O extends DividerIn
|
|
|
160
220
|
|
|
161
221
|
type EmailDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
162
222
|
/** Split top-level domain from the rest of the email address. */
|
|
163
|
-
splitTLD?: boolean;
|
|
223
|
+
readonly splitTLD?: boolean;
|
|
164
224
|
};
|
|
165
225
|
type CsvDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
166
226
|
/** Character used for quoting values. */
|
|
167
|
-
quoteChar?: string;
|
|
227
|
+
readonly quoteChar?: string;
|
|
168
228
|
/** Character used to separate CSV fields. */
|
|
169
|
-
delimiter?: string;
|
|
229
|
+
readonly delimiter?: string;
|
|
170
230
|
};
|
|
171
231
|
type PathDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
172
232
|
/** Collapse empty segments produced by leading/trailing or repeated separators. */
|
|
173
|
-
collapse?: boolean;
|
|
233
|
+
readonly collapse?: boolean;
|
|
174
234
|
};
|
|
175
235
|
type QueryDecodeMode = (typeof QUERY_DECODE_MODES)[keyof typeof QUERY_DECODE_MODES];
|
|
176
236
|
type QueryDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
177
237
|
/** Decoding mode: 'auto' applies standard URL decoding; 'raw' leaves values untouched. */
|
|
178
|
-
mode?: QueryDecodeMode;
|
|
238
|
+
readonly mode?: QueryDecodeMode;
|
|
179
239
|
};
|
|
180
240
|
|
|
181
241
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -21,21 +21,42 @@ declare const QUERY_DECODE_MODES: {
|
|
|
21
21
|
readonly RAW: "raw";
|
|
22
22
|
};
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Supported exclusion modes used to filter divider output.
|
|
26
|
+
*/
|
|
24
27
|
type DividerExcludeMode = (typeof DIVIDER_EXCLUDE_MODES)[keyof typeof DIVIDER_EXCLUDE_MODES];
|
|
28
|
+
/**
|
|
29
|
+
* Single string input accepted by divider functions.
|
|
30
|
+
*/
|
|
25
31
|
type StringInput = string;
|
|
32
|
+
/**
|
|
33
|
+
* Readonly string array input accepted by divider functions.
|
|
34
|
+
*/
|
|
26
35
|
type StringArrayInput = readonly string[];
|
|
36
|
+
/**
|
|
37
|
+
* Supported input shapes for divider functions.
|
|
38
|
+
*/
|
|
27
39
|
type DividerInput = StringInput | StringArrayInput;
|
|
40
|
+
/**
|
|
41
|
+
* Flat divider result.
|
|
42
|
+
*/
|
|
28
43
|
type DividerStringResult = string[];
|
|
44
|
+
/**
|
|
45
|
+
* Nested divider result for `string[]` inputs when `flatten` is not enabled.
|
|
46
|
+
*/
|
|
29
47
|
type DividerArrayResult = string[][];
|
|
48
|
+
/**
|
|
49
|
+
* Shared options supported by divider functions.
|
|
50
|
+
*/
|
|
30
51
|
type DividerOptions = {
|
|
31
52
|
/** If true, flattens nested arrays into a single array */
|
|
32
|
-
flatten?: boolean;
|
|
53
|
+
readonly flatten?: boolean;
|
|
33
54
|
/** If true, trims whitespace from each divided segment */
|
|
34
|
-
trim?: boolean;
|
|
55
|
+
readonly trim?: boolean;
|
|
35
56
|
/** If true, retains empty segments produced by division */
|
|
36
|
-
preserveEmpty?: boolean;
|
|
57
|
+
readonly preserveEmpty?: boolean;
|
|
37
58
|
/** Controls how empty or whitespace segments are handled */
|
|
38
|
-
exclude?: DividerExcludeMode;
|
|
59
|
+
readonly exclude?: DividerExcludeMode;
|
|
39
60
|
};
|
|
40
61
|
/**
|
|
41
62
|
* Represents the absence of user-specified divider options while retaining
|
|
@@ -52,37 +73,76 @@ type DividerEmptyOptions = {
|
|
|
52
73
|
readonly exclude?: never;
|
|
53
74
|
};
|
|
54
75
|
type DividerInferredOptions = DividerOptions | DividerEmptyOptions;
|
|
55
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Computes whether the provided options explicitly enable `flatten`.
|
|
78
|
+
*/
|
|
79
|
+
type IsFlattenEnabled<TOptions extends DividerInferredOptions> = TOptions extends {
|
|
56
80
|
readonly flatten?: infer Flag;
|
|
57
|
-
} ? Flag extends true ? true : false : false;
|
|
58
|
-
|
|
81
|
+
} ? [Flag] extends [true] ? true : false : false;
|
|
82
|
+
/**
|
|
83
|
+
* Resolves the divider output shape from the input and options.
|
|
84
|
+
*/
|
|
85
|
+
type DividerResult<T extends DividerInput, TOptions extends DividerInferredOptions = DividerEmptyOptions> = T extends StringInput ? DividerStringResult : IsFlattenEnabled<TOptions> extends true ? DividerStringResult : DividerArrayResult;
|
|
86
|
+
/**
|
|
87
|
+
* Numeric separator interpreted as an index.
|
|
88
|
+
*/
|
|
89
|
+
type NumericSeparator = number;
|
|
90
|
+
/**
|
|
91
|
+
* String separator interpreted as a delimiter.
|
|
92
|
+
*/
|
|
93
|
+
type StringSeparator = string;
|
|
94
|
+
/**
|
|
95
|
+
* Any supported divider separator.
|
|
96
|
+
*/
|
|
97
|
+
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
98
|
+
/**
|
|
99
|
+
* A readonly list of separators without options.
|
|
100
|
+
*/
|
|
101
|
+
type DividerSeparators = readonly DividerSeparator[];
|
|
102
|
+
/**
|
|
103
|
+
* Any single divider argument.
|
|
104
|
+
*/
|
|
105
|
+
type DividerArg = DividerSeparator | DividerOptions;
|
|
106
|
+
/**
|
|
107
|
+
* Divider arguments with an optional trailing options object.
|
|
108
|
+
*
|
|
109
|
+
* WHY: Runtime only consumes options when they are passed last. This tuple
|
|
110
|
+
* shape keeps the public type contract aligned with that behavior.
|
|
111
|
+
*/
|
|
112
|
+
type DividerArgs = DividerSeparators | readonly [...DividerSeparator[], DividerOptions];
|
|
113
|
+
/**
|
|
114
|
+
* Extracts trailing divider options from a variadic argument tuple.
|
|
115
|
+
*/
|
|
116
|
+
type ExtractedDividerOptions<TArgs extends readonly unknown[]> = TArgs extends readonly [...unknown[], infer Last] ? Last extends DividerOptions ? Last : DividerEmptyOptions : DividerEmptyOptions;
|
|
59
117
|
/**
|
|
60
118
|
* Computes the divider return type based on the input and provided arguments.
|
|
61
119
|
*
|
|
62
120
|
* WHY: When no arguments are provided, divider returns the input as-is for
|
|
63
121
|
* string arrays. This type keeps the signature aligned with runtime behavior.
|
|
64
122
|
*/
|
|
65
|
-
type DividerReturn<T extends DividerInput, TArgs extends DividerArgs> = T extends StringInput ? DividerStringResult : TArgs['length'] extends 0 ? T :
|
|
66
|
-
|
|
123
|
+
type DividerReturn<T extends DividerInput, TArgs extends DividerArgs> = T extends StringInput ? DividerStringResult : TArgs['length'] extends 0 ? T : IsFlattenEnabled<ExtractedDividerOptions<TArgs>> extends true ? DividerStringResult : DividerArrayResult;
|
|
124
|
+
/**
|
|
125
|
+
* Additional options supported by `dividerLoop`.
|
|
126
|
+
*/
|
|
67
127
|
type DividerLoopOptions = DividerOptions & {
|
|
68
128
|
/** Starting position for the division (0-based) */
|
|
69
|
-
startOffset?: number;
|
|
129
|
+
readonly startOffset?: number;
|
|
70
130
|
/** Maximum number of chunks to produce */
|
|
71
|
-
maxChunks?: number;
|
|
131
|
+
readonly maxChunks?: number;
|
|
72
132
|
};
|
|
133
|
+
/**
|
|
134
|
+
* Represents the absence of loop-specific options while preserving inference.
|
|
135
|
+
*/
|
|
73
136
|
type DividerLoopEmptyOptions = DividerEmptyOptions & {
|
|
74
137
|
/** Placeholder to signal startOffset is intentionally absent */
|
|
75
138
|
readonly startOffset?: never;
|
|
76
139
|
/** Placeholder to signal maxChunks is intentionally absent */
|
|
77
140
|
readonly maxChunks?: never;
|
|
78
141
|
};
|
|
142
|
+
/**
|
|
143
|
+
* Accepted option shapes for `dividerLoop`.
|
|
144
|
+
*/
|
|
79
145
|
type DividerLoopOptionsLike = DividerLoopOptions | DividerLoopEmptyOptions;
|
|
80
|
-
type NumericSeparator = number;
|
|
81
|
-
type StringSeparator = string;
|
|
82
|
-
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
83
|
-
type DividerSeparators = readonly DividerSeparator[];
|
|
84
|
-
type DividerArg = DividerSeparator | DividerOptions;
|
|
85
|
-
type DividerArgs = readonly DividerArg[];
|
|
86
146
|
|
|
87
147
|
/**
|
|
88
148
|
* Main divider function that splits input based on numeric positions or string delimiters.
|
|
@@ -96,7 +156,7 @@ type DividerArgs = readonly DividerArg[];
|
|
|
96
156
|
* @param args - Array of separators (numbers/strings) and optional options object
|
|
97
157
|
* @returns Divided string segments based on input type and options
|
|
98
158
|
*/
|
|
99
|
-
declare function divider<T extends DividerInput, const TArgs extends
|
|
159
|
+
declare function divider<T extends DividerInput, const TArgs extends DividerArgs>(input: T, ...args: TArgs): DividerReturn<T, TArgs>;
|
|
100
160
|
|
|
101
161
|
/**
|
|
102
162
|
* Extracts the first segment after dividing the input using specified separators.
|
|
@@ -160,22 +220,22 @@ declare function dividerNumberString<T extends DividerInput, O extends DividerIn
|
|
|
160
220
|
|
|
161
221
|
type EmailDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
162
222
|
/** Split top-level domain from the rest of the email address. */
|
|
163
|
-
splitTLD?: boolean;
|
|
223
|
+
readonly splitTLD?: boolean;
|
|
164
224
|
};
|
|
165
225
|
type CsvDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
166
226
|
/** Character used for quoting values. */
|
|
167
|
-
quoteChar?: string;
|
|
227
|
+
readonly quoteChar?: string;
|
|
168
228
|
/** Character used to separate CSV fields. */
|
|
169
|
-
delimiter?: string;
|
|
229
|
+
readonly delimiter?: string;
|
|
170
230
|
};
|
|
171
231
|
type PathDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
172
232
|
/** Collapse empty segments produced by leading/trailing or repeated separators. */
|
|
173
|
-
collapse?: boolean;
|
|
233
|
+
readonly collapse?: boolean;
|
|
174
234
|
};
|
|
175
235
|
type QueryDecodeMode = (typeof QUERY_DECODE_MODES)[keyof typeof QUERY_DECODE_MODES];
|
|
176
236
|
type QueryDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
177
237
|
/** Decoding mode: 'auto' applies standard URL decoding; 'raw' leaves values untouched. */
|
|
178
|
-
mode?: QueryDecodeMode;
|
|
238
|
+
readonly mode?: QueryDecodeMode;
|
|
179
239
|
};
|
|
180
240
|
|
|
181
241
|
/**
|
package/dist/index.js
CHANGED
|
@@ -314,6 +314,13 @@ function classifySeparators(args) {
|
|
|
314
314
|
);
|
|
315
315
|
}
|
|
316
316
|
|
|
317
|
+
// src/utils/transform-divider-input.ts
|
|
318
|
+
function transformDividerInput(input, transform, options) {
|
|
319
|
+
const result = isString(input) ? transform(input) : input.map(transform);
|
|
320
|
+
const resolvedOptions = options ?? {};
|
|
321
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
322
|
+
}
|
|
323
|
+
|
|
317
324
|
// src/core/divider.ts
|
|
318
325
|
function divider(input, ...args) {
|
|
319
326
|
if (!isValidInput(input)) {
|
|
@@ -330,8 +337,7 @@ function divider(input, ...args) {
|
|
|
330
337
|
const applyDivision = (str) => divideString(str, numSeparators, strSeparators, {
|
|
331
338
|
preserveEmpty: options.preserveEmpty
|
|
332
339
|
});
|
|
333
|
-
|
|
334
|
-
return applyDividerOptions(result, options);
|
|
340
|
+
return transformDividerInput(input, applyDivision, options);
|
|
335
341
|
}
|
|
336
342
|
|
|
337
343
|
// src/core/divider-first.ts
|
|
@@ -382,15 +388,15 @@ function dividerLoop(input, size, options) {
|
|
|
382
388
|
console.warn("dividerLoop: chunk size must be a positive number");
|
|
383
389
|
return [];
|
|
384
390
|
}
|
|
385
|
-
const resolvedOptions = options ?? {};
|
|
386
391
|
const {
|
|
387
392
|
startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
|
|
388
393
|
maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
|
|
389
|
-
} =
|
|
390
|
-
|
|
391
|
-
|
|
394
|
+
} = options ?? {};
|
|
395
|
+
return transformDividerInput(
|
|
396
|
+
input,
|
|
397
|
+
(str) => createChunksFromString(str, size, startOffset, maxChunks),
|
|
398
|
+
options
|
|
392
399
|
);
|
|
393
|
-
return applyDividerOptions(result, resolvedOptions);
|
|
394
400
|
}
|
|
395
401
|
|
|
396
402
|
// src/utils/divide.ts
|
|
@@ -400,9 +406,7 @@ function divideNumberString(str) {
|
|
|
400
406
|
|
|
401
407
|
// src/core/divider-number-string.ts
|
|
402
408
|
function dividerNumberString(input, options) {
|
|
403
|
-
|
|
404
|
-
const resolvedOptions = options ?? {};
|
|
405
|
-
return applyDividerOptions(result, resolvedOptions);
|
|
409
|
+
return transformDividerInput(input, divideNumberString, options);
|
|
406
410
|
}
|
|
407
411
|
|
|
408
412
|
// src/utils/quoted.ts
|