Socket
Socket
Sign inDemoInstall

url-assembler

Package Overview
Dependencies
2
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

test.js

10

index.js

@@ -23,5 +23,9 @@ var extend = require('extend');

if(!value && typeof key === 'object') {
for (var i in key) {
if (nullOrUndef(key[i]))
delete key[i];
}
query = extend(query, key);
}
else {
else if (!nullOrUndef(value)) {
query[key] = value;

@@ -74,1 +78,5 @@ }

};
function nullOrUndef (value) {
return value === null || typeof value === 'undefined';
}

6

package.json
{
"name": "url-assembler",
"version": "0.0.2",
"version": "0.0.3",
"description": "Assemble urls from route-like templates (/path/:param)",
"main": "index.js",
"scripts": {
"test": "istanbul cover --print detail _mocha -- -R spec test"
"test": "istanbul cover --print detail _mocha -- -R spec test",
"coveralls": "cat coverage/lcov.info | coveralls"
},

@@ -30,2 +31,3 @@ "repository": {

"chai": "^1.10.0",
"coveralls": "^2.11.2",
"istanbul": "^0.3.3",

@@ -32,0 +34,0 @@ "mocha": "^2.0.1"

@@ -37,2 +37,10 @@ var expect = require('chai').expect

it('does not add the query parameter if it has a null value', function () {
expect(myUrl.query('param', null).toString()).to.equal('/hello');
})
it('keeps the query parameter if it has a falsy yet correct value', function () {
expect(myUrl.query('param', 0).toString()).to.equal('/hello?param=0');
});
describe('called with a hash map', function () {

@@ -47,2 +55,21 @@ it('adds each of it to the query string', function () {

it('does not add the query parameters which are null', function () {
myUrl.query({
'hello': 'goodbye',
'one': null,
'goodbye': 'hello'
})
expect(myUrl.toString()).to.equal('/hello?hello=goodbye&goodbye=hello');
});
it('keeps falsy values if they are correct', function () {
myUrl.query({
'hello': 'goodbye',
'two': '',
'three': 0,
'goodbye': 'hello'
})
expect(myUrl.toString()).to.equal('/hello?hello=goodbye&two=&three=0&goodbye=hello');
});
describe('when some query param have already been set', function () {

@@ -49,0 +76,0 @@ beforeEach(function () {

@@ -36,2 +36,14 @@ var expect = require('chai').expect

describe('when passed to url.format', function () {
beforeEach(function () {
myUrl.prefix('/v4').segment('/users/:user').segment('/rights');
});
it('should give the same output as toString()', function () {
var url = require('url');
myUrl.param('user', 'floby');
var expected = myUrl.toString();
expect(url.format(myUrl)).to.equal(expected);
});
})
});

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc