Skip to content

Commit c1cdfcc

Browse files
committed
Better named variable (key -> token)
1 parent 43f29c7 commit c1cdfcc

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

index.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -120,57 +120,56 @@ function tokensToFunction (tokens) {
120120

121121
return function (obj) {
122122
var path = ''
123-
124-
obj = obj || {}
123+
var data = obj || {}
125124

126125
for (var i = 0; i < tokens.length; i++) {
127-
var key = tokens[i]
126+
var token = tokens[i]
128127

129-
if (typeof key === 'string') {
130-
path += key
128+
if (typeof token === 'string') {
129+
path += token
131130

132131
continue
133132
}
134133

135-
var value = obj[key.name]
134+
var value = data[token.name]
136135

137136
if (value == null) {
138-
if (key.optional) {
137+
if (token.optional) {
139138
continue
140139
} else {
141-
throw new TypeError('Expected "' + key.name + '" to be defined')
140+
throw new TypeError('Expected "' + token.name + '" to be defined')
142141
}
143142
}
144143

145144
if (isarray(value)) {
146-
if (!key.repeat) {
147-
throw new TypeError('Expected "' + key.name + '" to not repeat')
145+
if (!token.repeat) {
146+
throw new TypeError('Expected "' + token.name + '" to not repeat')
148147
}
149148

150149
if (value.length === 0) {
151-
if (key.optional) {
150+
if (token.optional) {
152151
continue
153152
} else {
154-
throw new TypeError('Expected "' + key.name + '" to not be empty')
153+
throw new TypeError('Expected "' + token.name + '" to not be empty')
155154
}
156155
}
157156

158157
for (var j = 0; j < value.length; j++) {
159158
if (!matches[i].test(value[j])) {
160-
throw new TypeError('Expected all "' + key.name + '" to match "' + key.pattern + '"')
159+
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"')
161160
}
162161

163-
path += (j === 0 ? key.prefix : key.delimiter) + encodeURIComponent(value[j])
162+
path += (j === 0 ? token.prefix : token.delimiter) + encodeURIComponent(value[j])
164163
}
165164

166165
continue
167166
}
168167

169168
if (!matches[i].test(value)) {
170-
throw new TypeError('Expected "' + key.name + '" to match "' + key.pattern + '"')
169+
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '"')
171170
}
172171

173-
path += key.prefix + encodeURIComponent(value)
172+
path += token.prefix + encodeURIComponent(value)
174173
}
175174

176175
return path

0 commit comments

Comments
 (0)