@nyaomaru/divider 1.9.19 → 1.9.20

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
@@ -61,6 +61,15 @@ var PATH_SEPARATORS = {
61
61
  SLASH: "/",
62
62
  ALT: "|"
63
63
  };
64
+ var QUERY_SEPARATORS = {
65
+ QUESTION_MARK: "?",
66
+ AMPERSAND: "&",
67
+ EQUALS: "="
68
+ };
69
+ var QUERY_DECODE_MODES = {
70
+ AUTO: "auto",
71
+ RAW: "raw"
72
+ };
64
73
 
65
74
  // src/utils/is.ts
66
75
  function isString(value) {
@@ -515,22 +524,22 @@ function pathDivider(input, options = {}) {
515
524
  function tryExtractQuery(input) {
516
525
  try {
517
526
  const url = new URL(input);
518
- return url.search.startsWith("?") ? url.search.slice(1) : url.search;
527
+ return url.search.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? url.search.slice(1) : url.search;
519
528
  } catch {
520
529
  return input;
521
530
  }
522
531
  }
523
532
  function stripLeadingQuestionMark(query) {
524
- return query.startsWith("?") ? query.slice(1) : query;
533
+ return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
525
534
  }
526
535
  function splitOnFirstEquals(part) {
527
- const kv = dividePreserve(part, "=");
536
+ const kv = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
528
537
  if (kv.length === 1) return [kv[0] ?? "", ""];
529
- return [kv[0] ?? "", kv.slice(1).join("=")];
538
+ return [kv[0] ?? "", kv.slice(1).join(QUERY_SEPARATORS.EQUALS)];
530
539
  }
531
540
  function decodeField(text, mode, trim) {
532
541
  let t = text;
533
- if (mode === "auto") {
542
+ if (mode === QUERY_DECODE_MODES.AUTO) {
534
543
  t = t.replace(/\+/g, " ");
535
544
  try {
536
545
  t = decodeURIComponent(t);
@@ -540,11 +549,11 @@ function decodeField(text, mode, trim) {
540
549
  if (trim) t = t.trim();
541
550
  return t;
542
551
  }
543
- function queryDivider(input, { mode = "auto", trim = false } = {}) {
552
+ function queryDivider(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
544
553
  if (input.length === 0) return [];
545
554
  const query = stripLeadingQuestionMark(tryExtractQuery(input));
546
555
  if (query.length === 0) return [];
547
- return dividePreserve(query, "&").map((part) => {
556
+ return dividePreserve(query, QUERY_SEPARATORS.AMPERSAND).map((part) => {
548
557
  const [key, value] = splitOnFirstEquals(part);
549
558
  return [decodeField(key, mode, trim), decodeField(value, mode, trim)];
550
559
  });
package/dist/index.d.cts CHANGED
@@ -13,6 +13,13 @@ declare const DIVIDER_EXCLUDE_MODES: {
13
13
  readonly EMPTY: "empty";
14
14
  readonly WHITESPACE: "whitespace";
15
15
  };
16
+ /**
17
+ * Query string decode modes.
18
+ */
19
+ declare const QUERY_DECODE_MODES: {
20
+ readonly AUTO: "auto";
21
+ readonly RAW: "raw";
22
+ };
16
23
 
17
24
  type DividerExcludeMode = (typeof DIVIDER_EXCLUDE_MODES)[keyof typeof DIVIDER_EXCLUDE_MODES];
18
25
  type StringInput = string;
@@ -158,7 +165,7 @@ type PathDividerOptions = Pick<DividerOptions, 'trim'> & {
158
165
  /** Collapse empty segments produced by leading/trailing or repeated separators. */
159
166
  collapse?: boolean;
160
167
  };
161
- type QueryDecodeMode = 'auto' | 'raw';
168
+ type QueryDecodeMode = (typeof QUERY_DECODE_MODES)[keyof typeof QUERY_DECODE_MODES];
162
169
  type QueryDividerOptions = Pick<DividerOptions, 'trim'> & {
163
170
  /** Decoding mode: 'auto' applies standard URL decoding; 'raw' leaves values untouched. */
164
171
  mode?: QueryDecodeMode;
package/dist/index.d.ts CHANGED
@@ -13,6 +13,13 @@ declare const DIVIDER_EXCLUDE_MODES: {
13
13
  readonly EMPTY: "empty";
14
14
  readonly WHITESPACE: "whitespace";
15
15
  };
16
+ /**
17
+ * Query string decode modes.
18
+ */
19
+ declare const QUERY_DECODE_MODES: {
20
+ readonly AUTO: "auto";
21
+ readonly RAW: "raw";
22
+ };
16
23
 
17
24
  type DividerExcludeMode = (typeof DIVIDER_EXCLUDE_MODES)[keyof typeof DIVIDER_EXCLUDE_MODES];
18
25
  type StringInput = string;
@@ -158,7 +165,7 @@ type PathDividerOptions = Pick<DividerOptions, 'trim'> & {
158
165
  /** Collapse empty segments produced by leading/trailing or repeated separators. */
159
166
  collapse?: boolean;
160
167
  };
161
- type QueryDecodeMode = 'auto' | 'raw';
168
+ type QueryDecodeMode = (typeof QUERY_DECODE_MODES)[keyof typeof QUERY_DECODE_MODES];
162
169
  type QueryDividerOptions = Pick<DividerOptions, 'trim'> & {
163
170
  /** Decoding mode: 'auto' applies standard URL decoding; 'raw' leaves values untouched. */
164
171
  mode?: QueryDecodeMode;
package/dist/index.js CHANGED
@@ -27,6 +27,15 @@ var PATH_SEPARATORS = {
27
27
  SLASH: "/",
28
28
  ALT: "|"
29
29
  };
30
+ var QUERY_SEPARATORS = {
31
+ QUESTION_MARK: "?",
32
+ AMPERSAND: "&",
33
+ EQUALS: "="
34
+ };
35
+ var QUERY_DECODE_MODES = {
36
+ AUTO: "auto",
37
+ RAW: "raw"
38
+ };
30
39
 
31
40
  // src/utils/is.ts
32
41
  function isString(value) {
@@ -481,22 +490,22 @@ function pathDivider(input, options = {}) {
481
490
  function tryExtractQuery(input) {
482
491
  try {
483
492
  const url = new URL(input);
484
- return url.search.startsWith("?") ? url.search.slice(1) : url.search;
493
+ return url.search.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? url.search.slice(1) : url.search;
485
494
  } catch {
486
495
  return input;
487
496
  }
488
497
  }
489
498
  function stripLeadingQuestionMark(query) {
490
- return query.startsWith("?") ? query.slice(1) : query;
499
+ return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
491
500
  }
492
501
  function splitOnFirstEquals(part) {
493
- const kv = dividePreserve(part, "=");
502
+ const kv = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
494
503
  if (kv.length === 1) return [kv[0] ?? "", ""];
495
- return [kv[0] ?? "", kv.slice(1).join("=")];
504
+ return [kv[0] ?? "", kv.slice(1).join(QUERY_SEPARATORS.EQUALS)];
496
505
  }
497
506
  function decodeField(text, mode, trim) {
498
507
  let t = text;
499
- if (mode === "auto") {
508
+ if (mode === QUERY_DECODE_MODES.AUTO) {
500
509
  t = t.replace(/\+/g, " ");
501
510
  try {
502
511
  t = decodeURIComponent(t);
@@ -506,11 +515,11 @@ function decodeField(text, mode, trim) {
506
515
  if (trim) t = t.trim();
507
516
  return t;
508
517
  }
509
- function queryDivider(input, { mode = "auto", trim = false } = {}) {
518
+ function queryDivider(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
510
519
  if (input.length === 0) return [];
511
520
  const query = stripLeadingQuestionMark(tryExtractQuery(input));
512
521
  if (query.length === 0) return [];
513
- return dividePreserve(query, "&").map((part) => {
522
+ return dividePreserve(query, QUERY_SEPARATORS.AMPERSAND).map((part) => {
514
523
  const [key, value] = splitOnFirstEquals(part);
515
524
  return [decodeField(key, mode, trim), decodeField(value, mode, trim)];
516
525
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nyaomaru/divider",
3
3
  "type": "module",
4
- "version": "1.9.19",
4
+ "version": "1.9.20",
5
5
  "description": "To divide string or string[] with a given separator",
6
6
  "main": "./dist/index.cjs",
7
7
  "module": "./dist/index.js",