path-to-regexp
Advanced tools
Comparing version 3.0.0 to 3.1.0
@@ -0,1 +1,7 @@ | ||
3.0.0 / 2019-01-13 | ||
================== | ||
* Always use prefix character as delimiter token, allowing any character to be a delimiter (e.g. `/:att1-:att2-:att3-:att4-:att5`) | ||
* Remove `partial` support, prefer escaping the prefix delimiter explicitly (e.g. `\\/(apple-)?icon-:res(\\d+).png`) | ||
2.4.0 / 2018-08-26 | ||
@@ -2,0 +8,0 @@ ================== |
@@ -42,2 +42,9 @@ declare function pathToRegexp (path: pathToRegexp.Path, keys?: pathToRegexp.Key[], options?: pathToRegexp.RegExpOptions & pathToRegexp.ParseOptions): RegExp; | ||
export interface TokensToFunctionOptions { | ||
/** | ||
* When `true` the regexp will be case sensitive. (default: `false`) | ||
*/ | ||
sensitive?: boolean; | ||
} | ||
/** | ||
@@ -51,3 +58,3 @@ * Parse an Express-style path into an array of tokens. | ||
*/ | ||
export function compile <P extends object = object> (path: string, options?: ParseOptions): PathFunction<P>; | ||
export function compile <P extends object = object> (path: string, options?: ParseOptions & TokensToFunctionOptions): PathFunction<P>; | ||
@@ -57,3 +64,3 @@ /** | ||
*/ | ||
export function tokensToFunction <P extends object = object> (tokens: Token[]): PathFunction<P>; | ||
export function tokensToFunction <P extends object = object> (tokens: Token[], options?: TokensToFunctionOptions): PathFunction<P>; | ||
@@ -79,2 +86,6 @@ /** | ||
encode?: (value: string, token: Key) => string; | ||
/** | ||
* When `false` the function can produce an invalid (unmatched) path. (default: `true`) | ||
*/ | ||
validate?: boolean; | ||
} | ||
@@ -81,0 +92,0 @@ |
11
index.js
@@ -120,3 +120,3 @@ /** | ||
function compile (str, options) { | ||
return tokensToFunction(parse(str, options)) | ||
return tokensToFunction(parse(str, options), options) | ||
} | ||
@@ -127,3 +127,3 @@ | ||
*/ | ||
function tokensToFunction (tokens) { | ||
function tokensToFunction (tokens, options) { | ||
// Compile all the tokens into regexps. | ||
@@ -135,3 +135,3 @@ var matches = new Array(tokens.length) | ||
if (typeof tokens[i] === 'object') { | ||
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$') | ||
matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options)) | ||
} | ||
@@ -143,2 +143,3 @@ } | ||
var encode = (options && options.encode) || encodeURIComponent | ||
var validate = options ? options.validate !== false : true | ||
@@ -170,3 +171,3 @@ for (var i = 0; i < tokens.length; i++) { | ||
if (!matches[i].test(segment)) { | ||
if (validate && !matches[i].test(segment)) { | ||
throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '"') | ||
@@ -184,3 +185,3 @@ } | ||
if (!matches[i].test(segment)) { | ||
if (validate && !matches[i].test(segment)) { | ||
throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but got "' + segment + '"') | ||
@@ -187,0 +188,0 @@ } |
{ | ||
"name": "path-to-regexp", | ||
"description": "Express style path to RegExp utility", | ||
"version": "3.0.0", | ||
"version": "3.1.0", | ||
"main": "index.js", | ||
@@ -37,10 +37,10 @@ "typings": "index.d.ts", | ||
"@types/mocha": "^5.2.5", | ||
"@types/node": "^10.7.1", | ||
"@types/node": "^12.7.3", | ||
"chai": "^4.1.1", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^5.2.0", | ||
"standard": "^12.0.1", | ||
"ts-node": "^7.0.1", | ||
"mocha": "^6.2.0", | ||
"standard": "^14.1.0", | ||
"ts-node": "^8.3.0", | ||
"typescript": "^3.0.1" | ||
} | ||
} |
@@ -60,4 +60,4 @@ # Path-to-RegExp | ||
re.exec('/test/route') | ||
//=> ['/test/route', 'test', 'route'] | ||
regexp.exec('/test/route') | ||
//=> [ '/test/route', 'test', 'route', index: 0, input: '/test/route', groups: undefined ] | ||
``` | ||
@@ -77,7 +77,7 @@ | ||
re.exec('/test') | ||
//=> ['/test', 'test', undefined] | ||
regexp.exec('/test') | ||
//=> [ '/test', 'test', undefined, index: 0, input: '/test', groups: undefined ] | ||
re.exec('/test/route') | ||
//=> ['/test', 'test', 'route'] | ||
regexp.exec('/test/route') | ||
//=> [ '/test/route', 'test', 'route', index: 0, input: '/test/route', groups: undefined ] | ||
``` | ||
@@ -95,7 +95,7 @@ | ||
re.exec('/') | ||
//=> ['/', undefined] | ||
regexp.exec('/') | ||
//=> [ '/', undefined, index: 0, input: '/', groups: undefined ] | ||
re.exec('/bar/baz') | ||
//=> ['/bar/baz', 'bar/baz'] | ||
regexp.exec('/bar/baz') | ||
//=> [ '/bar/baz', 'bar/baz', index: 0, input: '/bar/baz', groups: undefined ] | ||
``` | ||
@@ -111,7 +111,7 @@ | ||
re.exec('/') | ||
regexp.exec('/') | ||
//=> null | ||
re.exec('/bar/baz') | ||
//=> ['/bar/baz', 'bar/baz'] | ||
regexp.exec('/bar/baz') | ||
//=> [ '/bar/baz','bar/baz', index: 0, input: '/bar/baz', groups: undefined ] | ||
``` | ||
@@ -128,3 +128,3 @@ | ||
regexp.exec('/test/route') | ||
//=> ['/test/route', 'test', 'route'] | ||
//=> [ '/test/route', 'test', 'route', index: 0, input: '/test/route', groups: undefined ] | ||
``` | ||
@@ -201,2 +201,3 @@ | ||
toPathRegexp({ id: 'abc' }) //=> Throws `TypeError`. | ||
toPathRegexp({ id: 'abc' }, { validate: true }) //=> "/user/abc" | ||
``` | ||
@@ -203,0 +204,0 @@ |
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
28721
394
250