Skip to content

Commit a177930

Browse files
committed
Style tweaks
1 parent db2607d commit a177930

File tree

1 file changed

+26
-24
lines changed

1 file changed

+26
-24
lines changed

modules/utils/Path.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,20 @@ function compilePattern(pattern) {
3535

3636
var Path = {
3737

38+
/**
39+
* Returns true if the given path is absolute.
40+
*/
41+
isAbsolute: function (path) {
42+
return path.charAt(0) === '/';
43+
},
44+
45+
/**
46+
* Joins two URL paths together.
47+
*/
48+
join: function (a, b) {
49+
return a.replace(/\/*$/, '/') + b;
50+
},
51+
3852
/**
3953
* Returns an array of the names of all parameters in the given pattern.
4054
*/
@@ -48,15 +62,15 @@ var Path = {
4862
* pattern does not match the given path.
4963
*/
5064
extractParams: function (pattern, path) {
51-
var object = compilePattern(pattern);
52-
var match = path.match(object.matcher);
65+
var { matcher, paramNames } = compilePattern(pattern);
66+
var match = path.match(matcher);
5367

5468
if (!match)
5569
return null;
5670

5771
var params = {};
5872

59-
object.paramNames.forEach(function (paramName, index) {
73+
paramNames.forEach(function (paramName, index) {
6074
params[paramName] = match[index + 1];
6175
});
6276

@@ -76,16 +90,17 @@ var Path = {
7690
paramName = paramName || 'splat';
7791

7892
// If param is optional don't check for existence
79-
if (paramName.slice(-1) !== '?') {
80-
invariant(
81-
params[paramName] != null,
82-
'Missing "' + paramName + '" parameter for path "' + pattern + '"'
83-
);
84-
} else {
93+
if (paramName.slice(-1) === '?') {
8594
paramName = paramName.slice(0, -1);
8695

8796
if (params[paramName] == null)
8897
return '';
98+
} else {
99+
invariant(
100+
params[paramName] != null,
101+
'Missing "%s" parameter for path "%s"',
102+
paramName, pattern
103+
);
89104
}
90105

91106
var segment;
@@ -94,7 +109,8 @@ var Path = {
94109

95110
invariant(
96111
segment != null,
97-
'Missing splat # ' + splatIndex + ' for path "' + pattern + '"'
112+
'Missing splat # %s for path "%s"',
113+
splatIndex, pattern
98114
);
99115
} else {
100116
segment = params[paramName];
@@ -136,20 +152,6 @@ var Path = {
136152
return Path.withoutQuery(path) + '?' + queryString;
137153

138154
return path;
139-
},
140-
141-
/**
142-
* Returns true if the given path is absolute.
143-
*/
144-
isAbsolute: function (path) {
145-
return path.charAt(0) === '/';
146-
},
147-
148-
/**
149-
* Joins two URL paths together.
150-
*/
151-
join: function (a, b) {
152-
return a.replace(/\/*$/, '/') + b;
153155
}
154156

155157
};

0 commit comments

Comments
 (0)