main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 | var $ = require('../internals/export');
|
---|
3 | var getBuiltIn = require('../internals/get-built-in');
|
---|
4 | var fails = require('../internals/fails');
|
---|
5 | var validateArgumentsLength = require('../internals/validate-arguments-length');
|
---|
6 | var toString = require('../internals/to-string');
|
---|
7 | var USE_NATIVE_URL = require('../internals/url-constructor-detection');
|
---|
8 |
|
---|
9 | var URL = getBuiltIn('URL');
|
---|
10 |
|
---|
11 | // https://github.com/nodejs/node/issues/47505
|
---|
12 | // https://github.com/denoland/deno/issues/18893
|
---|
13 | var THROWS_WITHOUT_ARGUMENTS = USE_NATIVE_URL && fails(function () {
|
---|
14 | URL.canParse();
|
---|
15 | });
|
---|
16 |
|
---|
17 | // Bun ~ 1.0.30 bug
|
---|
18 | // https://github.com/oven-sh/bun/issues/9250
|
---|
19 | var WRONG_ARITY = fails(function () {
|
---|
20 | return URL.canParse.length !== 1;
|
---|
21 | });
|
---|
22 |
|
---|
23 | // `URL.canParse` method
|
---|
24 | // https://url.spec.whatwg.org/#dom-url-canparse
|
---|
25 | $({ target: 'URL', stat: true, forced: !THROWS_WITHOUT_ARGUMENTS || WRONG_ARITY }, {
|
---|
26 | canParse: function canParse(url) {
|
---|
27 | var length = validateArgumentsLength(arguments.length, 1);
|
---|
28 | var urlString = toString(url);
|
---|
29 | var base = length < 2 || arguments[1] === undefined ? undefined : toString(arguments[1]);
|
---|
30 | try {
|
---|
31 | return !!new URL(urlString, base);
|
---|
32 | } catch (error) {
|
---|
33 | return false;
|
---|
34 | }
|
---|
35 | }
|
---|
36 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.