You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
huazhiyu/node_modules/core-js/modules/web.url.can-parse.js

30 lines
1.0 KiB

'use strict';
var $ = require('../internals/export');
var getBuiltIn = require('../internals/get-built-in');
var fails = require('../internals/fails');
var validateArgumentsLength = require('../internals/validate-arguments-length');
var toString = require('../internals/to-string');
var USE_NATIVE_URL = require('../internals/url-constructor-detection');
var URL = getBuiltIn('URL');
// https://github.com/nodejs/node/issues/47505
// https://github.com/denoland/deno/issues/18893
var THROWS_WITHOUT_ARGUMENTS = USE_NATIVE_URL && fails(function () {
URL.canParse();
});
// `URL.canParse` method
// https://url.spec.whatwg.org/#dom-url-canparse
$({ target: 'URL', stat: true, forced: !THROWS_WITHOUT_ARGUMENTS }, {
canParse: function canParse(url) {
var length = validateArgumentsLength(arguments.length, 1);
var urlString = toString(url);
var base = length < 2 || arguments[1] === undefined ? undefined : toString(arguments[1]);
try {
return !!new URL(urlString, base);
} catch (error) {
return false;
}
}
});