@nyaomaru/divider 1.9.12 → 1.9.14
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/README.md +1 -1
- package/dist/index.cjs +9 -5
- package/dist/index.d.cts +31 -6
- package/dist/index.d.ts +31 -6
- package/dist/index.js +9 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
<img src="https://img.shields.io/npm/v/@nyaomaru/divider.svg?sanitize=true" alt="npm version">
|
|
10
10
|
</a>
|
|
11
11
|
<a href="https://jsr.io/@nyaomaru/divider">
|
|
12
|
-
<img src="https://img.shields.io/
|
|
12
|
+
<img src="https://img.shields.io/jsr/v/@nyaomaru/divider" alt="JSR">
|
|
13
13
|
</a>
|
|
14
14
|
<a href="https://github.com/nyaomaru/divider/blob/main/LICENSE">
|
|
15
15
|
<img src="https://img.shields.io/npm/l/@nyaomaru/divider.svg?sanitize=true" alt="License">
|
package/dist/index.cjs
CHANGED
|
@@ -327,7 +327,10 @@ function divider(input, ...args) {
|
|
|
327
327
|
preserveEmpty: options.preserveEmpty
|
|
328
328
|
});
|
|
329
329
|
const result = isString(input) ? applyDivision(input) : input.map(applyDivision);
|
|
330
|
-
return applyDividerOptions(
|
|
330
|
+
return applyDividerOptions(
|
|
331
|
+
result,
|
|
332
|
+
options
|
|
333
|
+
);
|
|
331
334
|
}
|
|
332
335
|
|
|
333
336
|
// src/core/divider-first.ts
|
|
@@ -378,15 +381,15 @@ function dividerLoop(input, size, options) {
|
|
|
378
381
|
console.warn("dividerLoop: chunk size must be a positive number");
|
|
379
382
|
return [];
|
|
380
383
|
}
|
|
381
|
-
const
|
|
384
|
+
const resolvedOptions = options ?? {};
|
|
382
385
|
const {
|
|
383
386
|
startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
|
|
384
387
|
maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
|
|
385
|
-
} =
|
|
388
|
+
} = resolvedOptions;
|
|
386
389
|
const result = isString(input) ? createChunksFromString(input, size, startOffset, maxChunks) : input.map(
|
|
387
390
|
(str) => createChunksFromString(str, size, startOffset, maxChunks)
|
|
388
391
|
);
|
|
389
|
-
return applyDividerOptions(result,
|
|
392
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
390
393
|
}
|
|
391
394
|
|
|
392
395
|
// src/utils/divide.ts
|
|
@@ -397,7 +400,8 @@ function divideNumberString(str) {
|
|
|
397
400
|
// src/core/divider-number-string.ts
|
|
398
401
|
function dividerNumberString(input, options) {
|
|
399
402
|
const result = isString(input) ? divideNumberString(input) : input.map(divideNumberString);
|
|
400
|
-
|
|
403
|
+
const resolvedOptions = options ?? {};
|
|
404
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
401
405
|
}
|
|
402
406
|
|
|
403
407
|
// src/utils/quoted.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -20,7 +20,6 @@ type StringArrayInput = readonly string[];
|
|
|
20
20
|
type DividerInput = StringInput | StringArrayInput;
|
|
21
21
|
type DividerStringResult = string[];
|
|
22
22
|
type DividerArrayResult = string[][];
|
|
23
|
-
type DividerResult<T extends DividerInput> = T extends StringInput ? DividerStringResult : DividerArrayResult;
|
|
24
23
|
type DividerOptions = {
|
|
25
24
|
/** If true, flattens nested arrays into a single array */
|
|
26
25
|
flatten?: boolean;
|
|
@@ -31,17 +30,43 @@ type DividerOptions = {
|
|
|
31
30
|
/** Controls how empty or whitespace segments are handled */
|
|
32
31
|
exclude?: DividerExcludeMode;
|
|
33
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Represents the absence of user-specified divider options while retaining
|
|
35
|
+
* property knowledge for conditional typing.
|
|
36
|
+
*/
|
|
37
|
+
type DividerEmptyOptions = {
|
|
38
|
+
/** Explicitly omits flatten while preserving literal inference */
|
|
39
|
+
readonly flatten?: never;
|
|
40
|
+
/** Explicitly omits trim while preserving literal inference */
|
|
41
|
+
readonly trim?: never;
|
|
42
|
+
/** Explicitly omits preserveEmpty while preserving literal inference */
|
|
43
|
+
readonly preserveEmpty?: never;
|
|
44
|
+
/** Explicitly omits exclude while preserving literal inference */
|
|
45
|
+
readonly exclude?: never;
|
|
46
|
+
};
|
|
47
|
+
type DividerInferredOptions = DividerOptions | DividerEmptyOptions;
|
|
48
|
+
type HasFlattenOption<TOptions extends DividerInferredOptions> = TOptions extends {
|
|
49
|
+
readonly flatten?: infer Flag;
|
|
50
|
+
} ? Flag extends true ? true : false : false;
|
|
51
|
+
type DividerResult<T extends DividerInput, TOptions extends DividerInferredOptions = DividerEmptyOptions> = T extends StringInput ? DividerStringResult : HasFlattenOption<TOptions> extends true ? DividerStringResult : DividerArrayResult;
|
|
52
|
+
type ExtractedDividerOptions<TArgs extends readonly (string | number | DividerOptions)[]> = TArgs extends readonly [...infer _Rest, infer Last] ? Last extends DividerOptions ? Last : DividerEmptyOptions : DividerEmptyOptions;
|
|
34
53
|
type DividerLoopOptions = DividerOptions & {
|
|
35
54
|
/** Starting position for the division (0-based) */
|
|
36
55
|
startOffset?: number;
|
|
37
56
|
/** Maximum number of chunks to produce */
|
|
38
57
|
maxChunks?: number;
|
|
39
58
|
};
|
|
59
|
+
type DividerLoopEmptyOptions = DividerEmptyOptions & {
|
|
60
|
+
/** Placeholder to signal startOffset is intentionally absent */
|
|
61
|
+
readonly startOffset?: never;
|
|
62
|
+
/** Placeholder to signal maxChunks is intentionally absent */
|
|
63
|
+
readonly maxChunks?: never;
|
|
64
|
+
};
|
|
65
|
+
type DividerLoopOptionsLike = DividerLoopOptions | DividerLoopEmptyOptions;
|
|
40
66
|
type NumericSeparator = number;
|
|
41
67
|
type StringSeparator = string;
|
|
42
68
|
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
43
69
|
type DividerSeparators = DividerSeparator[];
|
|
44
|
-
type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
|
|
45
70
|
|
|
46
71
|
/**
|
|
47
72
|
* Main divider function that splits input based on numeric positions or string delimiters.
|
|
@@ -55,7 +80,7 @@ type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
|
|
|
55
80
|
* @param args - Array of separators (numbers/strings) and optional options object
|
|
56
81
|
* @returns Divided string segments based on input type and options
|
|
57
82
|
*/
|
|
58
|
-
declare function divider<T extends DividerInput>(input: T, ...args:
|
|
83
|
+
declare function divider<T extends DividerInput, const TArgs extends readonly (DividerSeparator | DividerOptions)[]>(input: T, ...args: TArgs): DividerResult<T, ExtractedDividerOptions<TArgs>>;
|
|
59
84
|
|
|
60
85
|
/**
|
|
61
86
|
* Extracts the first segment after dividing the input using specified separators.
|
|
@@ -100,7 +125,7 @@ declare function dividerLast(input: DividerInput, ...args: DividerSeparators): s
|
|
|
100
125
|
* dividerLoop("abcdef", 2) // returns ["ab", "cd", "ef"]
|
|
101
126
|
* dividerLoop("abcdef", 2, { maxChunks: 2 }) // returns ["ab", "cdef"]
|
|
102
127
|
*/
|
|
103
|
-
declare function dividerLoop<T extends DividerInput>(input: T, size: number, options?:
|
|
128
|
+
declare function dividerLoop<T extends DividerInput, O extends DividerLoopOptionsLike = DividerLoopEmptyOptions>(input: T, size: number, options?: O): DividerResult<T, O>;
|
|
104
129
|
|
|
105
130
|
/**
|
|
106
131
|
* Divides a string or array of strings by separating numbers from non-numbers.
|
|
@@ -115,7 +140,7 @@ declare function dividerLoop<T extends DividerInput>(input: T, size: number, opt
|
|
|
115
140
|
* dividerNumberString("abc123def") // returns ["abc", "123", "def"]
|
|
116
141
|
* dividerNumberString("test42") // returns ["test", "42"]
|
|
117
142
|
*/
|
|
118
|
-
declare function dividerNumberString<T extends DividerInput>(input: T, options?:
|
|
143
|
+
declare function dividerNumberString<T extends DividerInput, O extends DividerInferredOptions = DividerEmptyOptions>(input: T, options?: O): DividerResult<T, O>;
|
|
119
144
|
|
|
120
145
|
type EmailDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
121
146
|
/** Split top-level domain from the rest of the email address. */
|
|
@@ -163,4 +188,4 @@ declare function emailDivider(input: string, options?: EmailDividerOptions): Div
|
|
|
163
188
|
*/
|
|
164
189
|
declare function pathDivider(input: string, options?: PathDividerOptions): DividerStringResult;
|
|
165
190
|
|
|
166
|
-
export { type
|
|
191
|
+
export { type DividerArrayResult, type DividerEmptyOptions, type DividerExcludeMode, type DividerInferredOptions, type DividerInput, type DividerLoopEmptyOptions, type DividerLoopOptions, type DividerLoopOptionsLike, type DividerOptions, type DividerResult, type DividerSeparator, type DividerSeparators, type DividerStringResult, type ExtractedDividerOptions, type NumericSeparator, type StringArrayInput, type StringInput, type StringSeparator, csvDivider, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString, emailDivider, pathDivider };
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ type StringArrayInput = readonly string[];
|
|
|
20
20
|
type DividerInput = StringInput | StringArrayInput;
|
|
21
21
|
type DividerStringResult = string[];
|
|
22
22
|
type DividerArrayResult = string[][];
|
|
23
|
-
type DividerResult<T extends DividerInput> = T extends StringInput ? DividerStringResult : DividerArrayResult;
|
|
24
23
|
type DividerOptions = {
|
|
25
24
|
/** If true, flattens nested arrays into a single array */
|
|
26
25
|
flatten?: boolean;
|
|
@@ -31,17 +30,43 @@ type DividerOptions = {
|
|
|
31
30
|
/** Controls how empty or whitespace segments are handled */
|
|
32
31
|
exclude?: DividerExcludeMode;
|
|
33
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Represents the absence of user-specified divider options while retaining
|
|
35
|
+
* property knowledge for conditional typing.
|
|
36
|
+
*/
|
|
37
|
+
type DividerEmptyOptions = {
|
|
38
|
+
/** Explicitly omits flatten while preserving literal inference */
|
|
39
|
+
readonly flatten?: never;
|
|
40
|
+
/** Explicitly omits trim while preserving literal inference */
|
|
41
|
+
readonly trim?: never;
|
|
42
|
+
/** Explicitly omits preserveEmpty while preserving literal inference */
|
|
43
|
+
readonly preserveEmpty?: never;
|
|
44
|
+
/** Explicitly omits exclude while preserving literal inference */
|
|
45
|
+
readonly exclude?: never;
|
|
46
|
+
};
|
|
47
|
+
type DividerInferredOptions = DividerOptions | DividerEmptyOptions;
|
|
48
|
+
type HasFlattenOption<TOptions extends DividerInferredOptions> = TOptions extends {
|
|
49
|
+
readonly flatten?: infer Flag;
|
|
50
|
+
} ? Flag extends true ? true : false : false;
|
|
51
|
+
type DividerResult<T extends DividerInput, TOptions extends DividerInferredOptions = DividerEmptyOptions> = T extends StringInput ? DividerStringResult : HasFlattenOption<TOptions> extends true ? DividerStringResult : DividerArrayResult;
|
|
52
|
+
type ExtractedDividerOptions<TArgs extends readonly (string | number | DividerOptions)[]> = TArgs extends readonly [...infer _Rest, infer Last] ? Last extends DividerOptions ? Last : DividerEmptyOptions : DividerEmptyOptions;
|
|
34
53
|
type DividerLoopOptions = DividerOptions & {
|
|
35
54
|
/** Starting position for the division (0-based) */
|
|
36
55
|
startOffset?: number;
|
|
37
56
|
/** Maximum number of chunks to produce */
|
|
38
57
|
maxChunks?: number;
|
|
39
58
|
};
|
|
59
|
+
type DividerLoopEmptyOptions = DividerEmptyOptions & {
|
|
60
|
+
/** Placeholder to signal startOffset is intentionally absent */
|
|
61
|
+
readonly startOffset?: never;
|
|
62
|
+
/** Placeholder to signal maxChunks is intentionally absent */
|
|
63
|
+
readonly maxChunks?: never;
|
|
64
|
+
};
|
|
65
|
+
type DividerLoopOptionsLike = DividerLoopOptions | DividerLoopEmptyOptions;
|
|
40
66
|
type NumericSeparator = number;
|
|
41
67
|
type StringSeparator = string;
|
|
42
68
|
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
43
69
|
type DividerSeparators = DividerSeparator[];
|
|
44
|
-
type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
|
|
45
70
|
|
|
46
71
|
/**
|
|
47
72
|
* Main divider function that splits input based on numeric positions or string delimiters.
|
|
@@ -55,7 +80,7 @@ type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
|
|
|
55
80
|
* @param args - Array of separators (numbers/strings) and optional options object
|
|
56
81
|
* @returns Divided string segments based on input type and options
|
|
57
82
|
*/
|
|
58
|
-
declare function divider<T extends DividerInput>(input: T, ...args:
|
|
83
|
+
declare function divider<T extends DividerInput, const TArgs extends readonly (DividerSeparator | DividerOptions)[]>(input: T, ...args: TArgs): DividerResult<T, ExtractedDividerOptions<TArgs>>;
|
|
59
84
|
|
|
60
85
|
/**
|
|
61
86
|
* Extracts the first segment after dividing the input using specified separators.
|
|
@@ -100,7 +125,7 @@ declare function dividerLast(input: DividerInput, ...args: DividerSeparators): s
|
|
|
100
125
|
* dividerLoop("abcdef", 2) // returns ["ab", "cd", "ef"]
|
|
101
126
|
* dividerLoop("abcdef", 2, { maxChunks: 2 }) // returns ["ab", "cdef"]
|
|
102
127
|
*/
|
|
103
|
-
declare function dividerLoop<T extends DividerInput>(input: T, size: number, options?:
|
|
128
|
+
declare function dividerLoop<T extends DividerInput, O extends DividerLoopOptionsLike = DividerLoopEmptyOptions>(input: T, size: number, options?: O): DividerResult<T, O>;
|
|
104
129
|
|
|
105
130
|
/**
|
|
106
131
|
* Divides a string or array of strings by separating numbers from non-numbers.
|
|
@@ -115,7 +140,7 @@ declare function dividerLoop<T extends DividerInput>(input: T, size: number, opt
|
|
|
115
140
|
* dividerNumberString("abc123def") // returns ["abc", "123", "def"]
|
|
116
141
|
* dividerNumberString("test42") // returns ["test", "42"]
|
|
117
142
|
*/
|
|
118
|
-
declare function dividerNumberString<T extends DividerInput>(input: T, options?:
|
|
143
|
+
declare function dividerNumberString<T extends DividerInput, O extends DividerInferredOptions = DividerEmptyOptions>(input: T, options?: O): DividerResult<T, O>;
|
|
119
144
|
|
|
120
145
|
type EmailDividerOptions = Pick<DividerOptions, 'trim'> & {
|
|
121
146
|
/** Split top-level domain from the rest of the email address. */
|
|
@@ -163,4 +188,4 @@ declare function emailDivider(input: string, options?: EmailDividerOptions): Div
|
|
|
163
188
|
*/
|
|
164
189
|
declare function pathDivider(input: string, options?: PathDividerOptions): DividerStringResult;
|
|
165
190
|
|
|
166
|
-
export { type
|
|
191
|
+
export { type DividerArrayResult, type DividerEmptyOptions, type DividerExcludeMode, type DividerInferredOptions, type DividerInput, type DividerLoopEmptyOptions, type DividerLoopOptions, type DividerLoopOptionsLike, type DividerOptions, type DividerResult, type DividerSeparator, type DividerSeparators, type DividerStringResult, type ExtractedDividerOptions, type NumericSeparator, type StringArrayInput, type StringInput, type StringSeparator, csvDivider, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString, emailDivider, pathDivider };
|
package/dist/index.js
CHANGED
|
@@ -294,7 +294,10 @@ function divider(input, ...args) {
|
|
|
294
294
|
preserveEmpty: options.preserveEmpty
|
|
295
295
|
});
|
|
296
296
|
const result = isString(input) ? applyDivision(input) : input.map(applyDivision);
|
|
297
|
-
return applyDividerOptions(
|
|
297
|
+
return applyDividerOptions(
|
|
298
|
+
result,
|
|
299
|
+
options
|
|
300
|
+
);
|
|
298
301
|
}
|
|
299
302
|
|
|
300
303
|
// src/core/divider-first.ts
|
|
@@ -345,15 +348,15 @@ function dividerLoop(input, size, options) {
|
|
|
345
348
|
console.warn("dividerLoop: chunk size must be a positive number");
|
|
346
349
|
return [];
|
|
347
350
|
}
|
|
348
|
-
const
|
|
351
|
+
const resolvedOptions = options ?? {};
|
|
349
352
|
const {
|
|
350
353
|
startOffset = PERFORMANCE_CONSTANTS.DEFAULT_START_OFFSET,
|
|
351
354
|
maxChunks = PERFORMANCE_CONSTANTS.DEFAULT_MAX_CHUNKS
|
|
352
|
-
} =
|
|
355
|
+
} = resolvedOptions;
|
|
353
356
|
const result = isString(input) ? createChunksFromString(input, size, startOffset, maxChunks) : input.map(
|
|
354
357
|
(str) => createChunksFromString(str, size, startOffset, maxChunks)
|
|
355
358
|
);
|
|
356
|
-
return applyDividerOptions(result,
|
|
359
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
357
360
|
}
|
|
358
361
|
|
|
359
362
|
// src/utils/divide.ts
|
|
@@ -364,7 +367,8 @@ function divideNumberString(str) {
|
|
|
364
367
|
// src/core/divider-number-string.ts
|
|
365
368
|
function dividerNumberString(input, options) {
|
|
366
369
|
const result = isString(input) ? divideNumberString(input) : input.map(divideNumberString);
|
|
367
|
-
|
|
370
|
+
const resolvedOptions = options ?? {};
|
|
371
|
+
return applyDividerOptions(result, resolvedOptions);
|
|
368
372
|
}
|
|
369
373
|
|
|
370
374
|
// src/utils/quoted.ts
|