Socket
Socket
Sign inDemoInstall

path-parser

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

path-parser - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

.travis.yml

4

index.js

@@ -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&param2

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' });
})
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc