Skip to content

Commit

Permalink
url: move to module.exports = {} pattern
Browse files Browse the repository at this point in the history
PR-URL: #12717
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com
  • Loading branch information
jasnell committed Apr 29, 2017
1 parent 7c238be commit b331ba6
Showing 1 changed file with 26 additions and 11 deletions.
37 changes: 26 additions & 11 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@

const { toASCII } = process.binding('config').hasIntl ?
process.binding('icu') : require('punycode');

const { hexTable } = require('internal/querystring');
const internalUrl = require('internal/url');
exports.parse = urlParse;
exports.resolve = urlResolve;
exports.resolveObject = urlResolveObject;
exports.format = urlFormat;
exports.URL = internalUrl.URL;
exports.URLSearchParams = internalUrl.URLSearchParams;
exports.domainToASCII = internalUrl.domainToASCII;
exports.domainToUnicode = internalUrl.domainToUnicode;

// WHATWG URL implementation provided by internal/url
const {
URL,
URLSearchParams,
domainToASCII,
domainToUnicode,
formatSymbol
} = require('internal/url');

exports.Url = Url;
// Original url.parse() API

function Url() {
this.protocol = null;
Expand Down Expand Up @@ -559,7 +559,7 @@ function urlFormat(obj, options) {
throw new TypeError('Parameter "urlObj" must be an object, not ' +
(obj === null ? 'null' : typeof obj));
} else if (!(obj instanceof Url)) {
var format = obj[internalUrl.formatSymbol];
var format = obj[formatSymbol];
return format ?
format.call(obj, options) :
Url.prototype.format.call(obj);
Expand Down Expand Up @@ -1030,3 +1030,18 @@ function encodeAuth(str) {
return out + str.slice(lastPos);
return out;
}

module.exports = {
// Original API
Url,
parse: urlParse,
resolve: urlResolve,
resolveObject: urlResolveObject,
format: urlFormat,

// WHATWG API
URL,
URLSearchParams,
domainToASCII,
domainToUnicode
};

0 comments on commit b331ba6

Please sign in to comment.