Skip to content

Commit ea3c043

Browse files
committed
refactor(encode): scope URLSearchParams sentinel to encode module
REUSED_SEARCH_PARAMS is only used by encodeQualifierParam. Moving it from src/constants.ts into src/encode.ts keeps the mutable singleton private to its sole consumer so its side effects can't leak to other modules.
1 parent 66cfce2 commit ea3c043

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

src/constants.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,7 @@
11
/**
22
* @fileoverview Shared constants used across the PURL library.
3-
* Includes loop sentinels and reusable URL search parameter utilities.
43
*/
54

6-
import { URLSearchParamsCtor } from './primordials.js'
7-
85
const LOOP_SENTINEL = 1_000_000
96

10-
const REUSED_SEARCH_PARAMS = new URLSearchParamsCtor()
11-
12-
const REUSED_SEARCH_PARAMS_KEY = '_'
13-
14-
// '_='.length
15-
const REUSED_SEARCH_PARAMS_OFFSET = 2
16-
17-
export {
18-
LOOP_SENTINEL,
19-
REUSED_SEARCH_PARAMS,
20-
REUSED_SEARCH_PARAMS_KEY,
21-
REUSED_SEARCH_PARAMS_OFFSET,
22-
}
7+
export { LOOP_SENTINEL }

src/encode.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
* @fileoverview URL encoding functions for PURL components.
33
* Provides special handling for names, namespaces, versions, qualifiers, and subpaths.
44
*/
5-
import {
6-
REUSED_SEARCH_PARAMS,
7-
REUSED_SEARCH_PARAMS_KEY,
8-
REUSED_SEARCH_PARAMS_OFFSET,
9-
} from './constants.js'
105
import { isObject } from './objects.js'
116
import {
127
ArrayPrototypeToSorted,
@@ -18,6 +13,13 @@ import {
1813
} from './primordials.js'
1914
import { isNonEmptyString } from './strings.js'
2015

16+
// Module-private reusable URLSearchParams for encodeQualifierParam. Kept
17+
// private here so mutation side-effects can't leak to other modules.
18+
const REUSED_SEARCH_PARAMS = new URLSearchParamsCtor()
19+
const REUSED_SEARCH_PARAMS_KEY = '_'
20+
// '_='.length
21+
const REUSED_SEARCH_PARAMS_OFFSET = 2
22+
2123
/**
2224
* Encode package name component for URL.
2325
*/

0 commit comments

Comments
 (0)