path-parser
Advanced tools
Comparing version 0.2.3 to 0.2.4
@@ -36,3 +36,4 @@ define(['exports', 'module'], function (exports, module) { | ||
pattern: /^(?:\?|&)(?:\:)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/ | ||
}, { | ||
}, // regex: match => new RegExp('(?=(\?|.*&)' + match[0] + '(?=(\=|&|$)))') | ||
{ | ||
// Delimiter / | ||
@@ -61,3 +62,3 @@ name: 'delimiter', | ||
var tokenise = function tokenise(str) { | ||
var tokens = arguments[1] === undefined ? [] : arguments[1]; | ||
var tokens = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
@@ -89,3 +90,3 @@ // Look for a matching rule | ||
var optTrailingSlash = function optTrailingSlash(source, trailingSlash) { | ||
if (!trailingSlash || source === '\\/') return source; | ||
if (!trailingSlash) return source; | ||
return source.replace(/\\\/$/, '') + '(?:\\/)?'; | ||
@@ -103,9 +104,12 @@ }; | ||
this.hasUrlParams = this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type); | ||
return (/^url-parameter/.test(t.type) | ||
); | ||
}).length > 0; | ||
this.hasSpatParam = this.tokens.filter(function (t) { | ||
return /splat$/.test(t.type); | ||
return (/splat$/.test(t.type) | ||
); | ||
}).length > 0; | ||
this.hasMatrixParams = this.tokens.filter(function (t) { | ||
return /matrix$/.test(t.type); | ||
return (/matrix$/.test(t.type) | ||
); | ||
}).length > 0; | ||
@@ -117,3 +121,4 @@ this.hasQueryParams = this.tokens.filter(function (t) { | ||
this.urlParams = !this.hasUrlParams ? [] : this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type); | ||
return (/^url-parameter/.test(t.type) | ||
); | ||
}).map(function (t) { | ||
@@ -164,3 +169,3 @@ return t.val.slice(0, 1); | ||
var trailingSlash = arguments[1] === undefined ? 0 : arguments[1]; | ||
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; | ||
@@ -197,3 +202,3 @@ // trailingSlash: falsy => non optional, truthy => optional | ||
value: function partialMatch(path) { | ||
var trailingSlash = arguments[1] === undefined ? 0 : arguments[1]; | ||
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; | ||
@@ -208,4 +213,4 @@ // Check if partial match (start of given path matches regex) | ||
value: function build() { | ||
var params = arguments[0] === undefined ? {} : arguments[0]; | ||
var ignoreConstraints = arguments[1] === undefined ? false : arguments[1]; | ||
var params = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var ignoreConstraints = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; | ||
@@ -220,3 +225,4 @@ // Check all params are provided (not search parameters which are optional) | ||
var constraintsPassed = this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type) && !/-splat$/.test(t.type); | ||
return (/^url-parameter/.test(t.type) && !/-splat$/.test(t.type) | ||
); | ||
}).every(function (t) { | ||
@@ -233,3 +239,4 @@ return new RegExp('^' + defaultOrConstrained(t.otherVal[0]) + '$').test(params[t.val]); | ||
if (t.type === 'url-parameter-matrix') return ';' + t.val[0] + '=' + params[t.val[0]]; | ||
return /^url-parameter/.test(t.type) ? params[t.val[0]] : t.match; | ||
return (/^url-parameter/.test(t.type) ? params[t.val[0]] : t.match | ||
); | ||
}).join(''); | ||
@@ -249,3 +256,2 @@ | ||
module.exports = Path; | ||
}); | ||
// regex: match => new RegExp('(?=(\?|.*&)' + match[0] + '(?=(\=|&|$)))') | ||
}); |
@@ -39,3 +39,4 @@ 'use strict'; | ||
pattern: /^(?:\?|&)(?:\:)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/ | ||
}, { | ||
}, // regex: match => new RegExp('(?=(\?|.*&)' + match[0] + '(?=(\=|&|$)))') | ||
{ | ||
// Delimiter / | ||
@@ -64,3 +65,3 @@ name: 'delimiter', | ||
var tokenise = function tokenise(str) { | ||
var tokens = arguments[1] === undefined ? [] : arguments[1]; | ||
var tokens = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
@@ -92,3 +93,3 @@ // Look for a matching rule | ||
var optTrailingSlash = function optTrailingSlash(source, trailingSlash) { | ||
if (!trailingSlash || source === '\\/') return source; | ||
if (!trailingSlash) return source; | ||
return source.replace(/\\\/$/, '') + '(?:\\/)?'; | ||
@@ -106,9 +107,12 @@ }; | ||
this.hasUrlParams = this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type); | ||
return (/^url-parameter/.test(t.type) | ||
); | ||
}).length > 0; | ||
this.hasSpatParam = this.tokens.filter(function (t) { | ||
return /splat$/.test(t.type); | ||
return (/splat$/.test(t.type) | ||
); | ||
}).length > 0; | ||
this.hasMatrixParams = this.tokens.filter(function (t) { | ||
return /matrix$/.test(t.type); | ||
return (/matrix$/.test(t.type) | ||
); | ||
}).length > 0; | ||
@@ -120,3 +124,4 @@ this.hasQueryParams = this.tokens.filter(function (t) { | ||
this.urlParams = !this.hasUrlParams ? [] : this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type); | ||
return (/^url-parameter/.test(t.type) | ||
); | ||
}).map(function (t) { | ||
@@ -167,3 +172,3 @@ return t.val.slice(0, 1); | ||
var trailingSlash = arguments[1] === undefined ? 0 : arguments[1]; | ||
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; | ||
@@ -200,3 +205,3 @@ // trailingSlash: falsy => non optional, truthy => optional | ||
value: function partialMatch(path) { | ||
var trailingSlash = arguments[1] === undefined ? 0 : arguments[1]; | ||
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; | ||
@@ -211,4 +216,4 @@ // Check if partial match (start of given path matches regex) | ||
value: function build() { | ||
var params = arguments[0] === undefined ? {} : arguments[0]; | ||
var ignoreConstraints = arguments[1] === undefined ? false : arguments[1]; | ||
var params = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var ignoreConstraints = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; | ||
@@ -223,3 +228,4 @@ // Check all params are provided (not search parameters which are optional) | ||
var constraintsPassed = this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type) && !/-splat$/.test(t.type); | ||
return (/^url-parameter/.test(t.type) && !/-splat$/.test(t.type) | ||
); | ||
}).every(function (t) { | ||
@@ -236,3 +242,4 @@ return new RegExp('^' + defaultOrConstrained(t.otherVal[0]) + '$').test(params[t.val]); | ||
if (t.type === 'url-parameter-matrix') return ';' + t.val[0] + '=' + params[t.val[0]]; | ||
return /^url-parameter/.test(t.type) ? params[t.val[0]] : t.match; | ||
return (/^url-parameter/.test(t.type) ? params[t.val[0]] : t.match | ||
); | ||
}).join(''); | ||
@@ -252,3 +259,2 @@ | ||
exports['default'] = Path; | ||
module.exports = exports['default']; | ||
// regex: match => new RegExp('(?=(\?|.*&)' + match[0] + '(?=(\=|&|$)))') | ||
module.exports = exports['default']; |
@@ -48,3 +48,4 @@ (function (global, factory) { | ||
pattern: /^(?:\?|&)(?:\:)?([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/ | ||
}, { | ||
}, // regex: match => new RegExp('(?=(\?|.*&)' + match[0] + '(?=(\=|&|$)))') | ||
{ | ||
// Delimiter / | ||
@@ -73,3 +74,3 @@ name: 'delimiter', | ||
var tokenise = function tokenise(str) { | ||
var tokens = arguments[1] === undefined ? [] : arguments[1]; | ||
var tokens = arguments.length <= 1 || arguments[1] === undefined ? [] : arguments[1]; | ||
@@ -101,3 +102,3 @@ // Look for a matching rule | ||
var optTrailingSlash = function optTrailingSlash(source, trailingSlash) { | ||
if (!trailingSlash || source === '\\/') return source; | ||
if (!trailingSlash) return source; | ||
return source.replace(/\\\/$/, '') + '(?:\\/)?'; | ||
@@ -115,9 +116,12 @@ }; | ||
this.hasUrlParams = this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type); | ||
return (/^url-parameter/.test(t.type) | ||
); | ||
}).length > 0; | ||
this.hasSpatParam = this.tokens.filter(function (t) { | ||
return /splat$/.test(t.type); | ||
return (/splat$/.test(t.type) | ||
); | ||
}).length > 0; | ||
this.hasMatrixParams = this.tokens.filter(function (t) { | ||
return /matrix$/.test(t.type); | ||
return (/matrix$/.test(t.type) | ||
); | ||
}).length > 0; | ||
@@ -129,3 +133,4 @@ this.hasQueryParams = this.tokens.filter(function (t) { | ||
this.urlParams = !this.hasUrlParams ? [] : this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type); | ||
return (/^url-parameter/.test(t.type) | ||
); | ||
}).map(function (t) { | ||
@@ -176,3 +181,3 @@ return t.val.slice(0, 1); | ||
var trailingSlash = arguments[1] === undefined ? 0 : arguments[1]; | ||
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; | ||
@@ -209,3 +214,3 @@ // trailingSlash: falsy => non optional, truthy => optional | ||
value: function partialMatch(path) { | ||
var trailingSlash = arguments[1] === undefined ? 0 : arguments[1]; | ||
var trailingSlash = arguments.length <= 1 || arguments[1] === undefined ? 0 : arguments[1]; | ||
@@ -220,4 +225,4 @@ // Check if partial match (start of given path matches regex) | ||
value: function build() { | ||
var params = arguments[0] === undefined ? {} : arguments[0]; | ||
var ignoreConstraints = arguments[1] === undefined ? false : arguments[1]; | ||
var params = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var ignoreConstraints = arguments.length <= 1 || arguments[1] === undefined ? false : arguments[1]; | ||
@@ -232,3 +237,4 @@ // Check all params are provided (not search parameters which are optional) | ||
var constraintsPassed = this.tokens.filter(function (t) { | ||
return /^url-parameter/.test(t.type) && !/-splat$/.test(t.type); | ||
return (/^url-parameter/.test(t.type) && !/-splat$/.test(t.type) | ||
); | ||
}).every(function (t) { | ||
@@ -245,3 +251,4 @@ return new RegExp('^' + defaultOrConstrained(t.otherVal[0]) + '$').test(params[t.val]); | ||
if (t.type === 'url-parameter-matrix') return ';' + t.val[0] + '=' + params[t.val[0]]; | ||
return /^url-parameter/.test(t.type) ? params[t.val[0]] : t.match; | ||
return (/^url-parameter/.test(t.type) ? params[t.val[0]] : t.match | ||
); | ||
}).join(''); | ||
@@ -261,4 +268,2 @@ | ||
module.exports = Path; | ||
}); | ||
// regex: match => new RegExp('(?=(\?|.*&)' + match[0] + '(?=(\=|&|$)))') | ||
}); |
@@ -78,3 +78,3 @@ let defaultOrConstrained = (match) => { | ||
let optTrailingSlash = (source, trailingSlash) => { | ||
if (!trailingSlash || source === '\\/') return source | ||
if (!trailingSlash) return source | ||
return source.replace(/\\\/$/, '') + '(?:\\/)?' | ||
@@ -81,0 +81,0 @@ } |
{ | ||
"name": "path-parser", | ||
"version": "0.2.3", | ||
"version": "0.2.4", | ||
"description": "A small utility to parse, match and generate paths", | ||
@@ -5,0 +5,0 @@ "main": "dist/commonjs/path-parser.js", |
@@ -139,3 +139,8 @@ 'use strict'; | ||
path.match('/my-path', 1).should.eql({}); | ||
path = new Path('/'); | ||
should.not.exist(path.match('')); | ||
path.match('/', true).should.eql({}); | ||
path.match('', 1).should.eql({}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48689
989