@nyaomaru/divider 2.0.16 → 2.0.17
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 -21
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +28 -21
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -651,11 +651,11 @@ var buildPathSegments = (input, collapse) => collapse ? divider(input, PATH_SEPA
|
|
|
651
651
|
var trimSegments2 = (segments, trim) => trim ? segments.map((segment) => segment.trim()) : segments;
|
|
652
652
|
var applyCollapseRules = (segments, collapse) => collapse ? segments.filter((segment) => !isEmptyString(segment)) : segments;
|
|
653
653
|
|
|
654
|
-
// src/
|
|
655
|
-
function
|
|
654
|
+
// src/utils/query.ts
|
|
655
|
+
function extractQuery(input) {
|
|
656
656
|
try {
|
|
657
657
|
const url = new URL(input);
|
|
658
|
-
return
|
|
658
|
+
return stripLeadingQuestionMark(url.search);
|
|
659
659
|
} catch {
|
|
660
660
|
return extractQueryFromQuestionMark(input);
|
|
661
661
|
}
|
|
@@ -674,40 +674,47 @@ function extractQueryFromQuestionMark(input) {
|
|
|
674
674
|
}
|
|
675
675
|
const prefix = withoutFragment.slice(0, questionMarkIndex);
|
|
676
676
|
const hasQuerySeparatorBefore = prefix.includes(QUERY_SEPARATORS.AMPERSAND) || prefix.includes(QUERY_SEPARATORS.EQUALS);
|
|
677
|
-
|
|
678
|
-
return withoutFragment;
|
|
679
|
-
}
|
|
680
|
-
return withoutFragment.slice(questionMarkIndex + 1);
|
|
677
|
+
return hasQuerySeparatorBefore ? withoutFragment : withoutFragment.slice(questionMarkIndex + 1);
|
|
681
678
|
}
|
|
682
679
|
function stripLeadingQuestionMark(query) {
|
|
683
680
|
return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
|
|
684
681
|
}
|
|
685
|
-
function
|
|
686
|
-
const
|
|
687
|
-
if (
|
|
688
|
-
return [
|
|
682
|
+
function splitQueryPair(part) {
|
|
683
|
+
const keyValue = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
|
|
684
|
+
if (keyValue.length === 1) return [keyValue[0] ?? "", ""];
|
|
685
|
+
return [
|
|
686
|
+
keyValue[0] ?? "",
|
|
687
|
+
keyValue.slice(1).join(QUERY_SEPARATORS.EQUALS)
|
|
688
|
+
];
|
|
689
689
|
}
|
|
690
|
-
function
|
|
691
|
-
let
|
|
690
|
+
function decodeQueryField(text, mode, trim) {
|
|
691
|
+
let decoded = text;
|
|
692
692
|
if (mode === QUERY_DECODE_MODES.AUTO) {
|
|
693
|
-
|
|
693
|
+
decoded = decoded.replace(/\+/g, " ");
|
|
694
694
|
try {
|
|
695
|
-
|
|
695
|
+
decoded = decodeURIComponent(decoded);
|
|
696
696
|
} catch {
|
|
697
697
|
}
|
|
698
698
|
}
|
|
699
|
-
|
|
700
|
-
return t;
|
|
699
|
+
return trim ? decoded.trim() : decoded;
|
|
701
700
|
}
|
|
702
|
-
function
|
|
701
|
+
function parseQueryPairs(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
|
|
703
702
|
if (input.length === 0) return [];
|
|
704
|
-
const query = stripLeadingQuestionMark(
|
|
703
|
+
const query = stripLeadingQuestionMark(extractQuery(input));
|
|
705
704
|
if (query.length === 0) return [];
|
|
706
705
|
return dividePreserve(query, QUERY_SEPARATORS.AMPERSAND).map((part) => {
|
|
707
|
-
const [key, value] =
|
|
708
|
-
return [
|
|
706
|
+
const [key, value] = splitQueryPair(part);
|
|
707
|
+
return [
|
|
708
|
+
decodeQueryField(key, mode, trim),
|
|
709
|
+
decodeQueryField(value, mode, trim)
|
|
710
|
+
];
|
|
709
711
|
});
|
|
710
712
|
}
|
|
713
|
+
|
|
714
|
+
// src/presets/query-divider.ts
|
|
715
|
+
function queryDivider(input, options = {}) {
|
|
716
|
+
return parseQueryPairs(input, options);
|
|
717
|
+
}
|
|
711
718
|
// Annotate the CommonJS export names for ESM import in node:
|
|
712
719
|
0 && (module.exports = {
|
|
713
720
|
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,
|
|
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,
|
|
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
|
@@ -617,11 +617,11 @@ var buildPathSegments = (input, collapse) => collapse ? divider(input, PATH_SEPA
|
|
|
617
617
|
var trimSegments2 = (segments, trim) => trim ? segments.map((segment) => segment.trim()) : segments;
|
|
618
618
|
var applyCollapseRules = (segments, collapse) => collapse ? segments.filter((segment) => !isEmptyString(segment)) : segments;
|
|
619
619
|
|
|
620
|
-
// src/
|
|
621
|
-
function
|
|
620
|
+
// src/utils/query.ts
|
|
621
|
+
function extractQuery(input) {
|
|
622
622
|
try {
|
|
623
623
|
const url = new URL(input);
|
|
624
|
-
return
|
|
624
|
+
return stripLeadingQuestionMark(url.search);
|
|
625
625
|
} catch {
|
|
626
626
|
return extractQueryFromQuestionMark(input);
|
|
627
627
|
}
|
|
@@ -640,40 +640,47 @@ function extractQueryFromQuestionMark(input) {
|
|
|
640
640
|
}
|
|
641
641
|
const prefix = withoutFragment.slice(0, questionMarkIndex);
|
|
642
642
|
const hasQuerySeparatorBefore = prefix.includes(QUERY_SEPARATORS.AMPERSAND) || prefix.includes(QUERY_SEPARATORS.EQUALS);
|
|
643
|
-
|
|
644
|
-
return withoutFragment;
|
|
645
|
-
}
|
|
646
|
-
return withoutFragment.slice(questionMarkIndex + 1);
|
|
643
|
+
return hasQuerySeparatorBefore ? withoutFragment : withoutFragment.slice(questionMarkIndex + 1);
|
|
647
644
|
}
|
|
648
645
|
function stripLeadingQuestionMark(query) {
|
|
649
646
|
return query.startsWith(QUERY_SEPARATORS.QUESTION_MARK) ? query.slice(1) : query;
|
|
650
647
|
}
|
|
651
|
-
function
|
|
652
|
-
const
|
|
653
|
-
if (
|
|
654
|
-
return [
|
|
648
|
+
function splitQueryPair(part) {
|
|
649
|
+
const keyValue = dividePreserve(part, QUERY_SEPARATORS.EQUALS);
|
|
650
|
+
if (keyValue.length === 1) return [keyValue[0] ?? "", ""];
|
|
651
|
+
return [
|
|
652
|
+
keyValue[0] ?? "",
|
|
653
|
+
keyValue.slice(1).join(QUERY_SEPARATORS.EQUALS)
|
|
654
|
+
];
|
|
655
655
|
}
|
|
656
|
-
function
|
|
657
|
-
let
|
|
656
|
+
function decodeQueryField(text, mode, trim) {
|
|
657
|
+
let decoded = text;
|
|
658
658
|
if (mode === QUERY_DECODE_MODES.AUTO) {
|
|
659
|
-
|
|
659
|
+
decoded = decoded.replace(/\+/g, " ");
|
|
660
660
|
try {
|
|
661
|
-
|
|
661
|
+
decoded = decodeURIComponent(decoded);
|
|
662
662
|
} catch {
|
|
663
663
|
}
|
|
664
664
|
}
|
|
665
|
-
|
|
666
|
-
return t;
|
|
665
|
+
return trim ? decoded.trim() : decoded;
|
|
667
666
|
}
|
|
668
|
-
function
|
|
667
|
+
function parseQueryPairs(input, { mode = QUERY_DECODE_MODES.AUTO, trim = false } = {}) {
|
|
669
668
|
if (input.length === 0) return [];
|
|
670
|
-
const query = stripLeadingQuestionMark(
|
|
669
|
+
const query = stripLeadingQuestionMark(extractQuery(input));
|
|
671
670
|
if (query.length === 0) return [];
|
|
672
671
|
return dividePreserve(query, QUERY_SEPARATORS.AMPERSAND).map((part) => {
|
|
673
|
-
const [key, value] =
|
|
674
|
-
return [
|
|
672
|
+
const [key, value] = splitQueryPair(part);
|
|
673
|
+
return [
|
|
674
|
+
decodeQueryField(key, mode, trim),
|
|
675
|
+
decodeQueryField(value, mode, trim)
|
|
676
|
+
];
|
|
675
677
|
});
|
|
676
678
|
}
|
|
679
|
+
|
|
680
|
+
// src/presets/query-divider.ts
|
|
681
|
+
function queryDivider(input, options = {}) {
|
|
682
|
+
return parseQueryPairs(input, options);
|
|
683
|
+
}
|
|
677
684
|
export {
|
|
678
685
|
csvDivider,
|
|
679
686
|
divider,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nyaomaru/divider",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0.
|
|
4
|
+
"version": "2.0.17",
|
|
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",
|