@nyaomaru/divider 1.9.7 → 1.9.9
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 +28 -27
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +28 -27
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,12 +32,12 @@ __export(index_exports, {
|
|
|
32
32
|
module.exports = __toCommonJS(index_exports);
|
|
33
33
|
|
|
34
34
|
// src/constants/index.ts
|
|
35
|
-
var
|
|
35
|
+
var DIVIDER_EXCLUDE_MODES = {
|
|
36
36
|
NONE: "none",
|
|
37
37
|
EMPTY: "empty",
|
|
38
38
|
WHITESPACE: "whitespace"
|
|
39
39
|
};
|
|
40
|
-
var
|
|
40
|
+
var DIVIDER_OPTION_KEYS = ["flatten", "trim", "exclude"];
|
|
41
41
|
var PERFORMANCE_CONSTANTS = {
|
|
42
42
|
/** Maximum number of cached regex patterns to prevent memory leaks */
|
|
43
43
|
MAX_REGEX_CACHE_SIZE: 100,
|
|
@@ -57,43 +57,46 @@ var PATH_SEPARATORS = {
|
|
|
57
57
|
};
|
|
58
58
|
|
|
59
59
|
// src/utils/is.ts
|
|
60
|
-
function isString(
|
|
61
|
-
return typeof
|
|
60
|
+
function isString(value) {
|
|
61
|
+
return typeof value === "string";
|
|
62
62
|
}
|
|
63
|
-
function isNumber(
|
|
64
|
-
return typeof
|
|
63
|
+
function isNumber(value) {
|
|
64
|
+
return typeof value === "number";
|
|
65
65
|
}
|
|
66
|
-
function isObject(
|
|
67
|
-
return typeof
|
|
66
|
+
function isObject(value) {
|
|
67
|
+
return typeof value === "object" && value !== null;
|
|
68
68
|
}
|
|
69
69
|
function isOptions(value) {
|
|
70
70
|
if (!isObject(value)) return false;
|
|
71
71
|
const options = value;
|
|
72
|
-
return
|
|
72
|
+
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
73
73
|
}
|
|
74
|
-
function isEmptyArray(
|
|
75
|
-
return Array.isArray(
|
|
74
|
+
function isEmptyArray(value) {
|
|
75
|
+
return Array.isArray(value) && value.length === 0;
|
|
76
76
|
}
|
|
77
77
|
function isPositiveInteger(value) {
|
|
78
78
|
return Number.isInteger(value) && value > 0;
|
|
79
79
|
}
|
|
80
|
-
function isValidInput(
|
|
81
|
-
return isString(
|
|
80
|
+
function isValidInput(value) {
|
|
81
|
+
return isString(value) || Array.isArray(value) && value.every(isString);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
83
|
+
function isStringOrNumber(value) {
|
|
84
|
+
return isString(value) || isNumber(value);
|
|
85
85
|
}
|
|
86
|
-
function
|
|
87
|
-
return Array.isArray(
|
|
86
|
+
function isStringArray(value) {
|
|
87
|
+
return Array.isArray(value) && value.every(isString);
|
|
88
88
|
}
|
|
89
|
-
function
|
|
90
|
-
return
|
|
89
|
+
function isNestedStringArray(value) {
|
|
90
|
+
return Array.isArray(value) && value.length > 0 && Array.isArray(value[0]) && value[0].length > 0 && isStringArray(value[0]);
|
|
91
91
|
}
|
|
92
|
-
function
|
|
93
|
-
return
|
|
92
|
+
function isWhitespaceOnly(value) {
|
|
93
|
+
return value.trim() === "";
|
|
94
94
|
}
|
|
95
|
-
function
|
|
96
|
-
return
|
|
95
|
+
function isEmptyString(value) {
|
|
96
|
+
return value === "";
|
|
97
|
+
}
|
|
98
|
+
function isNoneMode(value) {
|
|
99
|
+
return value === DIVIDER_EXCLUDE_MODES.NONE;
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
// src/utils/regex.ts
|
|
@@ -245,9 +248,7 @@ function extractOptions(args) {
|
|
|
245
248
|
const clonedArgs = [...args];
|
|
246
249
|
const lastArg = clonedArgs.at(-1);
|
|
247
250
|
const options = isOptions(lastArg) ? (clonedArgs.pop(), lastArg) : {};
|
|
248
|
-
const cleanedArgs = clonedArgs.filter(
|
|
249
|
-
(arg) => isString(arg) || isNumber(arg)
|
|
250
|
-
);
|
|
251
|
+
const cleanedArgs = clonedArgs.filter(isStringOrNumber);
|
|
251
252
|
return {
|
|
252
253
|
cleanedArgs,
|
|
253
254
|
options
|
|
@@ -263,7 +264,7 @@ function applyDividerOptions(result, options) {
|
|
|
263
264
|
output = output.flat();
|
|
264
265
|
}
|
|
265
266
|
if (!isNoneMode(options.exclude)) {
|
|
266
|
-
const exclude = options.exclude ??
|
|
267
|
+
const exclude = options.exclude ?? DIVIDER_EXCLUDE_MODES.NONE;
|
|
267
268
|
let shouldKeep = () => true;
|
|
268
269
|
if (exclude in excludePredicateMap) {
|
|
269
270
|
shouldKeep = excludePredicateMap[exclude];
|
package/dist/index.d.cts
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
* @property {string} EMPTY - Exclude empty segments (length = 0)
|
|
9
9
|
* @property {string} WHITESPACE - Exclude segments that contain only whitespace characters
|
|
10
10
|
*/
|
|
11
|
-
declare const
|
|
11
|
+
declare const DIVIDER_EXCLUDE_MODES: {
|
|
12
12
|
readonly NONE: "none";
|
|
13
13
|
readonly EMPTY: "empty";
|
|
14
14
|
readonly WHITESPACE: "whitespace";
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
type DividerExcludeMode = (typeof
|
|
17
|
+
type DividerExcludeMode = (typeof DIVIDER_EXCLUDE_MODES)[keyof typeof DIVIDER_EXCLUDE_MODES];
|
|
18
18
|
type StringInput = string;
|
|
19
19
|
type StringArrayInput = readonly string[];
|
|
20
20
|
type DividerInput = StringInput | StringArrayInput;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
* @property {string} EMPTY - Exclude empty segments (length = 0)
|
|
9
9
|
* @property {string} WHITESPACE - Exclude segments that contain only whitespace characters
|
|
10
10
|
*/
|
|
11
|
-
declare const
|
|
11
|
+
declare const DIVIDER_EXCLUDE_MODES: {
|
|
12
12
|
readonly NONE: "none";
|
|
13
13
|
readonly EMPTY: "empty";
|
|
14
14
|
readonly WHITESPACE: "whitespace";
|
|
15
15
|
};
|
|
16
16
|
|
|
17
|
-
type DividerExcludeMode = (typeof
|
|
17
|
+
type DividerExcludeMode = (typeof DIVIDER_EXCLUDE_MODES)[keyof typeof DIVIDER_EXCLUDE_MODES];
|
|
18
18
|
type StringInput = string;
|
|
19
19
|
type StringArrayInput = readonly string[];
|
|
20
20
|
type DividerInput = StringInput | StringArrayInput;
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
// src/constants/index.ts
|
|
2
|
-
var
|
|
2
|
+
var DIVIDER_EXCLUDE_MODES = {
|
|
3
3
|
NONE: "none",
|
|
4
4
|
EMPTY: "empty",
|
|
5
5
|
WHITESPACE: "whitespace"
|
|
6
6
|
};
|
|
7
|
-
var
|
|
7
|
+
var DIVIDER_OPTION_KEYS = ["flatten", "trim", "exclude"];
|
|
8
8
|
var PERFORMANCE_CONSTANTS = {
|
|
9
9
|
/** Maximum number of cached regex patterns to prevent memory leaks */
|
|
10
10
|
MAX_REGEX_CACHE_SIZE: 100,
|
|
@@ -24,43 +24,46 @@ var PATH_SEPARATORS = {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// src/utils/is.ts
|
|
27
|
-
function isString(
|
|
28
|
-
return typeof
|
|
27
|
+
function isString(value) {
|
|
28
|
+
return typeof value === "string";
|
|
29
29
|
}
|
|
30
|
-
function isNumber(
|
|
31
|
-
return typeof
|
|
30
|
+
function isNumber(value) {
|
|
31
|
+
return typeof value === "number";
|
|
32
32
|
}
|
|
33
|
-
function isObject(
|
|
34
|
-
return typeof
|
|
33
|
+
function isObject(value) {
|
|
34
|
+
return typeof value === "object" && value !== null;
|
|
35
35
|
}
|
|
36
36
|
function isOptions(value) {
|
|
37
37
|
if (!isObject(value)) return false;
|
|
38
38
|
const options = value;
|
|
39
|
-
return
|
|
39
|
+
return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
|
|
40
40
|
}
|
|
41
|
-
function isEmptyArray(
|
|
42
|
-
return Array.isArray(
|
|
41
|
+
function isEmptyArray(value) {
|
|
42
|
+
return Array.isArray(value) && value.length === 0;
|
|
43
43
|
}
|
|
44
44
|
function isPositiveInteger(value) {
|
|
45
45
|
return Number.isInteger(value) && value > 0;
|
|
46
46
|
}
|
|
47
|
-
function isValidInput(
|
|
48
|
-
return isString(
|
|
47
|
+
function isValidInput(value) {
|
|
48
|
+
return isString(value) || Array.isArray(value) && value.every(isString);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
50
|
+
function isStringOrNumber(value) {
|
|
51
|
+
return isString(value) || isNumber(value);
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
return Array.isArray(
|
|
53
|
+
function isStringArray(value) {
|
|
54
|
+
return Array.isArray(value) && value.every(isString);
|
|
55
55
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
56
|
+
function isNestedStringArray(value) {
|
|
57
|
+
return Array.isArray(value) && value.length > 0 && Array.isArray(value[0]) && value[0].length > 0 && isStringArray(value[0]);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return
|
|
59
|
+
function isWhitespaceOnly(value) {
|
|
60
|
+
return value.trim() === "";
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
return
|
|
62
|
+
function isEmptyString(value) {
|
|
63
|
+
return value === "";
|
|
64
|
+
}
|
|
65
|
+
function isNoneMode(value) {
|
|
66
|
+
return value === DIVIDER_EXCLUDE_MODES.NONE;
|
|
64
67
|
}
|
|
65
68
|
|
|
66
69
|
// src/utils/regex.ts
|
|
@@ -212,9 +215,7 @@ function extractOptions(args) {
|
|
|
212
215
|
const clonedArgs = [...args];
|
|
213
216
|
const lastArg = clonedArgs.at(-1);
|
|
214
217
|
const options = isOptions(lastArg) ? (clonedArgs.pop(), lastArg) : {};
|
|
215
|
-
const cleanedArgs = clonedArgs.filter(
|
|
216
|
-
(arg) => isString(arg) || isNumber(arg)
|
|
217
|
-
);
|
|
218
|
+
const cleanedArgs = clonedArgs.filter(isStringOrNumber);
|
|
218
219
|
return {
|
|
219
220
|
cleanedArgs,
|
|
220
221
|
options
|
|
@@ -230,7 +231,7 @@ function applyDividerOptions(result, options) {
|
|
|
230
231
|
output = output.flat();
|
|
231
232
|
}
|
|
232
233
|
if (!isNoneMode(options.exclude)) {
|
|
233
|
-
const exclude = options.exclude ??
|
|
234
|
+
const exclude = options.exclude ?? DIVIDER_EXCLUDE_MODES.NONE;
|
|
234
235
|
let shouldKeep = () => true;
|
|
235
236
|
if (exclude in excludePredicateMap) {
|
|
236
237
|
shouldKeep = excludePredicateMap[exclude];
|