path-parser
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -21,3 +21,3 @@ 'use strict'; | ||
pattern: /^\*([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/, | ||
regex: /(.*?)/ | ||
regex: /([^\?]*)/ | ||
}, { | ||
@@ -31,3 +31,3 @@ // Query parameter: ?param1¶m2 | ||
name: 'delimiter', | ||
pattern: /^(\/|\?|\#)/, | ||
pattern: /^(\/|\?|#)/, | ||
regex: function regex(match) { | ||
@@ -34,0 +34,0 @@ return new RegExp(match[0]); |
@@ -13,3 +13,3 @@ const rules = [ | ||
pattern: /^\*([a-zA-Z0-9-_]*[a-zA-Z0-9]{1})/, | ||
regex: /(.*?)/ | ||
regex: /([^\?]*)/ | ||
}, | ||
@@ -26,3 +26,3 @@ { | ||
name: 'delimiter', | ||
pattern: /^(\/|\?|\#)/, | ||
pattern: /^(\/|\?|#)/, | ||
regex: match => new RegExp(match[0]) | ||
@@ -29,0 +29,0 @@ }, |
{ | ||
"name": "path-parser", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "A small utility to parse paths", | ||
@@ -15,5 +15,8 @@ "main": "index.js", | ||
"keywords": [ | ||
"path", | ||
"parser", | ||
"path", | ||
"url", | ||
"route", | ||
"match", | ||
"partial match", | ||
"regex" | ||
@@ -20,0 +23,0 @@ ], |
@@ -7,2 +7,3 @@ # path-parser | ||
Partial match allows to determine if a given path starts with the defined pattern. | ||
It is used by [route-node](https://github.com/troch/route-node) | ||
@@ -16,7 +17,7 @@ ## Usage | ||
// Matching | ||
p.match("users/profile/00123") // => {id: "00123"} | ||
p.match('/users/profile/00123') // => {id: "00123"} | ||
// Partial matching: does this path | ||
// starts with that pattern? | ||
p.partialMatch("users/profile/00123/orders") // => {id: "00123"} | ||
p.partialMatch("profile/00123/orders") // => false | ||
p.partialMatch('/users/profile/00123/orders') // => {id: "00123"} | ||
p.partialMatch('/profile/00123/orders') // => false | ||
// Building | ||
@@ -23,0 +24,0 @@ p.build({id: '00123'}) // => "users/profile/00123" |
@@ -42,7 +42,15 @@ 'use strict'; | ||
it('should match build paths with splat parameters', function () { | ||
var path = new Path('/users/*splat/:id'); | ||
var path = new Path('/users/*splat/view/:id'); | ||
path.hasSpatParam.should.be.true; | ||
// Successful match | ||
path.match('/users/profile/view/123').should.eql({ splat: 'profile/view', id: '123' }); | ||
path.match('/users/profile/view/123').should.eql({ splat: 'profile', id: '123' }); | ||
path.match('/users/admin/manage/view/123').should.eql({ splat: 'admin/manage', id: '123' }); | ||
}); | ||
it('should match build paths with url, splat and query parameters', function () { | ||
var path = new Path('/:section/*splat?id'); | ||
path.hasSpatParam.should.be.true; | ||
// Successful match | ||
path.match('/users/profile/view?id=123').should.eql({ section: 'users', splat: 'profile/view', id: '123' }); | ||
}) | ||
}); |
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
17774
8
364
35