@nyaomaru/divider 2.0.16 → 2.0.18

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,6 +32,38 @@ __export(index_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(index_exports);
34
34
 
35
+ // src/utils/guards/primitives.ts
36
+ function isString(value) {
37
+ return typeof value === "string";
38
+ }
39
+ function isNumber(value) {
40
+ return typeof value === "number";
41
+ }
42
+ function isObject(value) {
43
+ return typeof value === "object" && value !== null;
44
+ }
45
+ function isPlainObject(value) {
46
+ if (!isObject(value)) return false;
47
+ const proto = Object.getPrototypeOf(value);
48
+ return proto === null || Object.getPrototypeOf(proto) === null;
49
+ }
50
+ function isPositiveInteger(value) {
51
+ return typeof value === "number" && Number.isInteger(value) && value > 0;
52
+ }
53
+ function isStringOrNumber(value) {
54
+ return isString(value) || isNumber(value);
55
+ }
56
+
57
+ // src/utils/guards/array.ts
58
+ function isEmptyArray(value) {
59
+ return Array.isArray(value) && value.length === 0;
60
+ }
61
+ function isNestedStringArray(value) {
62
+ if (!Array.isArray(value) || value.length === 0) return false;
63
+ const firstRow = value[0];
64
+ return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
65
+ }
66
+
35
67
  // src/constants/index.ts
36
68
  var DIVIDER_EXCLUDE_MODES = {
37
69
  NONE: "none",
@@ -71,43 +103,7 @@ var QUERY_DECODE_MODES = {
71
103
  RAW: "raw"
72
104
  };
73
105
 
74
- // src/utils/is.ts
75
- function isString(value) {
76
- return typeof value === "string";
77
- }
78
- function isNumber(value) {
79
- return typeof value === "number";
80
- }
81
- function isObject(value) {
82
- return typeof value === "object" && value !== null;
83
- }
84
- function isPlainObject(value) {
85
- if (!isObject(value)) return false;
86
- const proto = Object.getPrototypeOf(value);
87
- return proto === null || Object.getPrototypeOf(proto) === null;
88
- }
89
- function isOptions(value) {
90
- if (!isPlainObject(value)) return false;
91
- const options = value;
92
- return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
93
- }
94
- function isEmptyArray(value) {
95
- return Array.isArray(value) && value.length === 0;
96
- }
97
- function isPositiveInteger(value) {
98
- return typeof value === "number" && Number.isInteger(value) && value > 0;
99
- }
100
- function isValidInput(value) {
101
- return isString(value) || Array.isArray(value) && value.every(isString);
102
- }
103
- function isStringOrNumber(value) {
104
- return isString(value) || isNumber(value);
105
- }
106
- function isNestedStringArray(value) {
107
- if (!Array.isArray(value) || value.length === 0) return false;
108
- const firstRow = value[0];
109
- return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
110
- }
106
+ // src/utils/guards/whitespace.ts
111
107
  function isSpaceOrTab(value) {
112
108
  return value === WHITE_SPACE || value === TAB;
113
109
  }
@@ -117,9 +113,6 @@ function isWhitespaceOnly(value) {
117
113
  function isEmptyString(value) {
118
114
  return value === "";
119
115
  }
120
- function isNoneMode(value) {
121
- return value === DIVIDER_EXCLUDE_MODES.NONE;
122
- }
123
116
 
124
117
  // src/utils/regex.ts
125
118
  function normalizeSeparators(separators) {
@@ -275,6 +268,11 @@ var assertValidNumSeparators = (numSeparators) => {
275
268
  }
276
269
  };
277
270
 
271
+ // src/utils/guards/divider-input.ts
272
+ function isValidInput(value) {
273
+ return isString(value) || Array.isArray(value) && value.every(isString);
274
+ }
275
+
278
276
  // src/utils/array.ts
279
277
  function ensureStringArray(input) {
280
278
  return isString(input) ? [input] : input;
@@ -293,6 +291,16 @@ var excludePredicateMap = {
293
291
  whitespace: (s) => !isWhitespaceOnly(s)
294
292
  };
295
293
 
294
+ // src/utils/guards/options.ts
295
+ function isOptions(value) {
296
+ if (!isPlainObject(value)) return false;
297
+ const options = value;
298
+ return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
299
+ }
300
+ function isNoneMode(value) {
301
+ return value === DIVIDER_EXCLUDE_MODES.NONE;
302
+ }
303
+
296
304
  // src/utils/option-exclude.ts
297
305
  function resolveExcludePredicate(exclude) {
298
306
  if (exclude == null || isNoneMode(exclude) || typeof exclude !== "string") {
@@ -651,11 +659,11 @@ var buildPathSegments = (input, collapse) => collapse ? divider(input, PATH_SEPA
651
659
  var trimSegments2 = (segments, trim) => trim ? segments.map((segment) => segment.trim()) : segments;
652
660
  var applyCollapseRules = (segments, collapse) => collapse ? segments.filter((segment) => !isEmptyString(segment)) : segments;
653
661
 
654
- // src/presets/query-divider.ts
655
- function tryExtractQuery(input) {
662
+ // src/utils/query.ts
663
+ function extractQuery(input) {
656
664
  try {
657
665
  const url = new URL(input);
658
- return url.search.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? url.search.slice(1) : url.search;
666
+ return stripLeadingQuestionMark(url.search);
659
667
  } catch {
660
668
  return extractQueryFromQuestionMark(input);
661
669
  }
@@ -674,40 +682,47 @@ function extractQueryFromQuestionMark(input) {
674
682
  }
675
683
  const prefix = withoutFragment.slice(0, questionMarkIndex);
676
684
  const hasQuerySeparatorBefore = prefix.includes(QUERY_SEPARATORS.AMPERSAND) || prefix.includes(QUERY_SEPARATORS.EQUALS);
677
- if (hasQuerySeparatorBefore) {
678
- return withoutFragment;
679
- }
680
- return withoutFragment.slice(questionMarkIndex + 1);
685
+ return hasQuerySeparatorBefore ? withoutFragment : withoutFragment.slice(questionMarkIndex + 1);
681
686
  }
682
687
  function stripLeadingQuestionMark(query) {
683
688
  return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
684
689
  }
685
- function splitOnFirstEquals(part) {
686
- const kv = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
687
- if (kv.length === 1) return [kv[0] ?? "", ""];
688
- return [kv[0] ?? "", kv.slice(1).join(QUERY_SEPARATORS.EQUALS)];
690
+ function splitQueryPair(part) {
691
+ const keyValue = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
692
+ if (keyValue.length === 1) return [keyValue[0] ?? "", ""];
693
+ return [
694
+ keyValue[0] ?? "",
695
+ keyValue.slice(1).join(QUERY_SEPARATORS.EQUALS)
696
+ ];
689
697
  }
690
- function decodeField(text, mode, trim) {
691
- let t = text;
698
+ function decodeQueryField(text, mode, trim) {
699
+ let decoded = text;
692
700
  if (mode === QUERY_DECODE_MODES.AUTO) {
693
- t = t.replace(/\+/g, " ");
701
+ decoded = decoded.replace(/\+/g, " ");
694
702
  try {
695
- t = decodeURIComponent(t);
703
+ decoded = decodeURIComponent(decoded);
696
704
  } catch {
697
705
  }
698
706
  }
699
- if (trim) t = t.trim();
700
- return t;
707
+ return trim ? decoded.trim() : decoded;
701
708
  }
702
- function queryDivider(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
709
+ function parseQueryPairs(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
703
710
  if (input.length === 0) return [];
704
- const query = stripLeadingQuestionMark(tryExtractQuery(input));
711
+ const query = stripLeadingQuestionMark(extractQuery(input));
705
712
  if (query.length === 0) return [];
706
713
  return dividePreserve(query, QUERY_SEPARATORS.AMPERSAND).map((part) => {
707
- const [key, value] = splitOnFirstEquals(part);
708
- return [decodeField(key, mode, trim), decodeField(value, mode, trim)];
714
+ const [key, value] = splitQueryPair(part);
715
+ return [
716
+ decodeQueryField(key, mode, trim),
717
+ decodeQueryField(value, mode, trim)
718
+ ];
709
719
  });
710
720
  }
721
+
722
+ // src/presets/query-divider.ts
723
+ function queryDivider(input, options = {}) {
724
+ return parseQueryPairs(input, options);
725
+ }
711
726
  // Annotate the CommonJS export names for ESM import in node:
712
727
  0 && (module.exports = {
713
728
  csvDivider,
package/dist/index.d.cts CHANGED
@@ -278,6 +278,6 @@ declare function pathDivider(input: string, options?: PathDividerOptions): Divid
278
278
  * @param options Parsing options: { mode?: 'auto' | 'raw'; trim?: boolean }.
279
279
  * @returns Array of [key, value] string tuples in input order.
280
280
  */
281
- declare function queryDivider(input: string, { mode, trim }?: QueryDividerOptions): DividerArrayResult;
281
+ declare function queryDivider(input: string, options?: QueryDividerOptions): DividerArrayResult;
282
282
 
283
283
  export { type CsvDividerOptions, 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 EmailDividerOptions, type ExtractedDividerOptions, type NumericSeparator, type PathDividerOptions, type QueryDecodeMode, type QueryDividerOptions, type StringArrayInput, type StringInput, type StringSeparator, csvDivider, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString, emailDivider, pathDivider, queryDivider };
package/dist/index.d.ts CHANGED
@@ -278,6 +278,6 @@ declare function pathDivider(input: string, options?: PathDividerOptions): Divid
278
278
  * @param options Parsing options: { mode?: 'auto' | 'raw'; trim?: boolean }.
279
279
  * @returns Array of [key, value] string tuples in input order.
280
280
  */
281
- declare function queryDivider(input: string, { mode, trim }?: QueryDividerOptions): DividerArrayResult;
281
+ declare function queryDivider(input: string, options?: QueryDividerOptions): DividerArrayResult;
282
282
 
283
283
  export { type CsvDividerOptions, 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 EmailDividerOptions, type ExtractedDividerOptions, type NumericSeparator, type PathDividerOptions, type QueryDecodeMode, type QueryDividerOptions, type StringArrayInput, type StringInput, type StringSeparator, csvDivider, divider, dividerFirst, dividerLast, dividerLoop, dividerNumberString, emailDivider, pathDivider, queryDivider };
package/dist/index.js CHANGED
@@ -1,3 +1,35 @@
1
+ // src/utils/guards/primitives.ts
2
+ function isString(value) {
3
+ return typeof value === "string";
4
+ }
5
+ function isNumber(value) {
6
+ return typeof value === "number";
7
+ }
8
+ function isObject(value) {
9
+ return typeof value === "object" && value !== null;
10
+ }
11
+ function isPlainObject(value) {
12
+ if (!isObject(value)) return false;
13
+ const proto = Object.getPrototypeOf(value);
14
+ return proto === null || Object.getPrototypeOf(proto) === null;
15
+ }
16
+ function isPositiveInteger(value) {
17
+ return typeof value === "number" && Number.isInteger(value) && value > 0;
18
+ }
19
+ function isStringOrNumber(value) {
20
+ return isString(value) || isNumber(value);
21
+ }
22
+
23
+ // src/utils/guards/array.ts
24
+ function isEmptyArray(value) {
25
+ return Array.isArray(value) && value.length === 0;
26
+ }
27
+ function isNestedStringArray(value) {
28
+ if (!Array.isArray(value) || value.length === 0) return false;
29
+ const firstRow = value[0];
30
+ return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
31
+ }
32
+
1
33
  // src/constants/index.ts
2
34
  var DIVIDER_EXCLUDE_MODES = {
3
35
  NONE: "none",
@@ -37,43 +69,7 @@ var QUERY_DECODE_MODES = {
37
69
  RAW: "raw"
38
70
  };
39
71
 
40
- // src/utils/is.ts
41
- function isString(value) {
42
- return typeof value === "string";
43
- }
44
- function isNumber(value) {
45
- return typeof value === "number";
46
- }
47
- function isObject(value) {
48
- return typeof value === "object" && value !== null;
49
- }
50
- function isPlainObject(value) {
51
- if (!isObject(value)) return false;
52
- const proto = Object.getPrototypeOf(value);
53
- return proto === null || Object.getPrototypeOf(proto) === null;
54
- }
55
- function isOptions(value) {
56
- if (!isPlainObject(value)) return false;
57
- const options = value;
58
- return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
59
- }
60
- function isEmptyArray(value) {
61
- return Array.isArray(value) && value.length === 0;
62
- }
63
- function isPositiveInteger(value) {
64
- return typeof value === "number" && Number.isInteger(value) && value > 0;
65
- }
66
- function isValidInput(value) {
67
- return isString(value) || Array.isArray(value) && value.every(isString);
68
- }
69
- function isStringOrNumber(value) {
70
- return isString(value) || isNumber(value);
71
- }
72
- function isNestedStringArray(value) {
73
- if (!Array.isArray(value) || value.length === 0) return false;
74
- const firstRow = value[0];
75
- return Array.isArray(firstRow) && firstRow.every((item) => isString(item));
76
- }
72
+ // src/utils/guards/whitespace.ts
77
73
  function isSpaceOrTab(value) {
78
74
  return value === WHITE_SPACE || value === TAB;
79
75
  }
@@ -83,9 +79,6 @@ function isWhitespaceOnly(value) {
83
79
  function isEmptyString(value) {
84
80
  return value === "";
85
81
  }
86
- function isNoneMode(value) {
87
- return value === DIVIDER_EXCLUDE_MODES.NONE;
88
- }
89
82
 
90
83
  // src/utils/regex.ts
91
84
  function normalizeSeparators(separators) {
@@ -241,6 +234,11 @@ var assertValidNumSeparators = (numSeparators) => {
241
234
  }
242
235
  };
243
236
 
237
+ // src/utils/guards/divider-input.ts
238
+ function isValidInput(value) {
239
+ return isString(value) || Array.isArray(value) && value.every(isString);
240
+ }
241
+
244
242
  // src/utils/array.ts
245
243
  function ensureStringArray(input) {
246
244
  return isString(input) ? [input] : input;
@@ -259,6 +257,16 @@ var excludePredicateMap = {
259
257
  whitespace: (s) => !isWhitespaceOnly(s)
260
258
  };
261
259
 
260
+ // src/utils/guards/options.ts
261
+ function isOptions(value) {
262
+ if (!isPlainObject(value)) return false;
263
+ const options = value;
264
+ return DIVIDER_OPTION_KEYS.some((key) => Object.hasOwn(options, key));
265
+ }
266
+ function isNoneMode(value) {
267
+ return value === DIVIDER_EXCLUDE_MODES.NONE;
268
+ }
269
+
262
270
  // src/utils/option-exclude.ts
263
271
  function resolveExcludePredicate(exclude) {
264
272
  if (exclude == null || isNoneMode(exclude) || typeof exclude !== "string") {
@@ -617,11 +625,11 @@ var buildPathSegments = (input, collapse) => collapse ? divider(input, PATH_SEPA
617
625
  var trimSegments2 = (segments, trim) => trim ? segments.map((segment) => segment.trim()) : segments;
618
626
  var applyCollapseRules = (segments, collapse) => collapse ? segments.filter((segment) => !isEmptyString(segment)) : segments;
619
627
 
620
- // src/presets/query-divider.ts
621
- function tryExtractQuery(input) {
628
+ // src/utils/query.ts
629
+ function extractQuery(input) {
622
630
  try {
623
631
  const url = new URL(input);
624
- return url.search.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? url.search.slice(1) : url.search;
632
+ return stripLeadingQuestionMark(url.search);
625
633
  } catch {
626
634
  return extractQueryFromQuestionMark(input);
627
635
  }
@@ -640,40 +648,47 @@ function extractQueryFromQuestionMark(input) {
640
648
  }
641
649
  const prefix = withoutFragment.slice(0, questionMarkIndex);
642
650
  const hasQuerySeparatorBefore = prefix.includes(QUERY_SEPARATORS.AMPERSAND) || prefix.includes(QUERY_SEPARATORS.EQUALS);
643
- if (hasQuerySeparatorBefore) {
644
- return withoutFragment;
645
- }
646
- return withoutFragment.slice(questionMarkIndex + 1);
651
+ return hasQuerySeparatorBefore ? withoutFragment : withoutFragment.slice(questionMarkIndex + 1);
647
652
  }
648
653
  function stripLeadingQuestionMark(query) {
649
654
  return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
650
655
  }
651
- function splitOnFirstEquals(part) {
652
- const kv = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
653
- if (kv.length === 1) return [kv[0] ?? "", ""];
654
- return [kv[0] ?? "", kv.slice(1).join(QUERY_SEPARATORS.EQUALS)];
656
+ function splitQueryPair(part) {
657
+ const keyValue = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
658
+ if (keyValue.length === 1) return [keyValue[0] ?? "", ""];
659
+ return [
660
+ keyValue[0] ?? "",
661
+ keyValue.slice(1).join(QUERY_SEPARATORS.EQUALS)
662
+ ];
655
663
  }
656
- function decodeField(text, mode, trim) {
657
- let t = text;
664
+ function decodeQueryField(text, mode, trim) {
665
+ let decoded = text;
658
666
  if (mode === QUERY_DECODE_MODES.AUTO) {
659
- t = t.replace(/\+/g, " ");
667
+ decoded = decoded.replace(/\+/g, " ");
660
668
  try {
661
- t = decodeURIComponent(t);
669
+ decoded = decodeURIComponent(decoded);
662
670
  } catch {
663
671
  }
664
672
  }
665
- if (trim) t = t.trim();
666
- return t;
673
+ return trim ? decoded.trim() : decoded;
667
674
  }
668
- function queryDivider(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
675
+ function parseQueryPairs(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
669
676
  if (input.length === 0) return [];
670
- const query = stripLeadingQuestionMark(tryExtractQuery(input));
677
+ const query = stripLeadingQuestionMark(extractQuery(input));
671
678
  if (query.length === 0) return [];
672
679
  return dividePreserve(query, QUERY_SEPARATORS.AMPERSAND).map((part) => {
673
- const [key, value] = splitOnFirstEquals(part);
674
- return [decodeField(key, mode, trim), decodeField(value, mode, trim)];
680
+ const [key, value] = splitQueryPair(part);
681
+ return [
682
+ decodeQueryField(key, mode, trim),
683
+ decodeQueryField(value, mode, trim)
684
+ ];
675
685
  });
676
686
  }
687
+
688
+ // src/presets/query-divider.ts
689
+ function queryDivider(input, options = {}) {
690
+ return parseQueryPairs(input, options);
691
+ }
677
692
  export {
678
693
  csvDivider,
679
694
  divider,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "2.0.16",
4
+ "version": "2.0.18",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",
@@ -35,9 +35,9 @@
35
35
  "author": "nyaomaru",
36
36
  "license": "MIT",
37
37
  "devDependencies": {
38
+ "@eslint/js": "^9.26.0",
38
39
  "@swc/core": "^1.15.21",
39
40
  "@swc/jest": "^0.2.39",
40
- "@eslint/js": "^9.26.0",
41
41
  "@types/jest": "^30.0.0",
42
42
  "@types/node": "^22.15.12",
43
43
  "@typescript-eslint/eslint-plugin": "^8.32.1",