Comparing version 0.4.2 to 0.4.3
54
index.js
@@ -103,3 +103,3 @@ var urlParse = require('url').parse; | ||
username: this._parsed.username, | ||
password: this._parsed.password | ||
password: this._parsed.password | ||
}; | ||
@@ -158,18 +158,6 @@ | ||
UrlGrey.prototype.query = function(mergeObject){ | ||
var path; | ||
if (mergeObject === false){ | ||
// clear the query entirely if the input === false | ||
if (arguments.length === 0) { | ||
return querystring.parse(this.queryString()); | ||
} else if (mergeObject === null || mergeObject === false){ | ||
return this.queryString(''); | ||
} | ||
var url = this.url; | ||
if (!mergeObject){ | ||
var parsed = urlParse(url); | ||
if (!!parsed.search){ | ||
var qstr = parsed.search.substring(1); | ||
var output = querystring.parse(qstr); | ||
return output; | ||
} | ||
return {}; | ||
} else { | ||
@@ -186,3 +174,4 @@ // read the object out | ||
var newString = querystring.stringify(oldQuery); | ||
return this.queryString(newString); | ||
var ret = this.queryString(newString); | ||
return ret; | ||
} | ||
@@ -193,16 +182,14 @@ }; | ||
UrlGrey.prototype.rawQuery = function(mergeObject){ | ||
var path; | ||
if (mergeObject === false){ | ||
// clear the query entirely if the input === false | ||
if (arguments.length === 0) { | ||
if (this.queryString().length === 0) { return {}; } | ||
return this.queryString().split("&").reduce(function(obj, pair) { | ||
pair = pair.split("="); | ||
var key = pair[0]; | ||
var val = pair[1]; | ||
obj[key] = val; | ||
return obj; | ||
}, {}); | ||
} else if (mergeObject === null || mergeObject === false){ | ||
return this.queryString(''); | ||
} | ||
var url = this.url; | ||
if (!mergeObject){ | ||
var parsed = urlParse(url); | ||
if (!!parsed.search){ | ||
var qstr = parsed.search.substring(1); | ||
return querystring.parse(qstr); | ||
} | ||
return {}; | ||
} else { | ||
@@ -212,3 +199,3 @@ // read the object out | ||
objectEach(mergeObject, function(v, k){ | ||
if (v === null || v === false){ | ||
if (v === null){ | ||
delete oldQuery[k]; | ||
@@ -449,3 +436,5 @@ } else { | ||
UrlGrey.prototype[methodName] = function(str){ | ||
if (!!str || str === ''){ | ||
if (!str && str !== "") { | ||
return this.parsed()[propertyName]; | ||
} else { | ||
var obj = new UrlGrey(this.toString()); | ||
@@ -455,3 +444,2 @@ obj.parsed()[propertyName] = str; | ||
} | ||
return this.parsed()[propertyName]; | ||
}; | ||
@@ -458,0 +446,0 @@ } |
@@ -8,3 +8,3 @@ { | ||
], | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"bugs": { | ||
@@ -11,0 +11,0 @@ "url": "https://github.com/cainus/urlgrey/issues" |
@@ -297,8 +297,12 @@ var isBrowser = !(typeof module !== 'undefined' && module.exports); | ||
it("sets the queryString", function(){ | ||
urlgrey("http://s.asdf.com").queryString('asdf=1234') | ||
.toString().should.equal("http://s.asdf.com?asdf=1234"); | ||
var updated = urlgrey("http://s.asdf.com").queryString('foo=1234'); | ||
updated.toString().should.equal("http://s.asdf.com?foo=1234"); | ||
updated.query().should.deep.equal({foo: "1234"}); | ||
}); | ||
it("updates the queryString", function(){ | ||
urlgrey("http://s.asdf.com?asdf=1234").queryString('qwer=1235') | ||
.toString().should.equal("http://s.asdf.com?qwer=1235"); | ||
it("changes the queryString", function(){ | ||
var updated = urlgrey("http://s.asdf.com?foo=1234&bar=5678").queryString('baz=3456'); | ||
updated.toString().should.equal("http://s.asdf.com?baz=3456"); | ||
updated.query().should.deep.equal({baz: "3456"}); | ||
}); | ||
@@ -318,22 +322,35 @@ it("gets the queryString", function(){ | ||
it("adds a querystring", function(){ | ||
urlgrey("http://asdf.com").rawQuery({asdf:'12 34'}) | ||
.toString().should.equal("http://asdf.com?asdf=12 34"); | ||
var updated = urlgrey("http://asdf.com").rawQuery({foo:'12 34'}); | ||
updated.toString().should.equal("http://asdf.com?foo=12 34"); | ||
updated.rawQuery().should.deep.equal({foo: "12 34"}); | ||
}); | ||
it("appends a querystring", function(){ | ||
var updated = urlgrey("http://asdf.com?foo=1234").rawQuery({bar:'56 78'}); | ||
updated.toString().should.equal("http://asdf.com?foo=1234&bar=56 78"); | ||
updated.rawQuery().should.deep.equal({foo: "1234", bar: "56 78"}); | ||
}); | ||
it("modifies a querystring", function(){ | ||
urlgrey("http://asdf.com?asdf=5678&b=2").rawQuery({asdf:'12 34'}) | ||
.toString().should.equal("http://asdf.com?asdf=12 34&b=2"); | ||
var updated = urlgrey("http://asdf.com?foo=1234&bar=abcd").rawQuery({foo: "56 78"}); | ||
updated.toString().should.equal("http://asdf.com?foo=56 78&bar=abcd"); | ||
updated.rawQuery().should.deep.equal({foo: "56 78", bar: "abcd"}); | ||
}); | ||
it("clears a querystring", function(){ | ||
urlgrey("http://asdf.com?asdf=5678").rawQuery(false) | ||
.toString().should.equal("http://asdf.com"); | ||
var updated = urlgrey("http://asdf.com?foo=1234").rawQuery(false); | ||
updated.toString().should.equal("http://asdf.com"); | ||
updated.rawQuery().should.deep.equal({}); | ||
}); | ||
it("clears an element of a querystring", function(){ | ||
urlgrey("http://asdf.com?a=1&b=2&c=3&d=4") | ||
.rawQuery({a: 0, b: null, c: false, d: "false", e: "12 34"}) | ||
.toString().should.equal("http://asdf.com?a=0&d=false&e=12 34"); | ||
it("clears an element of a querystring with null or false", function(){ | ||
var updated = urlgrey("http://asdf.com") | ||
.rawQuery({foo: 1, bar: 2, baz: 3}) | ||
.rawQuery({foo: 0, bar: null}); | ||
updated.toString().should.equal("http://asdf.com?foo=0&baz=3"); | ||
updated.rawQuery().should.deep.equal({foo: "0", baz: "3"}); | ||
}); | ||
it("extracts a querystring as an object", function(){ | ||
chai.expect( | ||
urlgrey("http://asdf.com?asdf=56%2078").rawQuery() | ||
).to.eql({asdf:'56 78'}); | ||
urlgrey("http://asdf.com?asdf=56%2078").rawQuery().should.deep.equal({asdf:'56%2078'}); | ||
}); | ||
@@ -343,22 +360,35 @@ }); | ||
it("adds a querystring", function(){ | ||
urlgrey("http://asdf.com").query({asdf:'12 34'}) | ||
.toString().should.equal("http://asdf.com?asdf=12%2034"); | ||
var updated = urlgrey("http://asdf.com").query({foo:'12 34'}); | ||
updated.toString().should.equal("http://asdf.com?foo=12%2034"); | ||
updated.query().should.deep.equal({foo: "12 34"}); | ||
}); | ||
it("appends a querystring", function(){ | ||
var updated = urlgrey("http://asdf.com?foo=1234").query({bar:'56 78'}); | ||
updated.toString().should.equal("http://asdf.com?foo=1234&bar=56%2078"); | ||
updated.query().should.deep.equal({foo: "1234", bar: "56 78"}); | ||
}); | ||
it("modifies a querystring", function(){ | ||
urlgrey("http://asdf.com?asdf=5678&b=2").query({asdf:1234}) | ||
.toString().should.equal("http://asdf.com?asdf=1234&b=2"); | ||
var updated = urlgrey("http://asdf.com?foo=1234&bar=abcd").query({foo: "56 78"}); | ||
updated.toString().should.equal("http://asdf.com?foo=56%2078&bar=abcd"); | ||
updated.query().should.deep.equal({foo: "56 78", bar: "abcd"}); | ||
}); | ||
it("clears a querystring", function(){ | ||
urlgrey("http://asdf.com?asdf=5678").query(false) | ||
.toString().should.equal("http://asdf.com"); | ||
var updated = urlgrey("http://asdf.com?foo=1234").query(false); | ||
updated.toString().should.equal("http://asdf.com"); | ||
updated.query().should.deep.equal({}); | ||
}); | ||
it("clears an element of a querystring", function(){ | ||
urlgrey("http://asdf.com?a=1&b=2&c=3&d=4") | ||
.query({a: 0, b: null, c: false, d: "false", e: "12 34"}) | ||
.toString().should.equal("http://asdf.com?a=0&d=false&e=12%2034"); | ||
it("clears an element of a querystring with null or false", function(){ | ||
var updated = urlgrey("http://asdf.com") | ||
.rawQuery({foo: 1, bar: 2, baz: 3}) | ||
.rawQuery({foo: 0, bar: null}); | ||
updated.toString().should.equal("http://asdf.com?foo=0&baz=3"); | ||
updated.query().should.deep.equal({foo: "0", baz: "3"}); | ||
}); | ||
it("extracts a querystring as an object", function(){ | ||
chai.expect( | ||
urlgrey("http://asdf.com?asdf=56%2078").query() | ||
).to.eql({asdf:'56 78'}); | ||
urlgrey("http://asdf.com?asdf=56%2078").query().should.deep.equal({asdf:'56 78'}); | ||
}); | ||
@@ -365,0 +395,0 @@ }); |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
446098
22
10761
2