diff options
author | cjihrig <cjihrig@gmail.com> | 2015-01-28 20:05:53 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2015-01-31 23:47:29 -0500 |
commit | 6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40 (patch) | |
tree | 29a3b1ce92cfad3ae5d41a4ba7451846beace950 /lib/url.js | |
parent | bce7a2608eb198eee6ecd7991062efd6daeeb440 (diff) | |
download | android-node-v8-6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40.tar.gz android-node-v8-6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40.tar.bz2 android-node-v8-6ac8bdc0aba5f60f4b4f2da5abd36d664062aa40.zip |
lib: reduce util.is*() usage
Many of the util.is*() methods used to check data types
simply compare against a single value or the result of
typeof. This commit replaces calls to these methods with
equivalent checks. This commit does not touch calls to the
more complex methods (isRegExp(), isDate(), etc.).
Fixes: https://github.com/iojs/io.js/issues/607
PR-URL: https://github.com/iojs/io.js/pull/647
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib/url.js')
-rw-r--r-- | lib/url.js | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/lib/url.js b/lib/url.js index 50126ae9bf..65012cd7c4 100644 --- a/lib/url.js +++ b/lib/url.js @@ -1,7 +1,6 @@ 'use strict'; const punycode = require('punycode'); -const util = require('util'); exports.parse = urlParse; exports.resolve = urlResolve; @@ -79,7 +78,7 @@ const slashedProtocol = { const querystring = require('querystring'); function urlParse(url, parseQueryString, slashesDenoteHost) { - if (url && util.isObject(url) && url instanceof Url) return url; + if (url instanceof Url) return url; var u = new Url; u.parse(url, parseQueryString, slashesDenoteHost); @@ -87,7 +86,7 @@ function urlParse(url, parseQueryString, slashesDenoteHost) { } Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { - if (!util.isString(url)) { + if (typeof url !== 'string') { throw new TypeError("Parameter 'url' must be a string, not " + typeof url); } @@ -353,7 +352,7 @@ function urlFormat(obj) { // If it's an obj, this is a no-op. // this way, you can call url_format() on strings // to clean up potentially wonky urls. - if (util.isString(obj)) obj = urlParse(obj); + if (typeof obj === 'string') obj = urlParse(obj); if (!(obj instanceof Url)) return Url.prototype.format.call(obj); return obj.format(); } @@ -383,8 +382,8 @@ Url.prototype.format = function() { } } - if (this.query && - util.isObject(this.query) && + if (this.query !== null && + typeof this.query === 'object' && Object.keys(this.query).length) { query = querystring.stringify(this.query); } @@ -428,7 +427,7 @@ function urlResolveObject(source, relative) { } Url.prototype.resolveObject = function(relative) { - if (util.isString(relative)) { + if (typeof relative === 'string') { var rel = new Url(); rel.parse(relative, false, true); relative = rel; @@ -574,7 +573,7 @@ Url.prototype.resolveObject = function(relative) { srcPath = srcPath.concat(relPath); result.search = relative.search; result.query = relative.query; - } else if (!util.isNullOrUndefined(relative.search)) { + } else if (relative.search !== null && relative.search !== undefined) { // just pull out the search. // like href='?foo'. // Put this after the other two cases because it simplifies the booleans @@ -593,7 +592,7 @@ Url.prototype.resolveObject = function(relative) { result.search = relative.search; result.query = relative.query; //to support http.request - if (!util.isNull(result.pathname) || !util.isNull(result.search)) { + if (result.pathname !== null || result.search !== null) { result.path = (result.pathname ? result.pathname : '') + (result.search ? result.search : ''); } @@ -687,7 +686,7 @@ Url.prototype.resolveObject = function(relative) { } //to support request.http - if (!util.isNull(result.pathname) || !util.isNull(result.search)) { + if (result.pathname !== null || result.search !== null) { result.path = (result.pathname ? result.pathname : '') + (result.search ? result.search : ''); } |