@nyaomaru/divider 1.8.3 → 1.8.4
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 +12 -4
- package/dist/index.d.cts +41 -9
- package/dist/index.d.ts +41 -9
- package/dist/index.js +12 -4
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,6 +28,13 @@ __export(index_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(index_exports);
|
|
30
30
|
|
|
31
|
+
// src/constants/index.ts
|
|
32
|
+
var DividerExcludeModes = {
|
|
33
|
+
NONE: "none",
|
|
34
|
+
EMPTY: "empty",
|
|
35
|
+
WHITESPACE: "whitespace"
|
|
36
|
+
};
|
|
37
|
+
|
|
31
38
|
// src/utils/is.ts
|
|
32
39
|
function isString(arg) {
|
|
33
40
|
return typeof arg === "string";
|
|
@@ -35,9 +42,10 @@ function isString(arg) {
|
|
|
35
42
|
function isNumber(arg) {
|
|
36
43
|
return typeof arg === "number";
|
|
37
44
|
}
|
|
38
|
-
function isOptions(
|
|
39
|
-
if (typeof
|
|
40
|
-
|
|
45
|
+
function isOptions(value) {
|
|
46
|
+
if (typeof value !== "object" || value === null) return false;
|
|
47
|
+
const options = value;
|
|
48
|
+
return "flatten" in options || "trim" in options || "exclude" in options;
|
|
41
49
|
}
|
|
42
50
|
function isEmptyArray(input) {
|
|
43
51
|
return Array.isArray(input) && input.length === 0;
|
|
@@ -61,7 +69,7 @@ function isEmptyString(s) {
|
|
|
61
69
|
return s === "";
|
|
62
70
|
}
|
|
63
71
|
function isNoneMode(mode) {
|
|
64
|
-
return mode ===
|
|
72
|
+
return mode === DividerExcludeModes.NONE;
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
// src/utils/regex.ts
|
package/dist/index.d.cts
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const DividerExcludeModes: {
|
|
2
|
+
readonly NONE: "none";
|
|
3
|
+
readonly EMPTY: "empty";
|
|
4
|
+
readonly WHITESPACE: "whitespace";
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type DividerExcludeMode = (typeof DividerExcludeModes)[keyof typeof DividerExcludeModes];
|
|
8
|
+
type StringInput = string;
|
|
9
|
+
type StringArrayInput = string[];
|
|
10
|
+
type DividerInput = StringInput | StringArrayInput;
|
|
11
|
+
type DividerStringResult = string[];
|
|
12
|
+
type DividerArrayResult = string[][];
|
|
13
|
+
type DividerResult<T extends DividerInput> = T extends StringInput ? DividerStringResult : DividerArrayResult;
|
|
14
|
+
interface DividerOptions {
|
|
15
|
+
/** If true, flattens nested arrays into a single array */
|
|
4
16
|
flatten?: boolean;
|
|
17
|
+
/** If true, trims whitespace from each divided segment */
|
|
5
18
|
trim?: boolean;
|
|
19
|
+
/** Controls how empty or whitespace segments are handled */
|
|
6
20
|
exclude?: DividerExcludeMode;
|
|
7
|
-
}
|
|
8
|
-
|
|
21
|
+
}
|
|
22
|
+
interface DividerLoopOptions extends DividerOptions {
|
|
23
|
+
/** Starting position for the division (0-based) */
|
|
9
24
|
startOffset?: number;
|
|
25
|
+
/** Maximum number of chunks to produce */
|
|
10
26
|
maxChunks?: number;
|
|
11
|
-
}
|
|
12
|
-
type
|
|
27
|
+
}
|
|
28
|
+
type NumericSeparator = number;
|
|
29
|
+
type StringSeparator = string;
|
|
30
|
+
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
31
|
+
type DividerSeparators = DividerSeparator[];
|
|
13
32
|
type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
|
|
14
33
|
|
|
15
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Main divider function that splits input based on numeric positions or string delimiters.
|
|
36
|
+
*
|
|
37
|
+
* This function can:
|
|
38
|
+
* - Split a string or array of strings
|
|
39
|
+
* - Use numeric positions and/or string delimiters
|
|
40
|
+
* - Apply various options like flattening and trimming
|
|
41
|
+
*
|
|
42
|
+
* @param input - String or array of strings to divide
|
|
43
|
+
* @param args - Array of separators (numbers/strings) and optional options object
|
|
44
|
+
* @returns Divided string segments based on input type and options
|
|
45
|
+
* @throws {DividerValidationError} If input or separators are invalid
|
|
46
|
+
*/
|
|
47
|
+
declare function divider<T extends DividerInput>(input: T, ...args: DividerArgs): DividerResult<T>;
|
|
16
48
|
|
|
17
49
|
declare function dividerFirst(input: string | string[], ...args: DividerSeparators): string;
|
|
18
50
|
|
|
@@ -22,4 +54,4 @@ declare function dividerLoop<T extends string | string[]>(input: T, size: number
|
|
|
22
54
|
|
|
23
55
|
declare function dividerNumberString<T extends string | string[]>(input: T, options?: DividerOptions): DividerResult<T>;
|
|
24
56
|
|
|
25
|
-
export { type DividerArgs, type DividerExcludeMode, type DividerLoopOptions, type DividerOptions, type DividerResult, type DividerSeparators, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
|
|
57
|
+
export { type DividerArgs, type DividerArrayResult, type DividerExcludeMode, type DividerInput, type DividerLoopOptions, type DividerOptions, type DividerResult, type DividerSeparator, type DividerSeparators, type DividerStringResult, type NumericSeparator, type StringArrayInput, type StringInput, type StringSeparator, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const DividerExcludeModes: {
|
|
2
|
+
readonly NONE: "none";
|
|
3
|
+
readonly EMPTY: "empty";
|
|
4
|
+
readonly WHITESPACE: "whitespace";
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
type DividerExcludeMode = (typeof DividerExcludeModes)[keyof typeof DividerExcludeModes];
|
|
8
|
+
type StringInput = string;
|
|
9
|
+
type StringArrayInput = string[];
|
|
10
|
+
type DividerInput = StringInput | StringArrayInput;
|
|
11
|
+
type DividerStringResult = string[];
|
|
12
|
+
type DividerArrayResult = string[][];
|
|
13
|
+
type DividerResult<T extends DividerInput> = T extends StringInput ? DividerStringResult : DividerArrayResult;
|
|
14
|
+
interface DividerOptions {
|
|
15
|
+
/** If true, flattens nested arrays into a single array */
|
|
4
16
|
flatten?: boolean;
|
|
17
|
+
/** If true, trims whitespace from each divided segment */
|
|
5
18
|
trim?: boolean;
|
|
19
|
+
/** Controls how empty or whitespace segments are handled */
|
|
6
20
|
exclude?: DividerExcludeMode;
|
|
7
|
-
}
|
|
8
|
-
|
|
21
|
+
}
|
|
22
|
+
interface DividerLoopOptions extends DividerOptions {
|
|
23
|
+
/** Starting position for the division (0-based) */
|
|
9
24
|
startOffset?: number;
|
|
25
|
+
/** Maximum number of chunks to produce */
|
|
10
26
|
maxChunks?: number;
|
|
11
|
-
}
|
|
12
|
-
type
|
|
27
|
+
}
|
|
28
|
+
type NumericSeparator = number;
|
|
29
|
+
type StringSeparator = string;
|
|
30
|
+
type DividerSeparator = NumericSeparator | StringSeparator;
|
|
31
|
+
type DividerSeparators = DividerSeparator[];
|
|
13
32
|
type DividerArgs = DividerSeparators | [...DividerSeparators, DividerOptions];
|
|
14
33
|
|
|
15
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Main divider function that splits input based on numeric positions or string delimiters.
|
|
36
|
+
*
|
|
37
|
+
* This function can:
|
|
38
|
+
* - Split a string or array of strings
|
|
39
|
+
* - Use numeric positions and/or string delimiters
|
|
40
|
+
* - Apply various options like flattening and trimming
|
|
41
|
+
*
|
|
42
|
+
* @param input - String or array of strings to divide
|
|
43
|
+
* @param args - Array of separators (numbers/strings) and optional options object
|
|
44
|
+
* @returns Divided string segments based on input type and options
|
|
45
|
+
* @throws {DividerValidationError} If input or separators are invalid
|
|
46
|
+
*/
|
|
47
|
+
declare function divider<T extends DividerInput>(input: T, ...args: DividerArgs): DividerResult<T>;
|
|
16
48
|
|
|
17
49
|
declare function dividerFirst(input: string | string[], ...args: DividerSeparators): string;
|
|
18
50
|
|
|
@@ -22,4 +54,4 @@ declare function dividerLoop<T extends string | string[]>(input: T, size: number
|
|
|
22
54
|
|
|
23
55
|
declare function dividerNumberString<T extends string | string[]>(input: T, options?: DividerOptions): DividerResult<T>;
|
|
24
56
|
|
|
25
|
-
export { type DividerArgs, type DividerExcludeMode, type DividerLoopOptions, type DividerOptions, type DividerResult, type DividerSeparators, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
|
|
57
|
+
export { type DividerArgs, type DividerArrayResult, type DividerExcludeMode, type DividerInput, type DividerLoopOptions, type DividerOptions, type DividerResult, type DividerSeparator, type DividerSeparators, type DividerStringResult, type NumericSeparator, type StringArrayInput, type StringInput, type StringSeparator, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// src/constants/index.ts
|
|
2
|
+
var DividerExcludeModes = {
|
|
3
|
+
NONE: "none",
|
|
4
|
+
EMPTY: "empty",
|
|
5
|
+
WHITESPACE: "whitespace"
|
|
6
|
+
};
|
|
7
|
+
|
|
1
8
|
// src/utils/is.ts
|
|
2
9
|
function isString(arg) {
|
|
3
10
|
return typeof arg === "string";
|
|
@@ -5,9 +12,10 @@ function isString(arg) {
|
|
|
5
12
|
function isNumber(arg) {
|
|
6
13
|
return typeof arg === "number";
|
|
7
14
|
}
|
|
8
|
-
function isOptions(
|
|
9
|
-
if (typeof
|
|
10
|
-
|
|
15
|
+
function isOptions(value) {
|
|
16
|
+
if (typeof value !== "object" || value === null) return false;
|
|
17
|
+
const options = value;
|
|
18
|
+
return "flatten" in options || "trim" in options || "exclude" in options;
|
|
11
19
|
}
|
|
12
20
|
function isEmptyArray(input) {
|
|
13
21
|
return Array.isArray(input) && input.length === 0;
|
|
@@ -31,7 +39,7 @@ function isEmptyString(s) {
|
|
|
31
39
|
return s === "";
|
|
32
40
|
}
|
|
33
41
|
function isNoneMode(mode) {
|
|
34
|
-
return mode ===
|
|
42
|
+
return mode === DividerExcludeModes.NONE;
|
|
35
43
|
}
|
|
36
44
|
|
|
37
45
|
// src/utils/regex.ts
|