Skip to content

Commit af16310

Browse files
committed
Fix lint nits
1 parent 144ef1c commit af16310

File tree

5 files changed

+28
-29
lines changed

5 files changed

+28
-29
lines changed

src/decode.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
const { PurlError } = require('./error')
44

5-
const { decodeURIComponent } = globalThis
5+
const { decodeURIComponent: decodeComponent } = globalThis
66

7-
function decodePurlComponent(comp, encodedURIComponent) {
7+
function decodePurlComponent(comp, encodedComponent) {
88
try {
9-
return decodeURIComponent(encodedURIComponent)
9+
return decodeComponent(encodedComponent)
1010
} catch {}
1111
throw new PurlError(`unable to decode "${comp}" component`)
1212
}

src/encode.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ const {
88
const { isObject } = require('./objects')
99
const { isNonEmptyString } = require('./strings')
1010

11-
const { encodeURIComponent } = globalThis
11+
const { encodeURIComponent: encodeComponent } = globalThis
1212

1313
function encodeName(name) {
1414
return isNonEmptyString(name)
15-
? encodeURIComponent(name).replace(/%3A/g, ':')
15+
? encodeComponent(name).replace(/%3A/g, ':')
1616
: ''
1717
}
1818

1919
function encodeNamespace(namespace) {
2020
return isNonEmptyString(namespace)
21-
? encodeURIComponent(namespace).replace(/%3A/g, ':').replace(/%2F/g, '/')
21+
? encodeComponent(namespace).replace(/%3A/g, ':').replace(/%2F/g, '/')
2222
: ''
2323
}
2424

@@ -51,13 +51,13 @@ function encodeQualifiers(qualifiers) {
5151

5252
function encodeSubpath(subpath) {
5353
return isNonEmptyString(subpath)
54-
? encodeURIComponent(subpath).replace(/%2F/g, '/')
54+
? encodeComponent(subpath).replace(/%2F/g, '/')
5555
: ''
5656
}
5757

5858
function encodeVersion(version) {
5959
return isNonEmptyString(version)
60-
? encodeURIComponent(version).replace(/%3A/g, ':').replace(/%2B/g, '+')
60+
? encodeComponent(version).replace(/%3A/g, ':').replace(/%2B/g, '+')
6161
: ''
6262
}
6363

@@ -67,11 +67,11 @@ function replacePlusSignWithPercentEncodedSpace(str) {
6767
}
6868

6969
module.exports = {
70+
encodeComponent,
7071
encodeName,
7172
encodeNamespace,
7273
encodeVersion,
7374
encodeQualifiers,
7475
encodeQualifierParam,
75-
encodeSubpath,
76-
encodeURIComponent
76+
encodeSubpath
7777
}

src/package-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class PackageURL {
8888
}
8989

9090
toString() {
91-
const { namespace, name, version, qualifiers, subpath, type } = this
91+
const { name, namespace, qualifiers, subpath, type, version } = this
9292
let purlStr = `pkg:${PurlComponent.type.encode(type)}/`
9393
if (namespace) {
9494
purlStr = `${purlStr}${PurlComponent.namespace.encode(namespace)}/`

src/purl-component.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
'use strict'
22

33
const {
4+
encodeComponent,
45
encodeName,
56
encodeNamespace,
6-
encodeVersion,
7-
encodeQualifiers,
87
encodeQualifierParam,
8+
encodeQualifiers,
99
encodeSubpath,
10-
encodeURIComponent
10+
encodeVersion
1111
} = require('./encode')
1212
const { createHelpersNamespaceObject } = require('./helpers')
1313
const {
14-
normalizeType,
15-
normalizeNamespace,
1614
normalizeName,
17-
normalizeVersion,
15+
normalizeNamespace,
1816
normalizeQualifiers,
19-
normalizeSubpath
17+
normalizeSubpath,
18+
normalizeType,
19+
normalizeVersion
2020
} = require('./normalize')
21-
const { localeCompare, isNonEmptyString } = require('./strings')
21+
const { isNonEmptyString, localeCompare } = require('./strings')
2222
const {
23-
validateType,
24-
validateNamespace,
2523
validateName,
26-
validateVersion,
27-
validateQualifiers,
24+
validateNamespace,
2825
validateQualifierKey,
29-
validateSubpath
26+
validateQualifiers,
27+
validateSubpath,
28+
validateType,
29+
validateVersion
3030
} = require('./validate')
3131

3232
const PurlComponentEncoder = comp =>
33-
isNonEmptyString(comp) ? encodeURIComponent(comp) : ''
33+
isNonEmptyString(comp) ? encodeComponent(comp) : ''
3434

3535
const PurlComponentStringNormalizer = comp =>
3636
typeof comp === 'string' ? comp : undefined

src/purl-type.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict'
22

3-
const { encodeURIComponent } = require('./encode')
3+
const { encodeComponent } = require('./encode')
44
const { PurlError } = require('./error')
55
const { createHelpersNamespaceObject } = require('./helpers')
66
const { isNullishOrEmptyString } = require('./lang')
@@ -279,7 +279,7 @@ module.exports = {
279279
}
280280
return false
281281
}
282-
if (encodeURIComponent(name) !== name) {
282+
if (encodeComponent(name) !== name) {
283283
if (throws) {
284284
throw new PurlError(
285285
`npm "name" component can only contain URL-friendly characters`
@@ -303,8 +303,7 @@ module.exports = {
303303
}
304304
const namespaceWithoutAtSign = namespace.slice(1)
305305
if (
306-
encodeURIComponent(namespaceWithoutAtSign) !==
307-
namespaceWithoutAtSign
306+
encodeComponent(namespaceWithoutAtSign) !== namespaceWithoutAtSign
308307
) {
309308
if (throws) {
310309
throw new PurlError(

0 commit comments

Comments
 (0)