path-parser
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -85,3 +85,3 @@ 'use strict'; | ||
this.hasUrlParams = this.tokens.filter(function (t) { | ||
return /url-parameter/.test(t.type); | ||
return /^url-parameter/.test(t.type); | ||
}).length > 0; | ||
@@ -96,3 +96,3 @@ this.hasSpatParam = 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) { | ||
@@ -187,3 +187,3 @@ return t.val; | ||
}).map(function (t) { | ||
return t.type === 'url-parameter' ? params[t.val[0]] : t.match; | ||
return /^url-parameter/.test(t.type) ? params[t.val[0]] : t.match; | ||
}).join(''); | ||
@@ -190,0 +190,0 @@ |
@@ -73,3 +73,3 @@ const rules = [ | ||
this.hasUrlParams = this.tokens.filter(t => /url-parameter/.test(t.type)).length > 0 | ||
this.hasUrlParams = this.tokens.filter(t => /^url-parameter/.test(t.type)).length > 0 | ||
this.hasSpatParam = this.tokens.filter(t => /splat/.test(t.type)).length > 0 | ||
@@ -79,3 +79,3 @@ this.hasQueryParams = this.tokens.filter(t => t.type === 'query-parameter').length > 0 | ||
this.urlParams = !this.hasUrlParams ? [] : this.tokens | ||
.filter(t => /url-parameter/.test(t.type)) | ||
.filter(t => /^url-parameter/.test(t.type)) | ||
.map(t => t.val) | ||
@@ -147,3 +147,3 @@ // Flatten | ||
.filter(t => t.type !== 'query-parameter') | ||
.map(t => t.type === 'url-parameter' ? params[t.val[0]] : t.match) | ||
.map(t => /^url-parameter/.test(t.type) ? params[t.val[0]] : t.match) | ||
.join('') | ||
@@ -150,0 +150,0 @@ |
{ | ||
"name": "path-parser", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "A small utility to parse paths", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,3 @@ | ||
[![Build Status](https://travis-ci.org/troch/path-parser.svg)](https://travis-ci.org/troch/path-parser) | ||
# path-parser | ||
@@ -2,0 +4,0 @@ |
@@ -42,2 +42,12 @@ 'use strict'; | ||
it('should match build paths with splat parameters', function () { | ||
var path = new Path('/users/*splat'); | ||
path.hasSpatParam.should.be.true; | ||
// Successful match | ||
path.match('/users/profile/123').should.eql({ splat: 'profile/123'}); | ||
path.match('/users/admin/manage/view/123').should.eql({ splat: 'admin/manage/view/123'}); | ||
// Build path | ||
path.build({ splat: 'profile/123'}).should.equal('/users/profile/123'); | ||
}); | ||
it('should match build paths with splat and url parameters', function () { | ||
var path = new Path('/users/*splat/view/:id'); | ||
@@ -55,3 +65,4 @@ path.hasSpatParam.should.be.true; | ||
path.match('/users/profile/view?id=123').should.eql({ section: 'users', splat: 'profile/view', id: '123' }); | ||
path.build({section: 'users', splat: 'profile/view', id: '123'}).should.equal('/users/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
18488
374
37