Skip to content

Commit 9a91343

Browse files
committed
use singular
1 parent 486f4c0 commit 9a91343

3 files changed

Lines changed: 89 additions & 89 deletions

File tree

index.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function normalize (uri, options) {
2626
*/
2727
function resolve (baseURI, relativeURI, options) {
2828
const schemelessOptions = options ? Object.assign({ scheme: 'null' }, options) : { scheme: 'null' }
29-
const resolved = resolveComponents(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true)
29+
const resolved = resolveComponent(parse(baseURI, schemelessOptions), parse(relativeURI, schemelessOptions), schemelessOptions, true)
3030
schemelessOptions.skipEscape = true
3131
return serialize(resolved, schemelessOptions)
3232
}
@@ -38,12 +38,12 @@ function resolve (baseURI, relativeURI, options) {
3838
* @param {boolean} [skipNormalization=false]
3939
* @returns {import ('./types/index').URIComponent}
4040
*/
41-
function resolveComponents (base, relative, options, skipNormalization) {
41+
function resolveComponent (base, relative, options, skipNormalization) {
4242
/** @type {import('./types/index').URIComponent} */
4343
const target = {}
4444
if (!skipNormalization) {
45-
base = parse(serialize(base, options), options) // normalize base components
46-
relative = parse(serialize(relative, options), options) // normalize relative components
45+
base = parse(serialize(base, options), options) // normalize base component
46+
relative = parse(serialize(relative, options), options) // normalize relative component
4747
}
4848
options = options || {}
4949

@@ -129,7 +129,7 @@ function equal (uriA, uriB, options) {
129129
* @returns {string}
130130
*/
131131
function serialize (cmpts, opts) {
132-
const components = {
132+
const component = {
133133
host: cmpts.host,
134134
scheme: cmpts.scheme,
135135
userinfo: cmpts.userinfo,
@@ -149,41 +149,41 @@ function serialize (cmpts, opts) {
149149
const uriTokens = []
150150

151151
// find scheme handler
152-
const schemeHandler = getSchemeHandler(options.scheme || components.scheme)
152+
const schemeHandler = getSchemeHandler(options.scheme || component.scheme)
153153

154154
// perform scheme specific serialization
155-
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(components, options)
155+
if (schemeHandler && schemeHandler.serialize) schemeHandler.serialize(component, options)
156156

157-
if (components.path !== undefined) {
157+
if (component.path !== undefined) {
158158
if (!options.skipEscape) {
159-
components.path = escape(components.path)
159+
component.path = escape(component.path)
160160

161-
if (components.scheme !== undefined) {
162-
components.path = components.path.split('%3A').join(':')
161+
if (component.scheme !== undefined) {
162+
component.path = component.path.split('%3A').join(':')
163163
}
164164
} else {
165-
components.path = unescape(components.path)
165+
component.path = unescape(component.path)
166166
}
167167
}
168168

169-
if (options.reference !== 'suffix' && components.scheme) {
170-
uriTokens.push(components.scheme, ':')
169+
if (options.reference !== 'suffix' && component.scheme) {
170+
uriTokens.push(component.scheme, ':')
171171
}
172172

173-
const authority = recomposeAuthority(components)
173+
const authority = recomposeAuthority(component)
174174
if (authority !== undefined) {
175175
if (options.reference !== 'suffix') {
176176
uriTokens.push('//')
177177
}
178178

179179
uriTokens.push(authority)
180180

181-
if (components.path && components.path[0] !== '/') {
181+
if (component.path && component.path[0] !== '/') {
182182
uriTokens.push('/')
183183
}
184184
}
185-
if (components.path !== undefined) {
186-
let s = components.path
185+
if (component.path !== undefined) {
186+
let s = component.path
187187

188188
if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
189189
s = removeDotSegments(s)
@@ -201,12 +201,12 @@ function serialize (cmpts, opts) {
201201
uriTokens.push(s)
202202
}
203203

204-
if (components.query !== undefined) {
205-
uriTokens.push('?', components.query)
204+
if (component.query !== undefined) {
205+
uriTokens.push('?', component.query)
206206
}
207207

208-
if (components.fragment !== undefined) {
209-
uriTokens.push('#', components.fragment)
208+
if (component.fragment !== undefined) {
209+
uriTokens.push('#', component.fragment)
210210
}
211211
return uriTokens.join('')
212212
}
@@ -329,7 +329,7 @@ const fastUri = {
329329
SCHEMES,
330330
normalize,
331331
resolve,
332-
resolveComponents,
332+
resolveComponent,
333333
equal,
334334
serialize,
335335
parse

lib/schemes.js

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ function isValidSchemeName (name) {
2727
* @typedef {Object} SchemeHandler
2828
* @property {SchemeName} scheme - The scheme name.
2929
* @property {boolean} [domainHost] - Indicates if the scheme supports domain hosts.
30-
* @property {SchemeFn} parse - Function to parse the URI components for this scheme.
31-
* @property {SchemeFn} serialize - Function to serialize the URI components for this scheme.
30+
* @property {SchemeFn} parse - Function to parse the URI component for this scheme.
31+
* @property {SchemeFn} serialize - Function to serialize the URI component for this scheme.
3232
* @property {boolean} [skipNormalize] - Indicates if normalization should be skipped for this scheme.
3333
* @property {boolean} [absolutePath] - Indicates if the scheme uses absolute paths.
3434
* @property {boolean} [unicodeSupport] - Indicates if the scheme supports Unicode.
@@ -56,33 +56,33 @@ function wsIsSecure (wsComponent) {
5656
}
5757

5858
/** @type {SchemeFn} */
59-
function httpParse (components) {
60-
if (!components.host) {
61-
components.error = components.error || 'HTTP URIs must have a host.'
59+
function httpParse (component) {
60+
if (!component.host) {
61+
component.error = component.error || 'HTTP URIs must have a host.'
6262
}
6363

64-
return components
64+
return component
6565
}
6666

6767
/** @type {SchemeFn} */
68-
function httpSerialize (components) {
69-
const secure = String(components.scheme).toLowerCase() === 'https'
68+
function httpSerialize (component) {
69+
const secure = String(component.scheme).toLowerCase() === 'https'
7070

7171
// normalize the default port
72-
if (components.port === (secure ? 443 : 80) || components.port === '') {
73-
components.port = undefined
72+
if (component.port === (secure ? 443 : 80) || component.port === '') {
73+
component.port = undefined
7474
}
7575

7676
// normalize the empty path
77-
if (!components.path) {
78-
components.path = '/'
77+
if (!component.path) {
78+
component.path = '/'
7979
}
8080

8181
// NOTE: We do not parse query strings for HTTP URIs
8282
// as WWW Form Url Encoded query strings are part of the HTML4+ spec,
8383
// and not the HTTP spec.
8484

85-
return components
85+
return component
8686
}
8787

8888
/** @type {SchemeFn} */
@@ -99,95 +99,95 @@ function wsParse (wsComponent) {
9999
}
100100

101101
/** @type {SchemeFn} */
102-
function wsSerialize (wsComponents) {
102+
function wsSerialize (wsComponent) {
103103
// normalize the default port
104-
if (wsComponents.port === (wsIsSecure(wsComponents) ? 443 : 80) || wsComponents.port === '') {
105-
wsComponents.port = undefined
104+
if (wsComponent.port === (wsIsSecure(wsComponent) ? 443 : 80) || wsComponent.port === '') {
105+
wsComponent.port = undefined
106106
}
107107

108108
// ensure scheme matches secure flag
109-
if (typeof wsComponents.secure === 'boolean') {
110-
wsComponents.scheme = (wsComponents.secure ? 'wss' : 'ws')
111-
wsComponents.secure = undefined
109+
if (typeof wsComponent.secure === 'boolean') {
110+
wsComponent.scheme = (wsComponent.secure ? 'wss' : 'ws')
111+
wsComponent.secure = undefined
112112
}
113113

114114
// reconstruct path from resource name
115-
if (wsComponents.resourceName) {
116-
const [path, query] = wsComponents.resourceName.split('?')
117-
wsComponents.path = (path && path !== '/' ? path : undefined)
118-
wsComponents.query = query
119-
wsComponents.resourceName = undefined
115+
if (wsComponent.resourceName) {
116+
const [path, query] = wsComponent.resourceName.split('?')
117+
wsComponent.path = (path && path !== '/' ? path : undefined)
118+
wsComponent.query = query
119+
wsComponent.resourceName = undefined
120120
}
121121

122122
// forbid fragment component
123-
wsComponents.fragment = undefined
123+
wsComponent.fragment = undefined
124124

125-
return wsComponents
125+
return wsComponent
126126
}
127127

128128
/** @type {SchemeFn} */
129-
function urnParse (urnComponents, options) {
130-
if (!urnComponents.path) {
131-
urnComponents.error = 'URN can not be parsed'
132-
return urnComponents
129+
function urnParse (urnComponent, options) {
130+
if (!urnComponent.path) {
131+
urnComponent.error = 'URN can not be parsed'
132+
return urnComponent
133133
}
134-
const matches = urnComponents.path.match(URN_REG)
134+
const matches = urnComponent.path.match(URN_REG)
135135
if (matches) {
136-
const scheme = options.scheme || urnComponents.scheme || 'urn'
137-
urnComponents.nid = matches[1].toLowerCase()
138-
urnComponents.nss = matches[2]
139-
const urnScheme = `${scheme}:${options.nid || urnComponents.nid}`
136+
const scheme = options.scheme || urnComponent.scheme || 'urn'
137+
urnComponent.nid = matches[1].toLowerCase()
138+
urnComponent.nss = matches[2]
139+
const urnScheme = `${scheme}:${options.nid || urnComponent.nid}`
140140
const schemeHandler = getSchemeHandler(urnScheme)
141-
urnComponents.path = undefined
141+
urnComponent.path = undefined
142142

143143
if (schemeHandler) {
144-
urnComponents = schemeHandler.parse(urnComponents, options)
144+
urnComponent = schemeHandler.parse(urnComponent, options)
145145
}
146146
} else {
147-
urnComponents.error = urnComponents.error || 'URN can not be parsed.'
147+
urnComponent.error = urnComponent.error || 'URN can not be parsed.'
148148
}
149149

150-
return urnComponents
150+
return urnComponent
151151
}
152152

153153
/** @type {SchemeFn} */
154-
function urnSerialize (urnComponents, options) {
155-
const scheme = options.scheme || urnComponents.scheme || 'urn'
156-
const nid = urnComponents.nid.toLowerCase()
154+
function urnSerialize (urnComponent, options) {
155+
const scheme = options.scheme || urnComponent.scheme || 'urn'
156+
const nid = urnComponent.nid.toLowerCase()
157157
const urnScheme = `${scheme}:${options.nid || nid}`
158158
const schemeHandler = getSchemeHandler(urnScheme)
159159

160160
if (schemeHandler) {
161-
urnComponents = schemeHandler.serialize(urnComponents, options)
161+
urnComponent = schemeHandler.serialize(urnComponent, options)
162162
}
163163

164-
const uriComponents = urnComponents
165-
const nss = urnComponents.nss
166-
uriComponents.path = `${nid || options.nid}:${nss}`
164+
const uriComponent = urnComponent
165+
const nss = urnComponent.nss
166+
uriComponent.path = `${nid || options.nid}:${nss}`
167167

168168
options.skipEscape = true
169-
return uriComponents
169+
return uriComponent
170170
}
171171

172172
/** @type {SchemeFn} */
173173
function urnuuidParse (urnComponent, options) {
174-
const uuidComponents = urnComponent
175-
uuidComponents.uuid = uuidComponents.nss
176-
uuidComponents.nss = undefined
174+
const uuidComponent = urnComponent
175+
uuidComponent.uuid = uuidComponent.nss
176+
uuidComponent.nss = undefined
177177

178-
if (!options.tolerant && (!uuidComponents.uuid || !isUUID(uuidComponents.uuid))) {
179-
uuidComponents.error = uuidComponents.error || 'UUID is not valid.'
178+
if (!options.tolerant && (!uuidComponent.uuid || !isUUID(uuidComponent.uuid))) {
179+
uuidComponent.error = uuidComponent.error || 'UUID is not valid.'
180180
}
181181

182-
return uuidComponents
182+
return uuidComponent
183183
}
184184

185185
/** @type {SchemeFn} */
186-
function urnuuidSerialize (uuidComponents) {
187-
const urnComponents = uuidComponents
186+
function urnuuidSerialize (uuidComponent) {
187+
const urnComponent = uuidComponent
188188
// normalize UUID
189-
urnComponents.nss = (uuidComponents.uuid || '').toLowerCase()
190-
return urnComponents
189+
urnComponent.nss = (uuidComponent.uuid || '').toLowerCase()
190+
return urnComponent
191191
}
192192

193193
const http = /** @type {SchemeHandler} */ ({

lib/utils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -292,33 +292,33 @@ function normalizeComponentEncoding (component, esc) {
292292
}
293293

294294
/**
295-
* @param {import('../types/index').URIComponent} components
295+
* @param {import('../types/index').URIComponent} component
296296
* @returns {string|undefined}
297297
*/
298-
function recomposeAuthority (components) {
298+
function recomposeAuthority (component) {
299299
const uriTokens = []
300300

301-
if (components.userinfo !== undefined) {
302-
uriTokens.push(components.userinfo)
301+
if (component.userinfo !== undefined) {
302+
uriTokens.push(component.userinfo)
303303
uriTokens.push('@')
304304
}
305305

306-
if (components.host !== undefined) {
307-
let host = unescape(components.host)
306+
if (component.host !== undefined) {
307+
let host = unescape(component.host)
308308
if (!isIPv4(host)) {
309309
const ipV6res = normalizeIPv6(host)
310310
if (ipV6res.isIPV6 === true) {
311311
host = `[${ipV6res.escapedHost}]`
312312
} else {
313-
host = components.host
313+
host = component.host
314314
}
315315
}
316316
uriTokens.push(host)
317317
}
318318

319-
if (typeof components.port === 'number' || typeof components.port === 'string') {
319+
if (typeof component.port === 'number' || typeof component.port === 'string') {
320320
uriTokens.push(':')
321-
uriTokens.push(String(components.port))
321+
uriTokens.push(String(component.port))
322322
}
323323

324324
return uriTokens.length ? uriTokens.join('') : undefined

0 commit comments

Comments
 (0)