@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 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 DividerExcludeModes = {
35
+ var DIVIDER_EXCLUDE_MODES = {
36
36
  NONE: "none",
37
37
  EMPTY: "empty",
38
38
  WHITESPACE: "whitespace"
39
39
  };
40
- var dividerOptionKeys = ["flatten", "trim", "exclude"];
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(arg) {
61
- return typeof arg === "string";
60
+ function isString(value) {
61
+ return typeof value === "string";
62
62
  }
63
- function isNumber(arg) {
64
- return typeof arg === "number";
63
+ function isNumber(value) {
64
+ return typeof value === "number";
65
65
  }
66
- function isObject(arg) {
67
- return typeof arg === "object" && arg !== null;
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 dividerOptionKeys.some((key) => Object.hasOwn(options, key));
72
+ return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
73
73
  }
74
- function isEmptyArray(input) {
75
- return Array.isArray(input) && input.length === 0;
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(input) {
81
- return isString(input) || Array.isArray(input) && input.every(isString);
80
+ function isValidInput(value) {
81
+ return isString(value) || Array.isArray(value) && value.every(isString);
82
82
  }
83
- function isStringArray(input) {
84
- return Array.isArray(input) && input.every(isString);
83
+ function isStringOrNumber(value) {
84
+ return isString(value) || isNumber(value);
85
85
  }
86
- function isNestedStringArray(input) {
87
- return Array.isArray(input) && input.length > 0 && Array.isArray(input[0]) && input[0].length > 0 && isStringArray(input[0]);
86
+ function isStringArray(value) {
87
+ return Array.isArray(value) && value.every(isString);
88
88
  }
89
- function isWhitespaceOnly(s) {
90
- return s.trim() === "";
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 isEmptyString(s) {
93
- return s === "";
92
+ function isWhitespaceOnly(value) {
93
+ return value.trim() === "";
94
94
  }
95
- function isNoneMode(mode) {
96
- return mode === DividerExcludeModes.NONE;
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 ?? DividerExcludeModes.NONE;
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 DividerExcludeModes: {
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 DividerExcludeModes)[keyof typeof DividerExcludeModes];
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 DividerExcludeModes: {
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 DividerExcludeModes)[keyof typeof DividerExcludeModes];
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 DividerExcludeModes = {
2
+ var DIVIDER_EXCLUDE_MODES = {
3
3
  NONE: "none",
4
4
  EMPTY: "empty",
5
5
  WHITESPACE: "whitespace"
6
6
  };
7
- var dividerOptionKeys = ["flatten", "trim", "exclude"];
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(arg) {
28
- return typeof arg === "string";
27
+ function isString(value) {
28
+ return typeof value === "string";
29
29
  }
30
- function isNumber(arg) {
31
- return typeof arg === "number";
30
+ function isNumber(value) {
31
+ return typeof value === "number";
32
32
  }
33
- function isObject(arg) {
34
- return typeof arg === "object" && arg !== null;
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 dividerOptionKeys.some((key) => Object.hasOwn(options, key));
39
+ return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
40
40
  }
41
- function isEmptyArray(input) {
42
- return Array.isArray(input) && input.length === 0;
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(input) {
48
- return isString(input) || Array.isArray(input) && input.every(isString);
47
+ function isValidInput(value) {
48
+ return isString(value) || Array.isArray(value) && value.every(isString);
49
49
  }
50
- function isStringArray(input) {
51
- return Array.isArray(input) && input.every(isString);
50
+ function isStringOrNumber(value) {
51
+ return isString(value) || isNumber(value);
52
52
  }
53
- function isNestedStringArray(input) {
54
- return Array.isArray(input) && input.length > 0 && Array.isArray(input[0]) && input[0].length > 0 && isStringArray(input[0]);
53
+ function isStringArray(value) {
54
+ return Array.isArray(value) && value.every(isString);
55
55
  }
56
- function isWhitespaceOnly(s) {
57
- return s.trim() === "";
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 isEmptyString(s) {
60
- return s === "";
59
+ function isWhitespaceOnly(value) {
60
+ return value.trim() === "";
61
61
  }
62
- function isNoneMode(mode) {
63
- return mode === DividerExcludeModes.NONE;
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 ?? DividerExcludeModes.NONE;
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];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.9.7",
4
+ "version": "1.9.9",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",