@nyaomaru/divider 2.0.0 → 2.0.1
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 +1 -4
- package/dist/index.d.cts +10 -3
- package/dist/index.d.ts +10 -3
- package/dist/index.js +1 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -343,10 +343,7 @@ function divider(input, ...args) {
|
|
|
343
343
|
preserveEmpty: options.preserveEmpty
|
|
344
344
|
});
|
|
345
345
|
const result = isString(input) ? applyDivision(input) : input.map(applyDivision);
|
|
346
|
-
return applyDividerOptions(
|
|
347
|
-
result,
|
|
348
|
-
options
|
|
349
|
-
);
|
|
346
|
+
return applyDividerOptions(result, options);
|
|
350
347
|
}
|
|
351
348
|
|
|
352
349
|
// src/core/divider-first.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -56,6 +56,13 @@ type HasFlattenOption<TOptions extends DividerInferredOptions> = TOptions extend
|
|
|
56
56
|
readonly flatten?: infer Flag;
|
|
57
57
|
} ? Flag extends true ? true : false : false;
|
|
58
58
|
type DividerResult<T extends DividerInput, TOptions extends DividerInferredOptions = DividerEmptyOptions> = T extends StringInput ? DividerStringResult : HasFlattenOption<TOptions> extends true ? DividerStringResult : DividerArrayResult;
|
|
59
|
+
/**
|
|
60
|
+
* Computes the divider return type based on the input and provided arguments.
|
|
61
|
+
*
|
|
62
|
+
* WHY: When no arguments are provided, divider returns the input as-is for
|
|
63
|
+
* string arrays. This type keeps the signature aligned with runtime behavior.
|
|
64
|
+
*/
|
|
65
|
+
type DividerReturn<T extends DividerInput, TArgs extends DividerArgs> = T extends StringInput ? DividerStringResult : TArgs['length'] extends 0 ? T : HasFlattenOption<ExtractedDividerOptions<TArgs>> extends true ? DividerStringResult : DividerArrayResult;
|
|
59
66
|
type ExtractedDividerOptions<TArgs extends DividerArgs> = TArgs extends readonly [...infer Rest, infer Last] ? Rest extends DividerArg[] ? Last extends DividerOptions ? Last : DividerEmptyOptions : DividerEmptyOptions : DividerEmptyOptions;
|
|
60
67
|
type DividerLoopOptions = DividerOptions & {
|
|
61
68
|
/** Starting position for the division (0-based) */
|
|
@@ -73,7 +80,7 @@ type DividerLoopOptionsLike = DividerLoopOptions | DividerLoopEmptyOptions;
|
|
|
73
80
|
type NumericSeparator = number;
|
|
74
81
|
type StringSeparator = string;
|
|
75
82
|
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
76
|
-
type DividerSeparators = DividerSeparator[];
|
|
83
|
+
type DividerSeparators = readonly DividerSeparator[];
|
|
77
84
|
type DividerArg = DividerSeparator | DividerOptions;
|
|
78
85
|
type DividerArgs = readonly DividerArg[];
|
|
79
86
|
|
|
@@ -89,7 +96,7 @@ type DividerArgs = readonly DividerArg[];
|
|
|
89
96
|
* @param args - Array of separators (numbers/strings) and optional options object
|
|
90
97
|
* @returns Divided string segments based on input type and options
|
|
91
98
|
*/
|
|
92
|
-
declare function divider<T extends DividerInput, const TArgs extends readonly DividerArg[]>(input: T, ...args: TArgs):
|
|
99
|
+
declare function divider<T extends DividerInput, const TArgs extends readonly DividerArg[]>(input: T, ...args: TArgs): DividerReturn<T, TArgs>;
|
|
93
100
|
|
|
94
101
|
/**
|
|
95
102
|
* Extracts the first segment after dividing the input using specified separators.
|
|
@@ -213,4 +220,4 @@ declare function pathDivider(input: string, options?: PathDividerOptions): Divid
|
|
|
213
220
|
*/
|
|
214
221
|
declare function queryDivider(input: string, { mode, trim }?: QueryDividerOptions): DividerArrayResult;
|
|
215
222
|
|
|
216
|
-
export { type DividerArg, type DividerArgs, 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, queryDivider };
|
|
223
|
+
export { type DividerArg, type DividerArgs, type DividerArrayResult, type DividerEmptyOptions, type DividerExcludeMode, type DividerInferredOptions, type DividerInput, type DividerLoopEmptyOptions, type DividerLoopOptions, type DividerLoopOptionsLike, type DividerOptions, type DividerResult, type DividerReturn, type DividerSeparator, type DividerSeparators, type DividerStringResult, type ExtractedDividerOptions, type NumericSeparator, type StringArrayInput, type StringInput, type StringSeparator, csvDivider, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString, emailDivider, pathDivider, queryDivider };
|
package/dist/index.d.ts
CHANGED
|
@@ -56,6 +56,13 @@ type HasFlattenOption<TOptions extends DividerInferredOptions> = TOptions extend
|
|
|
56
56
|
readonly flatten?: infer Flag;
|
|
57
57
|
} ? Flag extends true ? true : false : false;
|
|
58
58
|
type DividerResult<T extends DividerInput, TOptions extends DividerInferredOptions = DividerEmptyOptions> = T extends StringInput ? DividerStringResult : HasFlattenOption<TOptions> extends true ? DividerStringResult : DividerArrayResult;
|
|
59
|
+
/**
|
|
60
|
+
* Computes the divider return type based on the input and provided arguments.
|
|
61
|
+
*
|
|
62
|
+
* WHY: When no arguments are provided, divider returns the input as-is for
|
|
63
|
+
* string arrays. This type keeps the signature aligned with runtime behavior.
|
|
64
|
+
*/
|
|
65
|
+
type DividerReturn<T extends DividerInput, TArgs extends DividerArgs> = T extends StringInput ? DividerStringResult : TArgs['length'] extends 0 ? T : HasFlattenOption<ExtractedDividerOptions<TArgs>> extends true ? DividerStringResult : DividerArrayResult;
|
|
59
66
|
type ExtractedDividerOptions<TArgs extends DividerArgs> = TArgs extends readonly [...infer Rest, infer Last] ? Rest extends DividerArg[] ? Last extends DividerOptions ? Last : DividerEmptyOptions : DividerEmptyOptions : DividerEmptyOptions;
|
|
60
67
|
type DividerLoopOptions = DividerOptions & {
|
|
61
68
|
/** Starting position for the division (0-based) */
|
|
@@ -73,7 +80,7 @@ type DividerLoopOptionsLike = DividerLoopOptions | DividerLoopEmptyOptions;
|
|
|
73
80
|
type NumericSeparator = number;
|
|
74
81
|
type StringSeparator = string;
|
|
75
82
|
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
76
|
-
type DividerSeparators = DividerSeparator[];
|
|
83
|
+
type DividerSeparators = readonly DividerSeparator[];
|
|
77
84
|
type DividerArg = DividerSeparator | DividerOptions;
|
|
78
85
|
type DividerArgs = readonly DividerArg[];
|
|
79
86
|
|
|
@@ -89,7 +96,7 @@ type DividerArgs = readonly DividerArg[];
|
|
|
89
96
|
* @param args - Array of separators (numbers/strings) and optional options object
|
|
90
97
|
* @returns Divided string segments based on input type and options
|
|
91
98
|
*/
|
|
92
|
-
declare function divider<T extends DividerInput, const TArgs extends readonly DividerArg[]>(input: T, ...args: TArgs):
|
|
99
|
+
declare function divider<T extends DividerInput, const TArgs extends readonly DividerArg[]>(input: T, ...args: TArgs): DividerReturn<T, TArgs>;
|
|
93
100
|
|
|
94
101
|
/**
|
|
95
102
|
* Extracts the first segment after dividing the input using specified separators.
|
|
@@ -213,4 +220,4 @@ declare function pathDivider(input: string, options?: PathDividerOptions): Divid
|
|
|
213
220
|
*/
|
|
214
221
|
declare function queryDivider(input: string, { mode, trim }?: QueryDividerOptions): DividerArrayResult;
|
|
215
222
|
|
|
216
|
-
export { type DividerArg, type DividerArgs, 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, queryDivider };
|
|
223
|
+
export { type DividerArg, type DividerArgs, type DividerArrayResult, type DividerEmptyOptions, type DividerExcludeMode, type DividerInferredOptions, type DividerInput, type DividerLoopEmptyOptions, type DividerLoopOptions, type DividerLoopOptionsLike, type DividerOptions, type DividerResult, type DividerReturn, type DividerSeparator, type DividerSeparators, type DividerStringResult, type ExtractedDividerOptions, type NumericSeparator, type StringArrayInput, type StringInput, type StringSeparator, csvDivider, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString, emailDivider, pathDivider, queryDivider };
|
package/dist/index.js
CHANGED
|
@@ -309,10 +309,7 @@ function divider(input, ...args) {
|
|
|
309
309
|
preserveEmpty: options.preserveEmpty
|
|
310
310
|
});
|
|
311
311
|
const result = isString(input) ? applyDivision(input) : input.map(applyDivision);
|
|
312
|
-
return applyDividerOptions(
|
|
313
|
-
result,
|
|
314
|
-
options
|
|
315
|
-
);
|
|
312
|
+
return applyDividerOptions(result, options);
|
|
316
313
|
}
|
|
317
314
|
|
|
318
315
|
// src/core/divider-first.ts
|