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.3 to 0.0.4

8

index.js

@@ -30,3 +30,3 @@ 'use strict';

name: 'delimiter',
pattern: /^(\/|\?|#)/,
pattern: /^(\/|\?)/,
regex: function regex(match) {

@@ -38,3 +38,3 @@ return new RegExp(match[0]);

name: 'sub-delimiter',
pattern: /^(\!|\&|,|;|\-|_)/,
pattern: /^(\!|\&|\-|_|\.)/,
regex: function regex(match) {

@@ -46,3 +46,3 @@ return new RegExp(match[0]);

name: 'fragment',
pattern: /^(.*?)(?=\/|\?|\#|$)/,
pattern: /^([0-9a-zA-Z]+?)/,
regex: function regex(match) {

@@ -157,3 +157,3 @@ return new RegExp(match[0]);

if (Object.keys(queryParams).every(function (p) {
return _this2.queryParams.indexOf(p) !== 1;
return Object.keys(_this2.queryParams).indexOf(p) !== 1;
}) && Object.keys(queryParams).length === this.queryParams.length) {

@@ -160,0 +160,0 @@ // Extend url match

@@ -25,3 +25,3 @@ const rules = [

name: 'delimiter',
pattern: /^(\/|\?|#)/,
pattern: /^(\/|\?)/,
regex: match => new RegExp(match[0])

@@ -32,3 +32,3 @@ },

name: 'sub-delimiter',
pattern: /^(\!|\&|,|;|\-|_)/,
pattern: /^(\!|\&|\-|_|\.)/,
regex: match => new RegExp(match[0])

@@ -39,3 +39,3 @@ },

name: 'fragment',
pattern: /^(.*?)(?=\/|\?|\#|$)/,
pattern: /^([0-9a-zA-Z]+?)/,
regex: match => new RegExp(match[0])

@@ -125,3 +125,3 @@ }

if (Object.keys(queryParams).every(p => this.queryParams.indexOf(p) !== 1)
if (Object.keys(queryParams).every(p => Object.keys(this.queryParams).indexOf(p) !== 1)
&& Object.keys(queryParams).length === this.queryParams.length) {

@@ -128,0 +128,0 @@ // Extend url match

{
"name": "path-parser",
"version": "0.0.3",
"version": "0.0.4",
"description": "A small utility to parse paths",
"main": "index.js",
"scripts": {
"test": "_mocha",
"test": "node ./node_modules/mocha/bin/_mocha",
"test-cover": "node ./node_modules/istanbul/lib/cli.js cover ./node_modules/mocha/bin/_mocha",
"build": "./node_modules/.bin/babel -m common lib/Path.js > index.js"

@@ -32,4 +33,6 @@ },

"mocha": "^2.2.5",
"babel": "^5.5.8"
"babel": "^5.5.8",
"coveralls": "^2.11.2",
"istanbul": "^0.3.16"
}
}

@@ -15,2 +15,14 @@ 'use strict';

it('should throw an error if Path is used like a function', function () {
(function () {
Path()
}).should.throw();
});
it('should throw an error if a path cannot be tokenised', function () {
(function () {
new Path('/!#')
}).should.throw();
});
it('should match and build paths with url parameters', function () {

@@ -26,6 +38,21 @@ var path = new Path('/users/profile/:id-:id2.html');

path.build({ id: '123', id2: 'abc' }).should.equal('/users/profile/123-abc.html')
path.build({ id: '123', id2: 'abc' }).should.equal('/users/profile/123-abc.html');
(function () {
path.build({ id: '123'});
}).should.throw('Missing parameters');
});
it('should match build paths with url and query parameters', function () {
it('should match and build paths with query parameters', function () {
var path = new Path('/users?offset&limit');
// Successful match & partial match
path.match('/users?offset=31&limit=15').should.eql({ offset: '31', limit: '15' });
// path.partialMatch('/users').should.eql({});
// Unsuccessful match
path.match('/users?offset=31').should.be.false;
path.match('/users?limit=15').should.be.false;
path.build({ offset: 31, limit: 15 }).should.equal('/users?offset=31&limit=15')
});
it('should match and build paths with url and query parameters', function () {
var path = new Path('/users/profile/:id-:id2?:id3');

@@ -32,0 +59,0 @@ path.hasQueryParams.should.be.true;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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