Skip to content
Permalink
Browse files

url: move to module.exports = {} pattern

PR-URL: #12717
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com
  • Loading branch information...
jasnell committed Apr 28, 2017
1 parent 7c238be commit b331ba6ca9acaa9ae3525d75280e0d47463fab4b
Showing with 26 additions and 11 deletions.
  1. +26 −11 lib/url.js
@@ -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;
@@ -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);
@@ -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.
You can’t perform that action at this time.