file_path
stringlengths
3
280
file_language
stringclasses
66 values
content
stringlengths
1
1.04M
repo_name
stringlengths
5
92
repo_stars
int64
0
154k
repo_description
stringlengths
0
402
repo_primary_language
stringclasses
108 values
developer_username
stringlengths
1
25
developer_name
stringlengths
0
30
developer_company
stringlengths
0
82
tests/unit-pure/esnext.reflect.get-own-metadata-keys.js
JavaScript
import create from 'core-js-pure/full/object/create'; import defineMetadata from 'core-js-pure/full/reflect/define-metadata'; import getOwnMetadataKeys from 'core-js-pure/full/reflect/get-own-metadata-keys'; QUnit.test('Reflect.getOwnMetadataKeys', assert => { assert.isFunction(getOwnMetadataKeys); assert.arity(getOwnMetadataKeys, 1); assert.throws(() => getOwnMetadataKeys(undefined, undefined), TypeError); assert.deepEqual(getOwnMetadataKeys({}, undefined), []); let object = {}; defineMetadata('key', 'value', object, undefined); assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key']); let prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, undefined); assert.deepEqual(getOwnMetadataKeys(object, undefined), []); object = {}; defineMetadata('key0', 'value', object, undefined); defineMetadata('key1', 'value', object, undefined); assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key0', 'key1']); object = {}; defineMetadata('key0', 'value', object, undefined); defineMetadata('key1', 'value', object, undefined); defineMetadata('key0', 'value', object, undefined); assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key0', 'key1']); prototype = {}; defineMetadata('key2', 'value', prototype, undefined); object = create(prototype); defineMetadata('key0', 'value', object, undefined); defineMetadata('key1', 'value', object, undefined); assert.deepEqual(getOwnMetadataKeys(object, undefined), ['key0', 'key1']); assert.deepEqual(getOwnMetadataKeys({}, 'name'), []); object = {}; defineMetadata('key', 'value', object, 'name'); assert.deepEqual(getOwnMetadataKeys(object, 'name'), ['key']); prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, 'name'); assert.deepEqual(getOwnMetadataKeys(object, 'name'), []); object = {}; defineMetadata('key0', 'value', object, 'name'); defineMetadata('key1', 'value', object, 'name'); defineMetadata('key0', 'value', object, 'name'); assert.deepEqual(getOwnMetadataKeys(object, 'name'), ['key0', 'key1']); prototype = {}; defineMetadata('key2', 'value', prototype, 'name'); object = create(prototype); defineMetadata('key0', 'value', object, 'name'); defineMetadata('key1', 'value', object, 'name'); assert.deepEqual(getOwnMetadataKeys(object, 'name'), ['key0', 'key1']); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.reflect.get-own-metadata.js
JavaScript
import create from 'core-js-pure/full/object/create'; import defineMetadata from 'core-js-pure/full/reflect/define-metadata'; import getOwnMetadata from 'core-js-pure/full/reflect/get-own-metadata'; QUnit.test('Reflect.getOwnMetadata', assert => { assert.isFunction(getOwnMetadata); assert.arity(getOwnMetadata, 2); assert.throws(() => getOwnMetadata('key', undefined, undefined), TypeError); assert.same(getOwnMetadata('key', {}, undefined), undefined); let object = {}; defineMetadata('key', 'value', object, undefined); assert.same(getOwnMetadata('key', object, undefined), 'value'); let prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, undefined); assert.same(getOwnMetadata('key', object, undefined), undefined); assert.same(getOwnMetadata('key', {}, 'name'), undefined); object = {}; defineMetadata('key', 'value', object, 'name'); assert.same(getOwnMetadata('key', object, 'name'), 'value'); prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, 'name'); assert.same(getOwnMetadata('key', object, 'name'), undefined); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.reflect.has-metadata.js
JavaScript
import create from 'core-js-pure/full/object/create'; import defineMetadata from 'core-js-pure/full/reflect/define-metadata'; import hasMetadata from 'core-js-pure/full/reflect/has-metadata'; QUnit.test('Reflect.hasMetadata', assert => { assert.isFunction(hasMetadata); assert.arity(hasMetadata, 2); assert.throws(() => hasMetadata('key', undefined, undefined), TypeError); assert.false(hasMetadata('key', {}, undefined)); let object = {}; defineMetadata('key', 'value', object, undefined); assert.true(hasMetadata('key', object, undefined)); let prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, undefined); assert.true(hasMetadata('key', object, undefined)); assert.false(hasMetadata('key', {}, 'name')); object = {}; defineMetadata('key', 'value', object, 'name'); assert.true(hasMetadata('key', object, 'name')); prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, 'name'); assert.true(hasMetadata('key', object, 'name')); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.reflect.has-own-metadata.js
JavaScript
import create from 'core-js-pure/full/object/create'; import defineMetadata from 'core-js-pure/full/reflect/define-metadata'; import hasOwnMetadata from 'core-js-pure/full/reflect/has-own-metadata'; QUnit.test('Reflect.hasOwnMetadata', assert => { assert.isFunction(hasOwnMetadata); assert.arity(hasOwnMetadata, 2); assert.throws(() => hasOwnMetadata('key', undefined, undefined), TypeError); assert.false(hasOwnMetadata('key', {}, undefined)); let object = {}; defineMetadata('key', 'value', object, undefined); assert.true(hasOwnMetadata('key', object, undefined)); let prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, undefined); assert.false(hasOwnMetadata('key', object, undefined)); assert.false(hasOwnMetadata('key', {}, 'name')); object = {}; defineMetadata('key', 'value', object, 'name'); assert.true(hasOwnMetadata('key', object, 'name')); prototype = {}; object = create(prototype); defineMetadata('key', 'value', prototype, 'name'); assert.false(hasOwnMetadata('key', object, 'name')); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.reflect.metadata.js
JavaScript
import hasOwnMetadata from 'core-js-pure/full/reflect/has-own-metadata'; import metadata from 'core-js-pure/full/reflect/metadata'; QUnit.test('Reflect.metadata', assert => { assert.isFunction(metadata); assert.arity(metadata, 2); assert.isFunction(metadata('key', 'value')); const decorator = metadata('key', 'value'); assert.throws(() => decorator(undefined, 'name'), TypeError); let target = function () { /* empty */ }; decorator(target); assert.true(hasOwnMetadata('key', target, undefined)); target = {}; decorator(target, 'name'); assert.true(hasOwnMetadata('key', target, 'name')); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.add-all.js
JavaScript
import from from 'core-js-pure/es/array/from'; import Set from 'core-js-pure/full/set'; QUnit.test('Set#addAll', assert => { const { addAll } = Set.prototype; assert.isFunction(addAll); assert.arity(addAll, 0); assert.name(addAll, 'addAll'); assert.nonEnumerable(Set.prototype, 'addAll'); const set = new Set([1]); assert.same(set.addAll(2), set); assert.deepEqual(from(new Set([1, 2, 3]).addAll(4, 5)), [1, 2, 3, 4, 5]); assert.deepEqual(from(new Set([1, 2, 3]).addAll(3, 4)), [1, 2, 3, 4]); assert.deepEqual(from(new Set([1, 2, 3]).addAll()), [1, 2, 3]); assert.throws(() => addAll.call({ add() { /* empty */ } }, 1, 2, 3)); assert.throws(() => addAll.call({}, 1, 2, 3), TypeError); assert.throws(() => addAll.call(undefined, 1, 2, 3), TypeError); assert.throws(() => addAll.call(null, 1, 2, 3), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.delete-all.js
JavaScript
import from from 'core-js-pure/es/array/from'; import Set from 'core-js-pure/full/set'; QUnit.test('Set#deleteAll', assert => { const { deleteAll } = Set.prototype; assert.isFunction(deleteAll); assert.arity(deleteAll, 0); assert.name(deleteAll, 'deleteAll'); assert.nonEnumerable(Set.prototype, 'deleteAll'); let set = new Set([1, 2, 3]); assert.true(set.deleteAll(1, 2)); assert.deepEqual(from(set), [3]); set = new Set([1, 2, 3]); assert.false(set.deleteAll(3, 4)); assert.deepEqual(from(set), [1, 2]); set = new Set([1, 2, 3]); assert.false(set.deleteAll(4, 5)); assert.deepEqual(from(set), [1, 2, 3]); set = new Set([1, 2, 3]); assert.true(set.deleteAll()); assert.deepEqual(from(set), [1, 2, 3]); assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, 1, 2, 3)); assert.throws(() => deleteAll.call({}, 1, 2, 3), TypeError); assert.throws(() => deleteAll.call(undefined, 1, 2, 3), TypeError); assert.throws(() => deleteAll.call(null, 1, 2, 3), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.every.js
JavaScript
import Set from 'core-js-pure/full/set'; QUnit.test('Set#every', assert => { const { every } = Set.prototype; assert.isFunction(every); assert.arity(every, 1); assert.name(every, 'every'); assert.nonEnumerable(Set.prototype, 'every'); const set = new Set([1]); const context = {}; set.every(function (value, key, that) { assert.same(arguments.length, 3, 'correct number of callback arguments'); assert.same(value, 1, 'correct value in callback'); assert.same(key, 1, 'correct key in callback'); assert.same(that, set, 'correct link to set in callback'); assert.same(this, context, 'correct callback context'); }, context); assert.true(new Set([1, 2, 3]).every(it => typeof it == 'number')); assert.false(new Set(['1', '2', '3']).some(it => typeof it == 'number')); assert.false(new Set([1, '2', 3]).every(it => typeof it == 'number')); assert.true(new Set().every(it => typeof it == 'number')); assert.throws(() => every.call({}, () => { /* empty */ }), TypeError); assert.throws(() => every.call(undefined, () => { /* empty */ }), TypeError); assert.throws(() => every.call(null, () => { /* empty */ }), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.filter.js
JavaScript
import from from 'core-js-pure/es/array/from'; import Set from 'core-js-pure/full/set'; QUnit.test('Set#filter', assert => { const { filter } = Set.prototype; assert.isFunction(filter); assert.arity(filter, 1); assert.name(filter, 'filter'); assert.nonEnumerable(Set.prototype, 'filter'); const set = new Set([1]); const context = {}; set.filter(function (value, key, that) { assert.same(arguments.length, 3, 'correct number of callback arguments'); assert.same(value, 1, 'correct value in callback'); assert.same(key, 1, 'correct key in callback'); assert.same(that, set, 'correct link to set in callback'); assert.same(this, context, 'correct callback context'); }, context); assert.true(new Set().filter(it => it) instanceof Set); assert.deepEqual(from(new Set([1, 2, 3, 'q', {}, 4, true, 5]).filter(it => typeof it == 'number')), [1, 2, 3, 4, 5]); assert.throws(() => filter.call({}, () => { /* empty */ }), TypeError); assert.throws(() => filter.call(undefined, () => { /* empty */ }), TypeError); assert.throws(() => filter.call(null, () => { /* empty */ }), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.find.js
JavaScript
import Set from 'core-js-pure/full/set'; QUnit.test('Set#find', assert => { const { find } = Set.prototype; assert.isFunction(find); assert.arity(find, 1); assert.name(find, 'find'); assert.nonEnumerable(Set.prototype, 'find'); const set = new Set([1]); const context = {}; set.find(function (value, key, that) { assert.same(arguments.length, 3, 'correct number of callback arguments'); assert.same(value, 1, 'correct value in callback'); assert.same(key, 1, 'correct key in callback'); assert.same(that, set, 'correct link to set in callback'); assert.same(this, context, 'correct callback context'); }, context); assert.same(new Set([2, 3, 4]).find(it => it % 2), 3); assert.same(new Set().find(it => it === 42), undefined); assert.throws(() => find.call({}, () => { /* empty */ }), TypeError); assert.throws(() => find.call(undefined, () => { /* empty */ }), TypeError); assert.throws(() => find.call(null, () => { /* empty */ }), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.from.js
JavaScript
import { createIterable } from '../helpers/helpers.js'; import toArray from 'core-js-pure/es/array/from'; import Set from 'core-js-pure/full/set'; QUnit.test('Set.from', assert => { const { from } = Set; assert.isFunction(from); assert.arity(from, 1); assert.true(from([]) instanceof Set); assert.deepEqual(toArray(from([])), []); assert.deepEqual(toArray(from([1])), [1]); assert.deepEqual(toArray(from([1, 2, 3, 2, 1])), [1, 2, 3]); assert.deepEqual(toArray(from(createIterable([1, 2, 3, 2, 1]))), [1, 2, 3]); const context = {}; from([1], function (element, index) { assert.same(element, 1); assert.same(index, 0); assert.same(this, context); return element; }, context); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.join.js
JavaScript
/* eslint-disable unicorn/require-array-join-separator -- required for testing */ import Set from 'core-js-pure/full/set'; QUnit.test('Set#join', assert => { const { join } = Set.prototype; assert.isFunction(join); assert.arity(join, 1); assert.name(join, 'join'); assert.nonEnumerable(Set.prototype, 'join'); assert.same(new Set([1, 2, 3]).join(), '1,2,3'); assert.same(new Set([1, 2, 3]).join(undefined), '1,2,3'); assert.same(new Set([1, 2, 3]).join('|'), '1|2|3'); assert.throws(() => join.call({}), TypeError); assert.throws(() => join.call(undefined), TypeError); assert.throws(() => join.call(null), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.map.js
JavaScript
import from from 'core-js-pure/es/array/from'; import Set from 'core-js-pure/full/set'; QUnit.test('Set#map', assert => { const { map } = Set.prototype; assert.isFunction(map); assert.arity(map, 1); assert.name(map, 'map'); assert.nonEnumerable(Set.prototype, 'map'); const set = new Set([1]); const context = {}; set.map(function (value, key, that) { assert.same(arguments.length, 3, 'correct number of callback arguments'); assert.same(value, 1, 'correct value in callback'); assert.same(key, 1, 'correct key in callback'); assert.same(that, set, 'correct link to set in callback'); assert.same(this, context, 'correct callback context'); }, context); assert.true(new Set().map(it => it) instanceof Set); assert.deepEqual(from(new Set([1, 2, 3]).map(it => it ** 2)), [1, 4, 9]); assert.deepEqual(from(new Set([1, 2, 3]).map(it => it % 2)), [1, 0]); assert.throws(() => map.call({}, () => { /* empty */ }), TypeError); assert.throws(() => map.call(undefined, () => { /* empty */ }), TypeError); assert.throws(() => map.call(null, () => { /* empty */ }), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.of.js
JavaScript
import from from 'core-js-pure/es/array/from'; import Set from 'core-js-pure/full/set'; QUnit.test('Set.of', assert => { const { of } = Set; assert.isFunction(of); assert.arity(of, 0); assert.true(of() instanceof Set); assert.deepEqual(from(of(1)), [1]); assert.deepEqual(from(of(1, 2, 3, 2, 1)), [1, 2, 3]); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.reduce.js
JavaScript
import Set from 'core-js-pure/full/set'; QUnit.test('Set#reduce', assert => { const { reduce } = Set.prototype; assert.isFunction(reduce); assert.arity(reduce, 1); assert.name(reduce, 'reduce'); assert.nonEnumerable(Set.prototype, 'reduce'); const set = new Set([1]); const accumulator = {}; set.reduce(function (memo, value, key, that) { assert.same(arguments.length, 4, 'correct number of callback arguments'); assert.same(memo, accumulator, 'correct callback accumulator'); assert.same(value, 1, 'correct value in callback'); assert.same(key, 1, 'correct index in callback'); assert.same(that, set, 'correct link to set in callback'); }, accumulator); assert.same(new Set([1, 2, 3]).reduce((a, b) => a + b, 1), 7, 'works with initial accumulator'); new Set([1, 2]).reduce((memo, value, key) => { assert.same(memo, 1, 'correct default accumulator'); assert.same(value, 2, 'correct start value without initial accumulator'); assert.same(key, 2, 'correct start index without initial accumulator'); }); assert.same(new Set([1, 2, 3]).reduce((a, b) => a + b), 6, 'works without initial accumulator'); let values = ''; let keys = ''; new Set([1, 2, 3]).reduce((memo, value, key, s) => { s.delete(2); values += value; keys += key; }, 0); assert.same(values, '13', 'correct order #1'); assert.same(keys, '13', 'correct order #2'); assert.throws(() => reduce.call({}, () => { /* empty */ }, 1), TypeError); assert.throws(() => reduce.call(undefined, () => { /* empty */ }, 1), TypeError); assert.throws(() => reduce.call(null, () => { /* empty */ }, 1), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.set.some.js
JavaScript
import Set from 'core-js-pure/full/set'; QUnit.test('Set#some', assert => { const { some } = Set.prototype; assert.isFunction(some); assert.arity(some, 1); assert.name(some, 'some'); assert.nonEnumerable(Set.prototype, 'some'); const set = new Set([1]); const context = {}; set.some(function (value, key, that) { assert.same(arguments.length, 3, 'correct number of callback arguments'); assert.same(value, 1, 'correct value in callback'); assert.same(key, 1, 'correct key in callback'); assert.same(that, set, 'correct link to set in callback'); assert.same(this, context, 'correct callback context'); }, context); assert.true(new Set([1, 2, 3]).some(it => typeof it == 'number')); assert.false(new Set(['1', '2', '3']).some(it => typeof it == 'number')); assert.true(new Set([1, '2', 3]).some(it => typeof it == 'number')); assert.false(new Set().some(it => typeof it == 'number')); assert.throws(() => some.call({}, () => { /* empty */ }), TypeError); assert.throws(() => some.call(undefined, () => { /* empty */ }), TypeError); assert.throws(() => some.call(null, () => { /* empty */ }), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.string.at.js
JavaScript
import { STRICT } from '../helpers/constants.js'; import at from 'core-js-pure/full/string/at'; QUnit.test('String#at', assert => { assert.isFunction(at); // String that starts with a BMP symbol // assert.same(at('abc\uD834\uDF06def', -Infinity), ''); // assert.same(at('abc\uD834\uDF06def', -1), ''); assert.same(at('abc\uD834\uDF06def', -0), 'a'); assert.same(at('abc\uD834\uDF06def', +0), 'a'); assert.same(at('abc\uD834\uDF06def', 1), 'b'); assert.same(at('abc\uD834\uDF06def', 3), '\uD834\uDF06'); assert.same(at('abc\uD834\uDF06def', 4), '\uDF06'); assert.same(at('abc\uD834\uDF06def', 5), 'd'); // assert.same(at('abc\uD834\uDF06def', 42), ''); // assert.same(at('abc\uD834\uDF06def', Infinity), ''); assert.same(at('abc\uD834\uDF06def', null), 'a'); assert.same(at('abc\uD834\uDF06def', undefined), 'a'); assert.same(at('abc\uD834\uDF06def'), 'a'); assert.same(at('abc\uD834\uDF06def', false), 'a'); assert.same(at('abc\uD834\uDF06def', NaN), 'a'); assert.same(at('abc\uD834\uDF06def', ''), 'a'); assert.same(at('abc\uD834\uDF06def', '_'), 'a'); assert.same(at('abc\uD834\uDF06def', '1'), 'b'); assert.same(at('abc\uD834\uDF06def', []), 'a'); assert.same(at('abc\uD834\uDF06def', {}), 'a'); assert.same(at('abc\uD834\uDF06def', -0.9), 'a'); assert.same(at('abc\uD834\uDF06def', 1.9), 'b'); assert.same(at('abc\uD834\uDF06def', 7.9), 'f'); // assert.same(at('abc\uD834\uDF06def', 2 ** 32), ''); // String that starts with an astral symbol // assert.same(at('\uD834\uDF06def', -Infinity), ''); // assert.same(at('\uD834\uDF06def', -1), ''); assert.same(at('\uD834\uDF06def', -0), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', 0), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', 1), '\uDF06'); assert.same(at('\uD834\uDF06def', 2), 'd'); assert.same(at('\uD834\uDF06def', 3), 'e'); assert.same(at('\uD834\uDF06def', 4), 'f'); // assert.same(at('\uD834\uDF06def', 42), ''); // assert.same(at('\uD834\uDF06def', Infinity), ''); assert.same(at('\uD834\uDF06def', null), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', undefined), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def'), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', false), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', NaN), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', ''), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', '_'), '\uD834\uDF06'); assert.same(at('\uD834\uDF06def', '1'), '\uDF06'); // Lone high surrogates // assert.same(at('\uD834abc', -Infinity), ''); // assert.same(at('\uD834abc', -1), ''); assert.same(at('\uD834abc', -0), '\uD834'); assert.same(at('\uD834abc', 0), '\uD834'); assert.same(at('\uD834abc', 1), 'a'); // assert.same(at('\uD834abc', 42), ''); // assert.same(at('\uD834abc', Infinity), ''); assert.same(at('\uD834abc', null), '\uD834'); assert.same(at('\uD834abc', undefined), '\uD834'); assert.same(at('\uD834abc'), '\uD834'); assert.same(at('\uD834abc', false), '\uD834'); assert.same(at('\uD834abc', NaN), '\uD834'); assert.same(at('\uD834abc', ''), '\uD834'); assert.same(at('\uD834abc', '_'), '\uD834'); assert.same(at('\uD834abc', '1'), 'a'); // Lone low surrogates // assert.same(at('\uDF06abc', -Infinity), ''); // assert.same(at('\uDF06abc', -1), ''); assert.same(at('\uDF06abc', -0), '\uDF06'); assert.same(at('\uDF06abc', 0), '\uDF06'); assert.same(at('\uDF06abc', 1), 'a'); // assert.same(at('\uDF06abc', 42), ''); // assert.same(at('\uDF06abc', Infinity), ''); assert.same(at('\uDF06abc', null), '\uDF06'); assert.same(at('\uDF06abc', undefined), '\uDF06'); assert.same(at('\uDF06abc'), '\uDF06'); assert.same(at('\uDF06abc', false), '\uDF06'); assert.same(at('\uDF06abc', NaN), '\uDF06'); assert.same(at('\uDF06abc', ''), '\uDF06'); assert.same(at('\uDF06abc', '_'), '\uDF06'); assert.same(at('\uDF06abc', '1'), 'a'); assert.same(at(42, 0), '4'); assert.same(at(42, 1), '2'); assert.same(at({ toString() { return 'abc'; }, }, 2), 'c'); if (STRICT) { assert.throws(() => at(null, 0), TypeError); assert.throws(() => at(undefined, 0), TypeError); } });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.string.code-points.js
JavaScript
import Symbol from 'core-js-pure/es/symbol'; import codePoints from 'core-js-pure/full/string/code-points'; QUnit.test('String#codePoints', assert => { assert.isFunction(codePoints); let iterator = codePoints('qwe'); assert.isIterator(iterator); assert.isIterable(iterator); assert.same(iterator[Symbol.toStringTag], 'String Iterator'); assert.same(String(iterator), '[object String Iterator]'); assert.deepEqual(iterator.next(), { value: { codePoint: 113, position: 0 }, done: false, }); assert.deepEqual(iterator.next(), { value: { codePoint: 119, position: 1 }, done: false, }); assert.deepEqual(iterator.next(), { value: { codePoint: 101, position: 2 }, done: false, }); assert.deepEqual(iterator.next(), { value: undefined, done: true, }); iterator = codePoints('𠮷𠮷𠮷'); assert.deepEqual(iterator.next(), { value: { codePoint: 134071, position: 0 }, done: false, }); assert.deepEqual(iterator.next(), { value: { codePoint: 134071, position: 2 }, done: false, }); assert.deepEqual(iterator.next(), { value: { codePoint: 134071, position: 4 }, done: false, }); assert.deepEqual(iterator.next(), { value: undefined, done: true, }); assert.throws(() => codePoints(Symbol()), 'throws on symbol context'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.string.cooked.js
JavaScript
import Symbol from 'core-js-pure/es/symbol'; import cooked from 'core-js-pure/full/string/cooked'; QUnit.test('String.cooked', assert => { assert.isFunction(cooked); assert.arity(cooked, 1); assert.name(cooked, 'cooked'); assert.same(cooked(['Hi\\n', '!'], 'Bob'), 'Hi\\nBob!', 'template is an array'); assert.same(cooked('test', 0, 1, 2), 't0e1s2t', 'template is a string'); assert.same(cooked('test', 0), 't0est', 'lacks substituting'); assert.same(cooked([]), '', 'empty template'); if (typeof Symbol == 'function' && !Symbol.sham) { const symbol = Symbol('cooked test'); assert.throws(() => cooked([symbol]), TypeError, 'throws on symbol #1'); assert.throws(() => cooked('test', symbol), TypeError, 'throws on symbol #2'); } assert.throws(() => cooked([undefined]), TypeError); assert.throws(() => cooked(null), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.string.dedent.js
JavaScript
import Symbol from 'core-js-pure/es/symbol'; import cooked from 'core-js-pure/full/string/cooked'; import dedent from 'core-js-pure/full/string/dedent'; import freeze from 'core-js-pure/es/object/freeze'; QUnit.test('String.dedent', assert => { assert.isFunction(dedent); assert.arity(dedent, 1); assert.name(dedent, 'dedent'); assert.same(dedent` qwe asd zxc `, 'qwe\nasd\nzxc', '#1'); assert.same(dedent` qwe asd zxc `, ' qwe\nasd\n zxc', '#2'); assert.same(dedent` qwe asd ${ ' zxc' } `, ' qwe\n asd\n zxc', '#3'); assert.same(dedent({ raw: freeze(['\n qwe\n ']) }), 'qwe', '#4'); assert.same(dedent({ raw: freeze(['\n qwe', '\n ']) }, 1), 'qwe1', '#5'); assert.same(dedent(cooked)` qwe asd zxc `, ' qwe\nasd\n zxc', '#6'); const tag = (it => it)` abc `; assert.same(dedent(tag), dedent(tag), '#7'); if (typeof Symbol == 'function' && !Symbol.sham) { assert.throws(() => dedent({ raw: freeze(['\n', Symbol('dedent test'), '\n']) }), TypeError, 'throws on symbol'); } assert.throws(() => dedent([]), TypeError, '[]'); assert.throws(() => dedent(['qwe']), TypeError, '[qwe]'); assert.throws(() => dedent({ raw: freeze([]) }), TypeError, 'empty tpl'); assert.throws(() => dedent({ raw: freeze(['qwe']) }), TypeError, 'wrong start'); assert.throws(() => dedent({ raw: freeze(['\n', 'qwe']) }), TypeError, 'wrong start'); assert.throws(() => dedent({ raw: freeze(['\n qwe', 5, '\n ']) }, 1, 2), TypeError, 'wrong part'); assert.throws(() => dedent([undefined]), TypeError); assert.throws(() => dedent(null), TypeError); // \u{} (empty braces) should be an invalid escape, causing TypeError assert.same(dedent({ raw: freeze(['\n \\u{41}\n ']) }), 'A', 'valid unicode brace escape in raw'); assert.throws(() => dedent({ raw: freeze(['\n \\u{}\n ']) }), TypeError, '\\u{} is an invalid escape'); // hex/unicode escapes at end of string segment assert.same(dedent({ raw: freeze(['\n \\x41\n ']) }), 'A', 'hex escape at end of raw string'); assert.same(dedent({ raw: freeze(['\n \\u0041\n ']) }), 'A', 'unicode escape at end of raw string'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.custom-matcher.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.customMatcher', assert => { assert.true('customMatcher' in Symbol, 'Symbol.customMatcher available'); assert.true(Object(Symbol.customMatcher) instanceof Symbol, 'Symbol.customMatcher is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.is-registered-symbol.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.isRegisteredSymbol', assert => { const { isRegisteredSymbol } = Symbol; assert.isFunction(isRegisteredSymbol, 'Symbol.isRegisteredSymbol is function'); assert.arity(isRegisteredSymbol, 1, 'Symbol.isRegisteredSymbol arity is 1'); assert.name(isRegisteredSymbol, 'isRegisteredSymbol', 'Symbol.isRegisteredSymbol.name is "isRegisteredSymbol"'); assert.true(isRegisteredSymbol(Symbol.for('foo')), 'registered'); assert.true(isRegisteredSymbol(Object(Symbol.for('foo'))), 'registered, boxed'); const symbol = Symbol('Symbol.isRegisteredSymbol test'); assert.false(isRegisteredSymbol(symbol), 'non-registered'); assert.false(isRegisteredSymbol(Object(symbol)), 'non-registered, boxed'); assert.false(isRegisteredSymbol(1), '1'); assert.false(isRegisteredSymbol(true), 'true'); assert.false(isRegisteredSymbol('1'), 'string'); assert.false(isRegisteredSymbol(null), 'null'); assert.false(isRegisteredSymbol(), 'undefined'); assert.false(isRegisteredSymbol({}), 'object'); assert.false(isRegisteredSymbol([]), 'array'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.is-registered.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.isRegistered', assert => { const { isRegistered } = Symbol; assert.isFunction(isRegistered, 'Symbol.isRegistered is function'); assert.arity(isRegistered, 1, 'Symbol.isRegistered arity is 1'); assert.name(isRegistered, 'isRegisteredSymbol', 'Symbol.isRegistered.name is "isRegisteredSymbol"'); assert.true(isRegistered(Symbol.for('foo')), 'registered'); assert.true(isRegistered(Object(Symbol.for('foo'))), 'registered, boxed'); const symbol = Symbol('Symbol.isRegistered test'); assert.false(isRegistered(symbol), 'non-registered'); assert.false(isRegistered(Object(symbol)), 'non-registered, boxed'); assert.false(isRegistered(1), '1'); assert.false(isRegistered(true), 'true'); assert.false(isRegistered('1'), 'string'); assert.false(isRegistered(null), 'null'); assert.false(isRegistered(), 'undefined'); assert.false(isRegistered({}), 'object'); assert.false(isRegistered([]), 'array'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.is-well-known-symbol.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.isWellKnownSymbol', assert => { const { isWellKnownSymbol } = Symbol; assert.isFunction(isWellKnownSymbol, 'Symbol.isWellKnownSymbol is function'); assert.arity(isWellKnownSymbol, 1, 'Symbol.isWellKnownSymbol arity is 1'); assert.name(isWellKnownSymbol, 'isWellKnownSymbol', 'Symbol.isWellKnownSymbol.name is "isWellKnownSymbol"'); assert.true(isWellKnownSymbol(Symbol.iterator), 'registered-1'); assert.true(isWellKnownSymbol(Object(Symbol.iterator)), 'registered-2, boxed'); assert.true(isWellKnownSymbol(Symbol.patternMatch), 'registered-3'); assert.true(isWellKnownSymbol(Object(Symbol.patternMatch)), 'registered-4, boxed'); const symbol = Symbol('Symbol.isWellKnownSymbol test'); assert.false(isWellKnownSymbol(symbol), 'non-registered'); assert.false(isWellKnownSymbol(Object(symbol)), 'non-registered, boxed'); assert.false(isWellKnownSymbol(1), '1'); assert.false(isWellKnownSymbol(true), 'true'); assert.false(isWellKnownSymbol('1'), 'string'); assert.false(isWellKnownSymbol(null), 'null'); assert.false(isWellKnownSymbol(), 'undefined'); assert.false(isWellKnownSymbol({}), 'object'); assert.false(isWellKnownSymbol([]), 'array'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.is-well-known.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.isWellKnown', assert => { const { isWellKnown } = Symbol; assert.isFunction(isWellKnown, 'Symbol.isWellKnown is function'); assert.arity(isWellKnown, 1, 'Symbol.isWellKnown arity is 1'); assert.name(isWellKnown, 'isWellKnownSymbol', 'Symbol.isWellKnown.name is "isWellKnownSymbol"'); assert.true(isWellKnown(Symbol.iterator), 'registered-1'); assert.true(isWellKnown(Object(Symbol.iterator)), 'registered-2, boxed'); assert.true(isWellKnown(Symbol.patternMatch), 'registered-3'); assert.true(isWellKnown(Object(Symbol.patternMatch)), 'registered-4, boxed'); const symbol = Symbol('Symbol.isWellKnown test'); assert.false(isWellKnown(symbol), 'non-registered'); assert.false(isWellKnown(Object(symbol)), 'non-registered, boxed'); assert.false(isWellKnown(1), '1'); assert.false(isWellKnown(true), 'true'); assert.false(isWellKnown('1'), 'string'); assert.false(isWellKnown(null), 'null'); assert.false(isWellKnown(), 'undefined'); assert.false(isWellKnown({}), 'object'); assert.false(isWellKnown([]), 'array'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.matcher.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.matcher', assert => { assert.true('matcher' in Symbol, 'Symbol.matcher available'); assert.true(Object(Symbol.matcher) instanceof Symbol, 'Symbol.matcher is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.metadata-key.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.metadataKey', assert => { assert.true('metadataKey' in Symbol, 'Symbol.metadataKey available'); assert.true(Object(Symbol.metadataKey) instanceof Symbol, 'Symbol.metadataKey is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.metadata.js
JavaScript
import Symbol from 'core-js-pure/actual/symbol'; QUnit.test('Symbol.metadata', assert => { assert.true('metadata' in Symbol, 'Symbol.metadata available'); assert.true(Object(Symbol.metadata) instanceof Symbol, 'Symbol.metadata is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.observable.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.observable', assert => { assert.true('observable' in Symbol, 'Symbol.observable available'); assert.true(Object(Symbol.observable) instanceof Symbol, 'Symbol.observable is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.pattern-match.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.patternMatch', assert => { assert.true('patternMatch' in Symbol, 'Symbol.patternMatch available'); assert.true(Object(Symbol.patternMatch) instanceof Symbol, 'Symbol.patternMatch is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.symbol.replace-all.js
JavaScript
import Symbol from 'core-js-pure/full/symbol'; QUnit.test('Symbol.replaceAll', assert => { assert.true('replaceAll' in Symbol, 'Symbol.replaceAll is available'); assert.true(Object(Symbol.replaceAll) instanceof Symbol, 'Symbol.replaceAll is symbol'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-map.delete-all.js
JavaScript
import WeakMap from 'core-js-pure/full/weak-map'; QUnit.test('WeakMap#deleteAll', assert => { const { deleteAll } = WeakMap.prototype; assert.isFunction(deleteAll); assert.arity(deleteAll, 0); assert.nonEnumerable(WeakMap.prototype, 'deleteAll'); const a = []; const b = []; const c = []; const d = []; const e = []; let set = new WeakMap([[a, 1], [b, 2], [c, 3]]); assert.true(set.deleteAll(a, b)); assert.false(set.has(a)); assert.false(set.has(b)); assert.true(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); set = new WeakMap([[a, 1], [b, 2], [c, 3]]); assert.false(set.deleteAll(c, d)); assert.true(set.has(a)); assert.true(set.has(b)); assert.false(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); set = new WeakMap([[a, 1], [b, 2], [c, 3]]); assert.false(set.deleteAll(d, e)); assert.true(set.has(a)); assert.true(set.has(b)); assert.true(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); set = new WeakMap([[a, 1], [b, 2], [c, 3]]); assert.true(set.deleteAll()); assert.true(set.has(a)); assert.true(set.has(b)); assert.true(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, a, b, c)); assert.throws(() => deleteAll.call({}, a, b, c), TypeError); assert.throws(() => deleteAll.call(undefined, a, b, c), TypeError); assert.throws(() => deleteAll.call(null, a, b, c), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-map.emplace.js
JavaScript
import WeakMap from 'core-js-pure/full/weak-map'; QUnit.test('WeakMap#emplace', assert => { const { emplace } = WeakMap.prototype; assert.isFunction(emplace); assert.arity(emplace, 2); assert.name(emplace, 'emplace'); assert.nonEnumerable(WeakMap.prototype, 'emplace'); const a = {}; const b = {}; const map = new WeakMap([[a, 2]]); let handler = { update(value, key, that) { assert.same(this, handler, 'correct handler in callback'); assert.same(arguments.length, 3, 'correct number of callback arguments'); assert.same(value, 2, 'correct value in callback'); assert.same(key, a, 'correct key in callback'); assert.same(that, map, 'correct map in callback'); return value ** 2; }, insert() { assert.avoid(); }, }; assert.same(map.emplace(a, handler), 4, 'returns a correct value'); handler = { update() { assert.avoid(); }, insert(key, that) { assert.same(this, handler, 'correct handler in callback'); assert.same(arguments.length, 2, 'correct number of callback arguments'); assert.same(key, b, 'correct key in callback'); assert.same(that, map, 'correct map in callback'); return 3; }, }; assert.same(map.emplace(b, handler), 3, 'returns a correct value'); assert.same(map.get(a), 4, 'correct result #1'); assert.same(map.get(b), 3, 'correct result #2'); assert.same(new WeakMap([[a, 2]]).emplace(b, { insert: () => 3 }), 3); assert.same(new WeakMap([[a, 2]]).emplace(a, { update: value => value ** 2 }), 4); handler = { update() { /* empty */ }, insert() { /* empty */ } }; assert.throws(() => new WeakMap().emplace(a), TypeError); assert.throws(() => emplace.call({}, a, handler), TypeError); assert.throws(() => emplace.call([], a, handler), TypeError); assert.throws(() => emplace.call(undefined, a, handler), TypeError); assert.throws(() => emplace.call(null, a, handler), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-map.from.js
JavaScript
import { createIterable } from '../helpers/helpers.js'; import WeakMap from 'core-js-pure/full/weak-map'; QUnit.test('WeakMap.from', assert => { const { from } = WeakMap; assert.isFunction(from); assert.arity(from, 1); assert.true(from([]) instanceof WeakMap); const array = []; assert.same(from([[array, 2]]).get(array), 2); assert.same(from(createIterable([[array, 2]])).get(array), 2); const pair = [{}, 1]; const context = {}; from([pair], function (element, index) { assert.same(element, pair); assert.same(index, 0); assert.same(this, context); return element; }, context); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-map.of.js
JavaScript
import WeakMap from 'core-js-pure/full/weak-map'; QUnit.test('WeakMap.of', assert => { const { of } = WeakMap; assert.isFunction(of); assert.arity(of, 0); const array = []; assert.true(of() instanceof WeakMap); assert.same(of([array, 2]).get(array), 2); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-map.upsert.js
JavaScript
import WeakMap from 'core-js-pure/full/weak-map'; QUnit.test('WeakMap#upsert', assert => { const { upsert } = WeakMap.prototype; assert.isFunction(upsert); assert.arity(upsert, 2); assert.nonEnumerable(WeakMap.prototype, 'upsert'); const a = {}; const b = {}; const map = new WeakMap([[a, 2]]); assert.same(map.upsert(a, function (value) { assert.same(arguments.length, 1, 'correct number of callback arguments'); assert.same(value, 2, 'correct value in callback'); return value ** 2; }, () => { assert.avoid(); return 3; }), 4, 'returns a correct value'); assert.same(map.upsert(b, value => { assert.avoid(); return value ** 2; }, function () { assert.same(arguments.length, 0, 'correct number of callback arguments'); return 3; }), 3, 'returns a correct value'); assert.same(map.get(a), 4, 'correct result #1'); assert.same(map.get(b), 3, 'correct result #2'); assert.same(new WeakMap([[a, 2]]).upsert(b, null, () => 3), 3); assert.same(new WeakMap([[a, 2]]).upsert(a, value => value ** 2), 4); assert.throws(() => new WeakMap().upsert(a), TypeError); assert.throws(() => upsert.call({}, a, () => { /* empty */ }, () => { /* empty */ }), TypeError); assert.throws(() => upsert.call([], a, () => { /* empty */ }, () => { /* empty */ }), TypeError); assert.throws(() => upsert.call(undefined, a, () => { /* empty */ }, () => { /* empty */ }), TypeError); assert.throws(() => upsert.call(null, a, () => { /* empty */ }, () => { /* empty */ }), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-set.add-all.js
JavaScript
import WeakSet from 'core-js-pure/full/weak-set'; QUnit.test('WeakSet#addAll', assert => { const { addAll } = WeakSet.prototype; assert.isFunction(addAll); assert.arity(addAll, 0); assert.name(addAll, 'addAll'); assert.nonEnumerable(WeakSet.prototype, 'addAll'); const a = []; const b = []; const c = []; let set = new WeakSet([a]); assert.same(set.addAll(b), set); set = new WeakSet([a]).addAll(b, c); assert.true(set.has(a)); assert.true(set.has(b)); assert.true(set.has(c)); set = new WeakSet([a]).addAll(a, b); assert.true(set.has(a)); assert.true(set.has(b)); set = new WeakSet([a]).addAll(); assert.true(set.has(a)); assert.throws(() => addAll.call({ add() { /* empty */ } }, a, b, c)); assert.throws(() => addAll.call({}, a, b, c), TypeError); assert.throws(() => addAll.call(undefined, a, b, c), TypeError); assert.throws(() => addAll.call(null, a, b, c), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-set.delete-all.js
JavaScript
import WeakSet from 'core-js-pure/full/weak-set'; QUnit.test('WeakSet#deleteAll', assert => { const { deleteAll } = WeakSet.prototype; assert.isFunction(deleteAll); assert.arity(deleteAll, 0); assert.name(deleteAll, 'deleteAll'); assert.nonEnumerable(WeakSet.prototype, 'deleteAll'); const a = []; const b = []; const c = []; const d = []; const e = []; let set = new WeakSet([a, b, c]); assert.true(set.deleteAll(a, b)); assert.false(set.has(a)); assert.false(set.has(b)); assert.true(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); set = new WeakSet([a, b, c]); assert.false(set.deleteAll(c, d)); assert.true(set.has(a)); assert.true(set.has(b)); assert.false(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); set = new WeakSet([a, b, c]); assert.false(set.deleteAll(d, e)); assert.true(set.has(a)); assert.true(set.has(b)); assert.true(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); set = new WeakSet([a, b, c]); assert.true(set.deleteAll()); assert.true(set.has(a)); assert.true(set.has(b)); assert.true(set.has(c)); assert.false(set.has(d)); assert.false(set.has(e)); assert.throws(() => deleteAll.call({ delete() { /* empty */ } }, a, b, c)); assert.throws(() => deleteAll.call({}, a, b, c), TypeError); assert.throws(() => deleteAll.call(undefined, a, b, c), TypeError); assert.throws(() => deleteAll.call(null, a, b, c), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-set.from.js
JavaScript
import { createIterable } from '../helpers/helpers.js'; import WeakSet from 'core-js-pure/full/weak-set'; QUnit.test('WeakSet.from', assert => { const { from } = WeakSet; assert.isFunction(from); assert.arity(from, 1); assert.true(from([]) instanceof WeakSet); const array = []; assert.true(from([array]).has(array)); assert.true(from(createIterable([array])).has(array)); const object = {}; const context = {}; from([object], function (element, index) { assert.same(element, object); assert.same(index, 0); assert.same(this, context); return element; }, context); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/esnext.weak-set.of.js
JavaScript
import WeakSet from 'core-js-pure/full/weak-set'; QUnit.test('WeakSet.of', assert => { const { of } = WeakSet; assert.isFunction(of); assert.arity(of, 0); const array = []; assert.true(of() instanceof WeakSet); assert.true(of(array).has(array)); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/helpers.get-iterator-method.js
JavaScript
import { createIterable } from '../helpers/helpers.js'; import getIteratorMethod from 'core-js-pure/full/get-iterator-method'; QUnit.test('getIteratorMethod helper', assert => { assert.isFunction(getIteratorMethod); const iterable = createIterable([]); const iterFn = getIteratorMethod(iterable); assert.isFunction(iterFn); assert.isIterator(iterFn.call(iterable)); assert.isFunction(getIteratorMethod([])); assert.isFunction(getIteratorMethod(function () { // eslint-disable-next-line prefer-rest-params -- required for testing return arguments; }())); assert.isFunction(getIteratorMethod(Array.prototype)); assert.same(getIteratorMethod({}), undefined); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/helpers.get-iterator.js
JavaScript
import { createIterable } from '../helpers/helpers.js'; import getIterator from 'core-js-pure/full/get-iterator'; QUnit.test('getIterator helper', assert => { assert.isFunction(getIterator); assert.isIterator(getIterator([])); assert.isIterator(getIterator(function () { // eslint-disable-next-line prefer-rest-params -- required for testing return arguments; }())); assert.isIterator(getIterator(createIterable([]))); assert.throws(() => getIterator({}), TypeError); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/helpers.is-iterable.js
JavaScript
import { createIterable } from '../helpers/helpers.js'; import isIterable from 'core-js-pure/full/is-iterable'; QUnit.test('isIterable helper', assert => { assert.isFunction(isIterable); assert.true(isIterable(createIterable([]))); assert.true(isIterable([])); assert.true(isIterable(function () { // eslint-disable-next-line prefer-rest-params -- required for testing return arguments; }())); assert.true(isIterable(Array.prototype)); assert.true(isIterable({})); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.atob.js
JavaScript
// based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js import atob from 'core-js-pure/stable/atob'; QUnit.test('atob', assert => { assert.isFunction(atob); assert.arity(atob, 1); assert.same(atob(''), ''); assert.same(atob('Zg=='), 'f'); assert.same(atob('Zm8='), 'fo'); assert.same(atob('Zm9v'), 'foo'); assert.same(atob('cXV1eA=='), 'quux'); assert.same(atob('ISIjJCU='), '!"#$%'); assert.same(atob('JicoKSor'), "&'()*+"); assert.same(atob('LC0uLzAxMg=='), ',-./012'); assert.same(atob('MzQ1Njc4OTo='), '3456789:'); assert.same(atob('Ozw9Pj9AQUJD'), ';<=>?@ABC'); assert.same(atob('REVGR0hJSktMTQ=='), 'DEFGHIJKLM'); assert.same(atob('Tk9QUVJTVFVWV1g='), 'NOPQRSTUVWX'); assert.same(atob('WVpbXF1eX2BhYmM='), 'YZ[\\]^_`abc'); assert.same(atob('ZGVmZ2hpamtsbW5vcA=='), 'defghijklmnop'); assert.same(atob('cXJzdHV2d3h5ent8fX4='), 'qrstuvwxyz{|}~'); assert.same(atob(' '), ''); assert.same(atob(42), atob('42')); assert.same(atob(null), atob('null')); assert.throws(() => atob(), TypeError, 'no args'); assert.throws(() => atob('a'), 'invalid #1'); assert.throws(() => atob('a '), 'invalid #2'); assert.throws(() => atob('aaaaa'), 'invalid #3'); assert.throws(() => atob('[object Object]'), 'invalid #4'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.btoa.js
JavaScript
// based on https://github.com/davidchambers/Base64.js/blob/master/test/base64.js import btoa from 'core-js-pure/stable/btoa'; QUnit.test('btoa', assert => { assert.isFunction(btoa); assert.arity(btoa, 1); assert.same(btoa(''), ''); assert.same(btoa('f'), 'Zg=='); assert.same(btoa('fo'), 'Zm8='); assert.same(btoa('foo'), 'Zm9v'); assert.same(btoa('quux'), 'cXV1eA=='); assert.same(btoa('!"#$%'), 'ISIjJCU='); assert.same(btoa("&'()*+"), 'JicoKSor'); assert.same(btoa(',-./012'), 'LC0uLzAxMg=='); assert.same(btoa('3456789:'), 'MzQ1Njc4OTo='); assert.same(btoa(';<=>?@ABC'), 'Ozw9Pj9AQUJD'); assert.same(btoa('DEFGHIJKLM'), 'REVGR0hJSktMTQ=='); assert.same(btoa('NOPQRSTUVWX'), 'Tk9QUVJTVFVWV1g='); assert.same(btoa('YZ[\\]^_`abc'), 'WVpbXF1eX2BhYmM='); assert.same(btoa('defghijklmnop'), 'ZGVmZ2hpamtsbW5vcA=='); assert.same(btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4='); assert.same(btoa('qrstuvwxyz{|}~'), 'cXJzdHV2d3h5ent8fX4='); assert.same(btoa(42), btoa('42')); assert.same(btoa(null), btoa('null')); assert.same(btoa({ x: 1 }), btoa('[object Object]')); assert.throws(() => btoa(), TypeError, 'no args'); assert.throws(() => btoa('✈'), 'non-ASCII'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.dom-collections.iterator.js
JavaScript
import { GLOBAL } from '../helpers/constants.js'; import Symbol from 'core-js-pure/es/symbol'; import getIteratorMethod from 'core-js-pure/stable/get-iterator-method'; QUnit.test('Iterable DOM collections', assert => { let absent = true; const collections = [ 'CSSRuleList', 'CSSStyleDeclaration', 'CSSValueList', 'ClientRectList', 'DOMRectList', 'DOMStringList', 'DOMTokenList', 'DataTransferItemList', 'FileList', 'HTMLAllCollection', 'HTMLCollection', 'HTMLFormElement', 'HTMLSelectElement', 'MediaList', 'MimeTypeArray', 'NamedNodeMap', 'NodeList', 'PaintRequestList', 'Plugin', 'PluginArray', 'SVGLengthList', 'SVGNumberList', 'SVGPathSegList', 'SVGPointList', 'SVGStringList', 'SVGTransformList', 'SourceBufferList', 'StyleSheetList', 'TextTrackCueList', 'TextTrackList', 'TouchList', ]; for (const name of collections) { const Collection = GLOBAL[name]; if (Collection) { absent = false; assert.same(Collection.prototype[Symbol.toStringTag], name, `${ name }::@@toStringTag is '${ name }'`); if (Object.prototype.toString.call(Collection.prototype).slice(8, -1) === name) { assert.isFunction(getIteratorMethod(Collection.prototype), `${ name }::@@iterator is function`); } } } if (GLOBAL.NodeList && GLOBAL.document && document.querySelectorAll && document.querySelectorAll('div') instanceof NodeList) { assert.isFunction(getIteratorMethod(document.querySelectorAll('div')), 'works with document.querySelectorAll'); } if (absent) { assert.required('DOM collections are absent'); } });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.dom-exception.constructor.js
JavaScript
import { DESCRIPTORS, NODE } from '../helpers/constants.js'; import DOMException from 'core-js-pure/stable/dom-exception'; import Symbol from 'core-js-pure/es/symbol'; const errors = { IndexSizeError: { s: 'INDEX_SIZE_ERR', c: 1, m: 1 }, DOMStringSizeError: { s: 'DOMSTRING_SIZE_ERR', c: 2, m: 0 }, HierarchyRequestError: { s: 'HIERARCHY_REQUEST_ERR', c: 3, m: 1 }, WrongDocumentError: { s: 'WRONG_DOCUMENT_ERR', c: 4, m: 1 }, InvalidCharacterError: { s: 'INVALID_CHARACTER_ERR', c: 5, m: 1 }, NoDataAllowedError: { s: 'NO_DATA_ALLOWED_ERR', c: 6, m: 0 }, NoModificationAllowedError: { s: 'NO_MODIFICATION_ALLOWED_ERR', c: 7, m: 1 }, NotFoundError: { s: 'NOT_FOUND_ERR', c: 8, m: 1 }, NotSupportedError: { s: 'NOT_SUPPORTED_ERR', c: 9, m: 1 }, InUseAttributeError: { s: 'INUSE_ATTRIBUTE_ERR', c: 10, m: 1 }, InvalidStateError: { s: 'INVALID_STATE_ERR', c: 11, m: 1 }, SyntaxError: { s: 'SYNTAX_ERR', c: 12, m: 1 }, InvalidModificationError: { s: 'INVALID_MODIFICATION_ERR', c: 13, m: 1 }, NamespaceError: { s: 'NAMESPACE_ERR', c: 14, m: 1 }, InvalidAccessError: { s: 'INVALID_ACCESS_ERR', c: 15, m: 1 }, ValidationError: { s: 'VALIDATION_ERR', c: 16, m: 0 }, TypeMismatchError: { s: 'TYPE_MISMATCH_ERR', c: 17, m: 1 }, SecurityError: { s: 'SECURITY_ERR', c: 18, m: 1 }, NetworkError: { s: 'NETWORK_ERR', c: 19, m: 1 }, AbortError: { s: 'ABORT_ERR', c: 20, m: 1 }, URLMismatchError: { s: 'URL_MISMATCH_ERR', c: 21, m: 1 }, // https://github.com/whatwg/webidl/pull/1465 // QuotaExceededError: { s: 'QUOTA_EXCEEDED_ERR', c: 22, m: 1 }, TimeoutError: { s: 'TIMEOUT_ERR', c: 23, m: 1 }, InvalidNodeTypeError: { s: 'INVALID_NODE_TYPE_ERR', c: 24, m: 1 }, DataCloneError: { s: 'DATA_CLONE_ERR', c: 25, m: 1 }, }; const HAS_STACK = 'stack' in new Error('1'); QUnit.test('DOMException', assert => { assert.isFunction(DOMException); assert.arity(DOMException, 0); assert.name(DOMException, 'DOMException'); let error = new DOMException({}, 'Foo'); assert.true(error instanceof DOMException, 'new DOMException({}, "Foo") instanceof DOMException'); assert.same(error.message, '[object Object]', 'new DOMException({}, "Foo").message'); assert.same(error.name, 'Foo', 'new DOMException({}, "Foo").name'); assert.same(error.code, 0, 'new DOMException({}, "Foo").code'); assert.same(String(error), 'Foo: [object Object]', 'String(new DOMException({}, "Foo"))'); // Safari 10.1 bug // assert.same(error.constructor, DOMException, 'new DOMException({}, "Foo").constructor'); assert.same(error[Symbol.toStringTag], 'DOMException', 'DOMException.prototype[Symbol.toStringTag]'); if (HAS_STACK) assert.true('stack' in error, "'stack' in new DOMException()"); assert.same(new DOMException().message, '', 'new DOMException().message'); assert.same(new DOMException(undefined).message, '', 'new DOMException(undefined).message'); assert.same(new DOMException(42).name, 'Error', 'new DOMException(42).name'); assert.same(new DOMException(42, undefined).name, 'Error', 'new DOMException(42, undefined).name'); for (const name in errors) { error = new DOMException(42, name); assert.true(error instanceof DOMException, `new DOMException({}, "${ name }") instanceof DOMException`); assert.same(error.message, '42', `new DOMException({}, "${ name }").message`); assert.same(error.name, name, `new DOMException({}, "${ name }").name`); if (errors[name].m) assert.same(error.code, errors[name].c, `new DOMException({}, "${ name }").code`); // NodeJS and Deno set codes to deprecated errors else if (!NODE) assert.same(error.code, 0, `new DOMException({}, "${ name }").code`); assert.same(String(error), `${ name }: 42`, `String(new DOMException({}, "${ name }"))`); // Safari 10.1 bug if (HAS_STACK) assert.true('stack' in error, `'stack' in new DOMException({}, "${ name }")`); assert.same(DOMException[errors[name].s], errors[name].c, `DOMException.${ errors[name].s }`); assert.same(DOMException.prototype[errors[name].s], errors[name].c, `DOMException.prototype.${ errors[name].s }`); } // eslint-disable-next-line sonarjs/inconsistent-function-call -- required for testing assert.throws(() => DOMException(42, 'DataCloneError'), "DOMException(42, 'DataCloneError')"); const symbol = Symbol('DOMException constructor test'); assert.throws(() => new DOMException(symbol, 'DataCloneError'), "new DOMException(Symbol(), 'DataCloneError')"); assert.throws(() => new DOMException(42, symbol), 'new DOMException(42, Symbol())'); if (DESCRIPTORS) { // assert.throws(() => DOMException.prototype.message, 'DOMException.prototype.message'); // FF55- , Safari 10.1 bug // assert.throws(() => DOMException.prototype.name, 'DOMException.prototype.name'); // FF55-, Safari 10.1 bug bug // assert.throws(() => DOMException.prototype.code, 'DOMException.prototype.code'); // Safari 10.1 bug // assert.throws(() => DOMException.prototype.toString(), 'DOMException.prototype.toString()'); // FF55- bug } });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.queue-microtask.js
JavaScript
import { timeLimitedPromise } from '../helpers/helpers.js'; import queueMicrotask from 'core-js-pure/full/queue-microtask'; QUnit.test('queueMicrotask', assert => { assert.isFunction(queueMicrotask); assert.arity(queueMicrotask, 1); return timeLimitedPromise(3e3, resolve => { let called = false; queueMicrotask(() => { called = true; resolve(); }); assert.false(called, 'async'); }).then(() => { assert.required('works'); }); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.self.js
JavaScript
import self from 'core-js-pure/stable/self'; QUnit.test('self', assert => { assert.same(self, Object(self), 'is object'); assert.same(self.Math, Math, 'contains globals'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.set-immediate.js
JavaScript
import { timeLimitedPromise } from '../helpers/helpers.js'; import setImmediate from 'core-js-pure/stable/set-immediate'; import clearImmediate from 'core-js-pure/stable/clear-immediate'; QUnit.test('setImmediate / clearImmediate', assert => { assert.isFunction(setImmediate, 'setImmediate is function'); assert.isFunction(clearImmediate, 'clearImmediate is function'); let called = false; const promise = timeLimitedPromise(1e3, resolve => { setImmediate(() => { called = true; resolve(); }); }).then(() => { assert.required('setImmediate works'); }, () => { assert.avoid('setImmediate works'); }).then(() => { return timeLimitedPromise(1e3, resolve => { setImmediate((a, b) => { resolve(a + b); }, 'a', 'b'); }); }).then(it => { assert.same(it, 'ab', 'setImmediate works with additional args'); }, () => { assert.avoid('setImmediate works with additional args'); }).then(() => { return timeLimitedPromise(50, resolve => { clearImmediate(setImmediate(resolve)); }); }).then(() => { assert.avoid('clearImmediate works'); }, () => { assert.required('clearImmediate works'); }); assert.false(called, 'setImmediate is async'); return promise; });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.set-interval.js
JavaScript
import { timeLimitedPromise } from '../helpers/helpers.js'; import setTimeout from 'core-js-pure/stable/set-timeout'; import setInterval from 'core-js-pure/stable/set-interval'; QUnit.test('setInterval / clearInterval', assert => { assert.isFunction(setInterval, 'setInterval is function'); assert.isFunction(clearInterval, 'clearInterval is function'); return timeLimitedPromise(1e4, (resolve, reject) => { let i = 0; const interval = setInterval((a, b) => { if (a + b !== 'ab' || i > 2) reject({ a, b, i }); if (i++ === 2) { clearInterval(interval); setTimeout(resolve, 30); } }, 5, 'a', 'b'); }).then(() => { assert.required('setInterval & clearInterval works with additional args'); }, (error = {}) => { assert.avoid(`setInterval & clearInterval works with additional args: ${ error.a }, ${ error.b }, times: ${ error.i }`); }); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.set-timeout.js
JavaScript
import { timeLimitedPromise } from '../helpers/helpers.js'; import setTimeout from 'core-js-pure/stable/set-timeout'; QUnit.test('setTimeout / clearTimeout', assert => { assert.isFunction(setTimeout, 'setTimeout is function'); assert.isFunction(clearTimeout, 'clearTimeout is function'); return timeLimitedPromise(1e3, resolve => { setTimeout((a, b) => { resolve(a + b); }, 10, 'a', 'b'); }).then(it => { assert.same(it, 'ab', 'setTimeout works with additional args'); }, () => { assert.avoid('setTimeout works with additional args'); }).then(() => { return timeLimitedPromise(50, resolve => { clearTimeout(setTimeout(resolve, 10)); }); }).then(() => { assert.avoid('clearImmediate works with wrapped setTimeout'); }, () => { assert.required('clearImmediate works with wrapped setTimeout'); }); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.structured-clone.js
JavaScript
// Originally from: https://github.com/web-platform-tests/wpt/blob/4b35e758e2fc4225368304b02bcec9133965fd1a/IndexedDB/structured-clone.any.js // Copyright © web-platform-tests contributors. Available under the 3-Clause BSD License. /* eslint-disable es/no-error-cause, es/no-typed-arrays -- safe */ import { GLOBAL, NODE, BUN } from '../helpers/constants.js'; import { bufferToArray, fromSource } from '../helpers/helpers.js'; import structuredClone from 'core-js-pure/stable/structured-clone'; import from from 'core-js-pure/es/array/from'; import assign from 'core-js-pure/es/object/assign'; import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of'; import keys from 'core-js-pure/es/object/keys'; import Symbol from 'core-js-pure/es/symbol'; import Map from 'core-js-pure/es/map'; import Set from 'core-js-pure/es/set'; import AggregateError from 'core-js-pure/es/aggregate-error'; import DOMException from 'core-js-pure/stable/dom-exception'; QUnit.module('structuredClone', () => { QUnit.test('identity', assert => { assert.isFunction(structuredClone, 'structuredClone is a function'); assert.name(structuredClone, 'structuredClone'); assert.arity(structuredClone, 1); assert.throws(() => structuredClone(), 'throws without arguments'); assert.same(structuredClone(1, null), 1, 'null as options'); assert.same(structuredClone(1, undefined), 1, 'undefined as options'); }); function cloneTest(value, verifyFunc) { verifyFunc(value, structuredClone(value)); } // Specialization of cloneTest() for objects, with common asserts. function cloneObjectTest(assert, value, verifyFunc) { cloneTest(value, (orig, clone) => { assert.notSame(orig, clone, 'clone should have different reference'); assert.same(typeof clone, 'object', 'clone should be an object'); // https://github.com/qunitjs/node-qunit/issues/146 assert.true(getPrototypeOf(orig) === getPrototypeOf(clone), 'clone should have same prototype'); verifyFunc(orig, clone); }); } // ECMAScript types // Primitive values: Undefined, Null, Boolean, Number, BigInt, String const booleans = [false, true]; const numbers = [ NaN, -Infinity, -Number.MAX_VALUE, -0xFFFFFFFF, -0x80000000, -0x7FFFFFFF, -1, -Number.MIN_VALUE, -0, 0, 1, Number.MIN_VALUE, 0x7FFFFFFF, 0x80000000, 0xFFFFFFFF, Number.MAX_VALUE, Infinity, ]; const bigints = fromSource(`[ -12345678901234567890n, -1n, 0n, 1n, 12345678901234567890n, ]`) || []; const strings = [ '', 'this is a sample string', 'null(\0)', ]; QUnit.test('primitives', assert => { const primitives = [undefined, null, ...booleans, ...numbers, ...bigints, ...strings]; for (const value of primitives) cloneTest(value, (orig, clone) => { assert.same(orig, clone, 'primitives should be same after cloned'); }); }); // "Primitive" Objects (Boolean, Number, BigInt, String) QUnit.test('primitive objects', assert => { const primitives = [...booleans, ...numbers, ...bigints, ...strings]; for (const value of primitives) cloneObjectTest(assert, Object(value), (orig, clone) => { assert.same(orig.valueOf(), clone.valueOf(), 'primitive wrappers should have same value'); }); }); // Dates QUnit.test('Date', assert => { const dates = [ new Date(-1e13), new Date(-1e12), new Date(-1e9), new Date(-1e6), new Date(-1e3), new Date(0), new Date(1e3), new Date(1e6), new Date(1e9), new Date(1e12), new Date(1e13), ]; for (const date of dates) cloneTest(date, (orig, clone) => { assert.notSame(orig, clone); assert.same(typeof clone, 'object'); assert.same(getPrototypeOf(orig), getPrototypeOf(clone)); assert.same(orig.valueOf(), clone.valueOf()); }); }); // Regular Expressions QUnit.test('RegExp', assert => { const regexes = [ new RegExp(), /abc/, /abc/g, /abc/i, /abc/gi, /abc/, /abc/g, /abc/i, /abc/gi, ]; const giuy = fromSource('/abc/giuy'); if (giuy) regexes.push(giuy); for (const regex of regexes) cloneObjectTest(assert, regex, (orig, clone) => { assert.same(orig.toString(), clone.toString(), `regex ${ regex }`); }); }); if (fromSource('ArrayBuffer.prototype.slice || DataView')) { // ArrayBuffer if (typeof Uint8Array == 'function') QUnit.test('ArrayBuffer', assert => { // Crashes cloneObjectTest(assert, new Uint8Array([0, 1, 254, 255]).buffer, (orig, clone) => { assert.arrayEqual(new Uint8Array(orig), new Uint8Array(clone)); }); }); // TODO SharedArrayBuffer // Array Buffer Views if (typeof Int8Array != 'undefined') { QUnit.test('%TypedArray%', assert => { const arrays = [ new Uint8Array([]), new Uint8Array([0, 1, 254, 255]), new Uint16Array([0x0000, 0x0001, 0xFFFE, 0xFFFF]), new Uint32Array([0x00000000, 0x00000001, 0xFFFFFFFE, 0xFFFFFFFF]), new Int8Array([0, 1, 254, 255]), new Int16Array([0x0000, 0x0001, 0xFFFE, 0xFFFF]), new Int32Array([0x00000000, 0x00000001, 0xFFFFFFFE, 0xFFFFFFFF]), new Float32Array([-Infinity, -1.5, -1, -0.5, 0, 0.5, 1, 1.5, Infinity, NaN]), new Float64Array([-Infinity, -Number.MAX_VALUE, -Number.MIN_VALUE, 0, Number.MIN_VALUE, Number.MAX_VALUE, Infinity, NaN]), ]; if (typeof Uint8ClampedArray != 'undefined') { arrays.push(new Uint8ClampedArray([0, 1, 254, 255])); } for (const array of arrays) cloneObjectTest(assert, array, (orig, clone) => { assert.arrayEqual(orig, clone); }); }); if (typeof DataView != 'undefined') QUnit.test('DataView', assert => { const array = new Int8Array([1, 2, 3, 4]); const view = new DataView(array.buffer); cloneObjectTest(assert, array, (orig, clone) => { assert.same(orig.byteLength, clone.byteLength); assert.same(orig.byteOffset, clone.byteOffset); assert.arrayEqual(new Int8Array(view.buffer), array); }); }); } if ('resizable' in ArrayBuffer.prototype) { QUnit.test('Resizable ArrayBuffer', assert => { const array = [1, 2, 3, 4, 5, 6, 7, 8]; // eslint-disable-next-line es/no-resizable-and-growable-arraybuffers -- safe let buffer = new ArrayBuffer(8, { maxByteLength: 16 }); new Int8Array(buffer).set(array); let copy = structuredClone(buffer); assert.arrayEqual(bufferToArray(copy), array, 'resizable-ab-1'); assert.true(copy.resizable, 'resizable-ab-1'); buffer = new ArrayBuffer(8); new Int8Array(buffer).set(array); copy = structuredClone(buffer); assert.arrayEqual(bufferToArray(copy), array, 'non-resizable-ab-1'); assert.false(copy.resizable, 'non-resizable-ab-1'); // eslint-disable-next-line es/no-resizable-and-growable-arraybuffers -- safe buffer = new ArrayBuffer(8, { maxByteLength: 16 }); let tarray = new Int8Array(buffer); tarray.set(array); copy = structuredClone(tarray).buffer; assert.arrayEqual(bufferToArray(copy), array, 'resizable-ab-2'); assert.true(copy.resizable, 'resizable-ab-2'); buffer = new ArrayBuffer(8); tarray = new Int8Array(buffer); tarray.set(array); copy = structuredClone(tarray).buffer; assert.arrayEqual(bufferToArray(copy), array, 'non-resizable-ab-2'); assert.false(copy.resizable, 'non-resizable-ab-2'); }); } } // Map QUnit.test('Map', assert => { cloneObjectTest(assert, new Map([[1, 2], [3, 4]]), (orig, clone) => { assert.deepEqual(from(orig.keys()), from(clone.keys())); assert.deepEqual(from(orig.values()), from(clone.values())); }); }); // Set QUnit.test('Set', assert => { cloneObjectTest(assert, new Set([1, 2, 3, 4]), (orig, clone) => { assert.deepEqual(from(orig.values()), from(clone.values())); }); }); // Error QUnit.test('Error', assert => { const errors = [ ['Error', new Error()], ['Error', new Error('msg', { cause: 42 })], ['EvalError', new EvalError()], ['EvalError', new EvalError('msg', { cause: 42 })], ['RangeError', new RangeError()], ['RangeError', new RangeError('msg', { cause: 42 })], ['ReferenceError', new ReferenceError()], ['ReferenceError', new ReferenceError('msg', { cause: 42 })], ['SyntaxError', new SyntaxError()], ['SyntaxError', new SyntaxError('msg', { cause: 42 })], ['TypeError', new TypeError()], ['TypeError', new TypeError('msg', { cause: 42 })], ['URIError', new URIError()], ['URIError', new URIError('msg', { cause: 42 })], ['AggregateError', new AggregateError([1, 2])], ['AggregateError', new AggregateError([1, 2], 'msg', { cause: 42 })], ]; const compile = fromSource('WebAssembly.CompileError()'); const link = fromSource('WebAssembly.LinkError()'); const runtime = fromSource('WebAssembly.RuntimeError()'); if (compile && compile.name === 'CompileError') errors.push(['CompileError', compile]); if (link && link.name === 'LinkError') errors.push(['LinkError', link]); if (runtime && runtime.name === 'RuntimeError') errors.push(['RuntimeError', runtime]); for (const [name, error] of errors) cloneObjectTest(assert, error, (orig, clone) => { assert.same(orig.constructor, clone.constructor, `${ name }#constructor`); assert.same(orig.name, clone.name, `${ name }#name`); assert.same(orig.message, clone.message, `${ name }#message`); assert.same(orig.stack, clone.stack, `${ name }#stack`); assert.same(orig.cause, clone.cause, `${ name }#cause`); assert.deepEqual(orig.errors, clone.errors, `${ name }#errors`); }); }); // Arrays QUnit.test('Array', assert => { const arrays = [ [], [1, 2, 3], Array(1), assign( ['foo', 'bar'], { 10: true, 11: false, 20: 123, 21: 456, 30: null }), assign( ['foo', 'bar'], { a: true, b: false, foo: 123, bar: 456, '': null }), ]; for (const array of arrays) cloneObjectTest(assert, array, (orig, clone) => { assert.deepEqual(orig, clone, `array content should be same: ${ array }`); assert.deepEqual(orig.length, clone.length, `array length should be same: ${ array }`); assert.deepEqual(keys(orig), keys(clone), `array key should be same: ${ array }`); for (const key of keys(orig)) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); // Objects QUnit.test('Object', assert => { cloneObjectTest(assert, { foo: true, bar: false }, (orig, clone) => { assert.deepEqual(keys(orig), keys(clone)); for (const key of keys(orig)) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); // [Serializable] Platform objects // Geometry types if (typeof DOMMatrix == 'function') { QUnit.test('Geometry types, DOMMatrix', assert => { cloneObjectTest(assert, new DOMMatrix(), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); } if (typeof DOMMatrixReadOnly == 'function' && typeof DOMMatrixReadOnly.fromMatrix == 'function') { QUnit.test('Geometry types, DOMMatrixReadOnly', assert => { cloneObjectTest(assert, new DOMMatrixReadOnly(), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); } if (typeof DOMPoint == 'function') { QUnit.test('Geometry types, DOMPoint', assert => { cloneObjectTest(assert, new DOMPoint(1, 2, 3, 4), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); } if (typeof DOMPointReadOnly == 'function' && typeof DOMPointReadOnly.fromPoint == 'function') { QUnit.test('Geometry types, DOMPointReadOnly', assert => { cloneObjectTest(assert, new DOMPointReadOnly(1, 2, 3, 4), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); } if (typeof DOMQuad == 'function' && typeof DOMPoint == 'function') { QUnit.test('Geometry types, DOMQuad', assert => { cloneObjectTest(assert, new DOMQuad( new DOMPoint(1, 2, 3, 4), new DOMPoint(2, 2, 3, 4), new DOMPoint(1, 3, 3, 4), new DOMPoint(1, 2, 4, 4), ), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.deepEqual(orig[key], clone[key], `Property ${ key }`); } }); }); } if (fromSource('new DOMRect(1, 2, 3, 4)')) { QUnit.test('Geometry types, DOMRect', assert => { cloneObjectTest(assert, new DOMRect(1, 2, 3, 4), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); } if (typeof DOMRectReadOnly == 'function' && typeof DOMRectReadOnly.fromRect == 'function') { QUnit.test('Geometry types, DOMRectReadOnly', assert => { cloneObjectTest(assert, new DOMRectReadOnly(1, 2, 3, 4), (orig, clone) => { for (const key of keys(getPrototypeOf(orig))) { assert.same(orig[key], clone[key], `Property ${ key }`); } }); }); } // Safari 8- does not support `{ colorSpace }` option if (fromSource('new ImageData(new ImageData(8, 8).data, 8, 8, { colorSpace: new ImageData(8, 8).colorSpace })')) { QUnit.test('ImageData', assert => { const imageData = new ImageData(8, 8); for (let i = 0; i < 256; ++i) { imageData.data[i] = i; } cloneObjectTest(assert, imageData, (orig, clone) => { assert.same(orig.width, clone.width); assert.same(orig.height, clone.height); assert.same(orig.colorSpace, clone.colorSpace); assert.arrayEqual(orig.data, clone.data); }); }); } if (fromSource('new Blob(["test"])')) QUnit.test('Blob', assert => { cloneObjectTest( assert, new Blob(['This is a test.'], { type: 'a/b' }), (orig, clone) => { assert.same(orig.size, clone.size); assert.same(orig.type, clone.type); // TODO: async // assert.same(await orig.text(), await clone.text()); }); }); QUnit.test('DOMException', assert => { const errors = [ new DOMException(), new DOMException('foo', 'DataCloneError'), ]; for (const error of errors) cloneObjectTest(assert, error, (orig, clone) => { assert.same(orig.name, clone.name); assert.same(orig.message, clone.message); assert.same(orig.code, clone.code); assert.same(orig.stack, clone.stack); }); }); // https://github.com/oven-sh/bun/issues/11696 if (!BUN && fromSource('new File(["test"], "foo.txt")')) QUnit.test('File', assert => { cloneObjectTest( assert, new File(['This is a test.'], 'foo.txt', { type: 'c/d' }), (orig, clone) => { assert.same(orig.size, clone.size); assert.same(orig.type, clone.type); assert.same(orig.name, clone.name); assert.same(orig.lastModified, clone.lastModified); // TODO: async // assert.same(await orig.text(), await clone.text()); }); }); // FileList if (fromSource('new File(["test"], "foo.txt")') && fromSource('new DataTransfer() && "items" in DataTransfer.prototype')) QUnit.test('FileList', assert => { const transfer = new DataTransfer(); transfer.items.add(new File(['test'], 'foo.txt')); cloneObjectTest( assert, transfer.files, (orig, clone) => { assert.same(1, clone.length); assert.same(orig[0].size, clone[0].size); assert.same(orig[0].type, clone[0].type); assert.same(orig[0].name, clone[0].name); assert.same(orig[0].lastModified, clone[0].lastModified); }, ); }); // Non-serializable types QUnit.test('Non-serializable types', assert => { const nons = [ function () { return 1; }, Symbol('desc'), GLOBAL, ]; const event = fromSource('new Event("")'); const port = fromSource('new MessageChannel().port1'); // NodeJS events are simple objects if (event && !NODE) nons.push(event); if (port) nons.push(port); for (const it of nons) { // native NodeJS `structuredClone` throws a `TypeError` on transferable non-serializable instead of `DOMException` // https://github.com/nodejs/node/issues/40841 assert.throws(() => structuredClone(it)); } }); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.url-search-params.js
JavaScript
import { DESCRIPTORS, BUN } from '../helpers/constants.js'; import { createIterable } from '../helpers/helpers.js'; import getPrototypeOf from 'core-js-pure/es/object/get-prototype-of'; import getOwnPropertyDescriptor from 'core-js-pure/es/object/get-own-property-descriptor'; import Symbol from 'core-js-pure/es/symbol'; import URL from 'core-js-pure/stable/url'; import URLSearchParams from 'core-js-pure/stable/url-search-params'; QUnit.test('URLSearchParams', assert => { assert.isFunction(URLSearchParams); assert.arity(URLSearchParams, 0); assert.same(String(new URLSearchParams()), ''); assert.same(String(new URLSearchParams('')), ''); assert.same(String(new URLSearchParams('a=b')), 'a=b'); assert.same(String(new URLSearchParams(new URLSearchParams('a=b'))), 'a=b'); assert.same(String(new URLSearchParams([])), ''); assert.same(String(new URLSearchParams([[1, 2], ['a', 'b']])), '1=2&a=b'); assert.same(String(new URLSearchParams(createIterable([createIterable(['a', 'b']), createIterable(['c', 'd'])]))), 'a=b&c=d'); assert.same(String(new URLSearchParams({})), ''); assert.same(String(new URLSearchParams({ 1: 2, a: 'b' })), '1=2&a=b'); assert.same(String(new URLSearchParams('?a=b')), 'a=b', 'leading ? should be ignored'); assert.same(String(new URLSearchParams('??a=b')), '%3Fa=b'); assert.same(String(new URLSearchParams('?')), ''); assert.same(String(new URLSearchParams('??')), '%3F='); assert.same(String(new URLSearchParams('a=b c')), 'a=b+c'); assert.same(String(new URLSearchParams('a=b&b=c&a=d')), 'a=b&b=c&a=d'); assert.same(String(new URLSearchParams('a==')), 'a=%3D'); assert.same(String(new URLSearchParams('a=b=')), 'a=b%3D'); assert.same(String(new URLSearchParams('a=b=c')), 'a=b%3Dc'); assert.same(String(new URLSearchParams('a==b')), 'a=%3Db'); let params = new URLSearchParams('a=b'); assert.true(params.has('a'), 'search params object has name "a"'); assert.false(params.has('b'), 'search params object has not got name "b"'); params = new URLSearchParams('a=b&c'); assert.true(params.has('a'), 'search params object has name "a"'); assert.true(params.has('c'), 'search params object has name "c"'); params = new URLSearchParams('&a&&& &&&&&a+b=& c&m%c3%b8%c3%b8'); assert.true(params.has('a'), 'search params object has name "a"'); assert.true(params.has('a b'), 'search params object has name "a b"'); assert.true(params.has(' '), 'search params object has name " "'); assert.false(params.has('c'), 'search params object did not have the name "c"'); assert.true(params.has(' c'), 'search params object has name " c"'); assert.true(params.has('møø'), 'search params object has name "møø"'); params = new URLSearchParams('a=b+c'); assert.same(params.get('a'), 'b c', 'parse +'); params = new URLSearchParams('a+b=c'); assert.same(params.get('a b'), 'c', 'parse +'); params = new URLSearchParams('a=b c'); assert.same(params.get('a'), 'b c', 'parse " "'); params = new URLSearchParams('a b=c'); assert.same(params.get('a b'), 'c', 'parse " "'); params = new URLSearchParams('a=b%20c'); assert.same(params.get('a'), 'b c', 'parse %20'); params = new URLSearchParams('a%20b=c'); assert.same(params.get('a b'), 'c', 'parse %20'); params = new URLSearchParams('a=b\0c'); assert.same(params.get('a'), 'b\0c', 'parse \\0'); params = new URLSearchParams('a\0b=c'); assert.same(params.get('a\0b'), 'c', 'parse \\0'); params = new URLSearchParams('a=b%00c'); assert.same(params.get('a'), 'b\0c', 'parse %00'); params = new URLSearchParams('a%00b=c'); assert.same(params.get('a\0b'), 'c', 'parse %00'); params = new URLSearchParams('a=b\u2384'); assert.same(params.get('a'), 'b\u2384', 'parse \u2384'); params = new URLSearchParams('a\u2384b=c'); assert.same(params.get('a\u2384b'), 'c', 'parse \u2384'); params = new URLSearchParams('a=b%e2%8e%84'); assert.same(params.get('a'), 'b\u2384', 'parse %e2%8e%84'); params = new URLSearchParams('a%e2%8e%84b=c'); assert.same(params.get('a\u2384b'), 'c', 'parse %e2%8e%84'); params = new URLSearchParams('a=b\uD83D\uDCA9c'); assert.same(params.get('a'), 'b\uD83D\uDCA9c', 'parse \uD83D\uDCA9'); params = new URLSearchParams('a\uD83D\uDCA9b=c'); assert.same(params.get('a\uD83D\uDCA9b'), 'c', 'parse \uD83D\uDCA9'); params = new URLSearchParams('a=b%f0%9f%92%a9c'); assert.same(params.get('a'), 'b\uD83D\uDCA9c', 'parse %f0%9f%92%a9'); params = new URLSearchParams('a%f0%9f%92%a9b=c'); assert.same(params.get('a\uD83D\uDCA9b'), 'c', 'parse %f0%9f%92%a9'); params = new URLSearchParams(); params.set('query', '+15555555555'); assert.same(params.toString(), 'query=%2B15555555555'); assert.same(params.get('query'), '+15555555555', 'parse encoded +'); params = new URLSearchParams(params.toString()); assert.same(params.get('query'), '+15555555555', 'parse encoded +'); params = new URLSearchParams('b=%2sf%2a'); assert.same(params.get('b'), '%2sf*', 'parse encoded %2sf%2a'); params = new URLSearchParams('b=%%2a'); assert.same(params.get('b'), '%*', 'parse encoded b=%%2a'); params = new URLSearchParams('a=b\u2384'); assert.same(params.get('a'), 'b\u2384', 'parse \u2384'); params = new URLSearchParams('a\u2384b=c'); assert.same(params.get('a\u2384b'), 'c', 'parse \u2384'); params = new URLSearchParams('a=b%e2%8e%84'); assert.same(params.get('a'), 'b\u2384', 'parse b%e2%8e%84'); params = new URLSearchParams('a%e2%8e%84b=c'); assert.same(params.get('a\u2384b'), 'c', 'parse b%e2%8e%84'); params = new URLSearchParams('a=b\uD83D\uDCA9c'); assert.same(params.get('a'), 'b\uD83D\uDCA9c', 'parse \uD83D\uDCA9'); params = new URLSearchParams('a\uD83D\uDCA9b=c'); assert.same(params.get('a\uD83D\uDCA9b'), 'c', 'parse \uD83D\uDCA9'); params = new URLSearchParams('a=b%f0%9f%92%a9c'); assert.same(params.get('a'), 'b\uD83D\uDCA9c', 'parse %f0%9f%92%a9'); params = new URLSearchParams('a%f0%9f%92%a9b=c'); assert.same(params.get('a\uD83D\uDCA9b'), 'c', 'parse %f0%9f%92%a9'); assert.same(String(new URLSearchParams('%C2')), '%EF%BF%BD='); assert.same(String(new URLSearchParams('%F0%9F%D0%90')), '%EF%BF%BD%D0%90='); assert.same(String(new URLSearchParams('%25')), '%25='); assert.same(String(new URLSearchParams('%4')), '%254='); assert.same(String(new URLSearchParams('%C3%ZZ')), '%EF%BF%BD%25ZZ=', 'invalid hex in continuation byte preserved'); // overlong UTF-8 encodings assert.same(String(new URLSearchParams('%C0%AF')), '%EF%BF%BD%EF%BF%BD=', 'overlong 2-byte slash'); assert.same(String(new URLSearchParams('%C0%80')), '%EF%BF%BD%EF%BF%BD=', 'overlong 2-byte NUL'); assert.same(String(new URLSearchParams('%E0%80%AF')), '%EF%BF%BD%EF%BF%BD%EF%BF%BD=', 'overlong 3-byte slash'); assert.same(String(new URLSearchParams('%F0%80%80%AF')), '%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD=', 'overlong 4-byte slash'); // surrogate codepoints encoded in UTF-8 assert.same(String(new URLSearchParams('%ED%A0%80')), '%EF%BF%BD%EF%BF%BD%EF%BF%BD=', 'UTF-8 encoded U+D800'); assert.same(String(new URLSearchParams('%ED%BF%BF')), '%EF%BF%BD%EF%BF%BD%EF%BF%BD=', 'UTF-8 encoded U+DFFF'); const testData = [ { input: '?a=%', output: [['a', '%']], name: 'handling %' }, { input: { '+': '%C2' }, output: [['+', '%C2']], name: 'object with +' }, { input: { c: 'x', a: '?' }, output: [['c', 'x'], ['a', '?']], name: 'object with two keys' }, { input: [['c', 'x'], ['a', '?']], output: [['c', 'x'], ['a', '?']], name: 'array with two keys' }, // eslint-disable-next-line @stylistic/max-len -- ignore // !!! { input: { 'a\0b': '42', 'c\uD83D': '23', dሴ: 'foo' }, output: [['a\0b', '42'], ['c\uFFFD', '23'], ['d\u1234', 'foo']], name: 'object with NULL, non-ASCII, and surrogate keys' }, ]; for (const { input, output, name } of testData) { params = new URLSearchParams(input); let i = 0; params.forEach((value, key) => { const [reqKey, reqValue] = output[i++]; assert.same(key, reqKey, `construct with ${ name }`); assert.same(value, reqValue, `construct with ${ name }`); }); } // https://github.com/oven-sh/bun/issues/9253 if (!BUN) assert.throws(() => { // eslint-disable-next-line sonarjs/inconsistent-function-call -- required for testing URLSearchParams(''); }, 'throws w/o `new`'); assert.throws(() => { new URLSearchParams([[1, 2, 3]]); }, 'sequence elements must be pairs #1'); assert.throws(() => { new URLSearchParams([createIterable([createIterable([1, 2, 3])])]); }, 'sequence elements must be pairs #2'); assert.throws(() => { new URLSearchParams([[1]]); }, 'sequence elements must be pairs #3'); assert.throws(() => { new URLSearchParams([createIterable([createIterable([1])])]); }, 'sequence elements must be pairs #4'); }); QUnit.test('URLSearchParams#append', assert => { const { append } = URLSearchParams.prototype; assert.isFunction(append); assert.arity(append, 2); assert.enumerable(URLSearchParams.prototype, 'append'); assert.same(new URLSearchParams().append('a', 'b'), undefined, 'void'); let params = new URLSearchParams(); params.append('a', 'b'); assert.same(String(params), 'a=b'); params.append('a', 'b'); assert.same(String(params), 'a=b&a=b'); params.append('a', 'c'); assert.same(String(params), 'a=b&a=b&a=c'); params = new URLSearchParams(); params.append('', ''); assert.same(String(params), '='); params.append('', ''); assert.same(String(params), '=&='); params = new URLSearchParams(); params.append(undefined, undefined); assert.same(String(params), 'undefined=undefined'); params.append(undefined, undefined); assert.same(String(params), 'undefined=undefined&undefined=undefined'); params = new URLSearchParams(); params.append(null, null); assert.same(String(params), 'null=null'); params.append(null, null); assert.same(String(params), 'null=null&null=null'); params = new URLSearchParams(); params.append('first', 1); params.append('second', 2); params.append('third', ''); params.append('first', 10); assert.true(params.has('first'), 'search params object has name "first"'); assert.same(params.get('first'), '1', 'search params object has name "first" with value "1"'); assert.same(params.get('second'), '2', 'search params object has name "second" with value "2"'); assert.same(params.get('third'), '', 'search params object has name "third" with value ""'); params.append('first', 10); assert.same(params.get('first'), '1', 'search params object has name "first" with value "1"'); assert.throws(() => { return new URLSearchParams('').append(); }, 'throws w/o arguments'); }); QUnit.test('URLSearchParams#delete', assert => { const $delete = URLSearchParams.prototype.delete; assert.isFunction($delete); assert.arity($delete, 1); assert.enumerable(URLSearchParams.prototype, 'delete'); let params = new URLSearchParams('a=b&c=d'); params.delete('a'); assert.same(String(params), 'c=d'); params = new URLSearchParams('a=a&b=b&a=a&c=c'); params.delete('a'); assert.same(String(params), 'b=b&c=c'); params = new URLSearchParams('a=a&=&b=b&c=c'); params.delete(''); assert.same(String(params), 'a=a&b=b&c=c'); params = new URLSearchParams('a=a&null=null&b=b'); params.delete(null); assert.same(String(params), 'a=a&b=b'); params = new URLSearchParams('a=a&undefined=undefined&b=b'); params.delete(undefined); assert.same(String(params), 'a=a&b=b'); params = new URLSearchParams(); params.append('first', 1); assert.true(params.has('first'), 'search params object has name "first"'); assert.same(params.get('first'), '1', 'search params object has name "first" with value "1"'); params.delete('first'); assert.false(params.has('first'), 'search params object has no "first" name'); params.append('first', 1); params.append('first', 10); params.delete('first'); assert.false(params.has('first'), 'search params object has no "first" name'); params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4'); params.delete('a', 2); assert.same(String(params), 'a=1&a=null&a=3&b=4'); params = new URLSearchParams('a=1&a=1&b=2&a=1'); params.delete('a', '1'); assert.same(String(params), 'b=2', 'delete with value removes all matching name+value pairs'); params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4'); params.delete('a', null); assert.same(String(params), 'a=1&a=2&a=3&b=4'); params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4'); params.delete('a', undefined); assert.same(String(params), 'b=4'); if (DESCRIPTORS) { let url = new URL('http://example.com/?param1&param2'); url.searchParams.delete('param1'); url.searchParams.delete('param2'); assert.same(String(url), 'http://example.com/', 'url.href does not have ?'); assert.same(url.search, '', 'url.search does not have ?'); url = new URL('http://example.com/?'); url.searchParams.delete('param1'); // assert.same(String(url), 'http://example.com/', 'url.href does not have ?'); // Safari bug assert.same(url.search, '', 'url.search does not have ?'); } assert.throws(() => { return new URLSearchParams('').delete(); }, 'throws w/o arguments'); }); QUnit.test('URLSearchParams#get', assert => { const { get } = URLSearchParams.prototype; assert.isFunction(get); assert.arity(get, 1); assert.enumerable(URLSearchParams.prototype, 'get'); let params = new URLSearchParams('a=b&c=d'); assert.same(params.get('a'), 'b'); assert.same(params.get('c'), 'd'); assert.same(params.get('e'), null); params = new URLSearchParams('a=b&c=d&a=e'); assert.same(params.get('a'), 'b'); params = new URLSearchParams('=b&c=d'); assert.same(params.get(''), 'b'); params = new URLSearchParams('a=&c=d&a=e'); assert.same(params.get('a'), ''); params = new URLSearchParams('first=second&third&&'); assert.true(params.has('first'), 'Search params object has name "first"'); assert.same(params.get('first'), 'second', 'Search params object has name "first" with value "second"'); assert.same(params.get('third'), '', 'Search params object has name "third" with the empty value.'); assert.same(params.get('fourth'), null, 'Search params object has no "fourth" name and value.'); assert.same(new URLSearchParams('a=b c').get('a'), 'b c'); assert.same(new URLSearchParams('a b=c').get('a b'), 'c'); assert.same(new URLSearchParams('a=b%20c').get('a'), 'b c', 'parse %20'); assert.same(new URLSearchParams('a%20b=c').get('a b'), 'c', 'parse %20'); assert.same(new URLSearchParams('a=b\0c').get('a'), 'b\0c', 'parse \\0'); assert.same(new URLSearchParams('a\0b=c').get('a\0b'), 'c', 'parse \\0'); assert.same(new URLSearchParams('a=b%2Bc').get('a'), 'b+c', 'parse %2B'); assert.same(new URLSearchParams('a%2Bb=c').get('a+b'), 'c', 'parse %2B'); assert.same(new URLSearchParams('a=b%00c').get('a'), 'b\0c', 'parse %00'); assert.same(new URLSearchParams('a%00b=c').get('a\0b'), 'c', 'parse %00'); assert.same(new URLSearchParams('a==').get('a'), '=', 'parse ='); assert.same(new URLSearchParams('a=b=').get('a'), 'b=', 'parse ='); assert.same(new URLSearchParams('a=b=c').get('a'), 'b=c', 'parse ='); assert.same(new URLSearchParams('a==b').get('a'), '=b', 'parse ='); assert.same(new URLSearchParams('a=b\u2384').get('a'), 'b\u2384', 'parse \\u2384'); assert.same(new URLSearchParams('a\u2384b=c').get('a\u2384b'), 'c', 'parse \\u2384'); assert.same(new URLSearchParams('a=b%e2%8e%84').get('a'), 'b\u2384', 'parse %e2%8e%84'); assert.same(new URLSearchParams('a%e2%8e%84b=c').get('a\u2384b'), 'c', 'parse %e2%8e%84'); assert.same(new URLSearchParams('a=b\uD83D\uDCA9c').get('a'), 'b\uD83D\uDCA9c', 'parse \\uD83D\\uDCA9'); assert.same(new URLSearchParams('a\uD83D\uDCA9b=c').get('a\uD83D\uDCA9b'), 'c', 'parse \\uD83D\\uDCA9'); assert.same(new URLSearchParams('a=b%f0%9f%92%a9c').get('a'), 'b\uD83D\uDCA9c', 'parse %f0%9f%92%a9'); assert.same(new URLSearchParams('a%f0%9f%92%a9b=c').get('a\uD83D\uDCA9b'), 'c', 'parse %f0%9f%92%a9'); assert.same(new URLSearchParams('=').get(''), '', 'parse ='); assert.throws(() => { return new URLSearchParams('').get(); }, 'throws w/o arguments'); }); QUnit.test('URLSearchParams#getAll', assert => { const { getAll } = URLSearchParams.prototype; assert.isFunction(getAll); assert.arity(getAll, 1); assert.enumerable(URLSearchParams.prototype, 'getAll'); let params = new URLSearchParams('a=b&c=d'); assert.arrayEqual(params.getAll('a'), ['b']); assert.arrayEqual(params.getAll('c'), ['d']); assert.arrayEqual(params.getAll('e'), []); params = new URLSearchParams('a=b&c=d&a=e'); assert.arrayEqual(params.getAll('a'), ['b', 'e']); params = new URLSearchParams('=b&c=d'); assert.arrayEqual(params.getAll(''), ['b']); params = new URLSearchParams('a=&c=d&a=e'); assert.arrayEqual(params.getAll('a'), ['', 'e']); params = new URLSearchParams('a=1&a=2&a=3&a'); assert.arrayEqual(params.getAll('a'), ['1', '2', '3', ''], 'search params object has expected name "a" values'); params.set('a', 'one'); assert.arrayEqual(params.getAll('a'), ['one'], 'search params object has expected name "a" values'); assert.throws(() => { return new URLSearchParams('').getAll(); }, 'throws w/o arguments'); }); QUnit.test('URLSearchParams#has', assert => { const { has } = URLSearchParams.prototype; assert.isFunction(has); assert.arity(has, 1); assert.enumerable(URLSearchParams.prototype, 'has'); let params = new URLSearchParams('a=b&c=d'); assert.true(params.has('a')); assert.true(params.has('c')); assert.false(params.has('e')); params = new URLSearchParams('a=b&c=d&a=e'); assert.true(params.has('a')); params = new URLSearchParams('=b&c=d'); assert.true(params.has('')); params = new URLSearchParams('null=a'); assert.true(params.has(null)); params = new URLSearchParams('a=b&c=d&&'); params.append('first', 1); params.append('first', 2); assert.true(params.has('a'), 'search params object has name "a"'); assert.true(params.has('c'), 'search params object has name "c"'); assert.true(params.has('first'), 'search params object has name "first"'); assert.false(params.has('d'), 'search params object has no name "d"'); params.delete('first'); assert.false(params.has('first'), 'search params object has no name "first"'); params = new URLSearchParams('a=1&a=2&a=null&a=3&b=4'); assert.true(params.has('a', 2)); assert.true(params.has('a', null)); assert.false(params.has('a', 4)); assert.true(params.has('b', 4)); assert.false(params.has('b', null)); assert.true(params.has('b', undefined)); assert.false(params.has('c', undefined)); assert.throws(() => { return new URLSearchParams('').has(); }, 'throws w/o arguments'); }); QUnit.test('URLSearchParams#set', assert => { const { set } = URLSearchParams.prototype; assert.isFunction(set); assert.arity(set, 2); assert.enumerable(URLSearchParams.prototype, 'set'); let params = new URLSearchParams('a=b&c=d'); params.set('a', 'B'); assert.same(String(params), 'a=B&c=d'); params = new URLSearchParams('a=b&c=d&a=e'); params.set('a', 'B'); assert.same(String(params), 'a=B&c=d'); params.set('e', 'f'); assert.same(String(params), 'a=B&c=d&e=f'); params = new URLSearchParams('a=1&a=2&a=3'); assert.true(params.has('a'), 'search params object has name "a"'); assert.same(params.get('a'), '1', 'search params object has name "a" with value "1"'); params.set('first', 4); assert.true(params.has('a'), 'search params object has name "a"'); assert.same(params.get('a'), '1', 'search params object has name "a" with value "1"'); assert.same(String(params), 'a=1&a=2&a=3&first=4'); params.set('a', 4); assert.true(params.has('a'), 'search params object has name "a"'); assert.same(params.get('a'), '4', 'search params object has name "a" with value "4"'); assert.same(String(params), 'a=4&first=4'); assert.throws(() => new URLSearchParams('').set(), 'throws w/o arguments'); assert.throws(() => new URLSearchParams('').set('a'), 'throws with only 1 argument'); }); QUnit.test('URLSearchParams#sort', assert => { const { sort } = URLSearchParams.prototype; assert.isFunction(sort); assert.arity(sort, 0); assert.enumerable(URLSearchParams.prototype, 'sort'); let params = new URLSearchParams('a=1&b=4&a=3&b=2'); params.sort(); assert.same(String(params), 'a=1&a=3&b=4&b=2'); params.delete('a'); params.append('a', '0'); params.append('b', '0'); params.sort(); assert.same(String(params), 'a=0&b=4&b=2&b=0'); const testData = [ { input: 'z=b&a=b&z=a&a=a', output: [['a', 'b'], ['a', 'a'], ['z', 'b'], ['z', 'a']], }, { input: '\uFFFD=x&\uFFFC&\uFFFD=a', output: [['\uFFFC', ''], ['\uFFFD', 'x'], ['\uFFFD', 'a']], }, { input: 'ffi&🌈', // 🌈 > code point, but < code unit because two code units output: [['🌈', ''], ['ffi', '']], }, { input: 'é&e\uFFFD&e\u0301', output: [['e\u0301', ''], ['e\uFFFD', ''], ['é', '']], }, { input: 'z=z&a=a&z=y&a=b&z=x&a=c&z=w&a=d&z=v&a=e&z=u&a=f&z=t&a=g', output: [ ['a', 'a'], ['a', 'b'], ['a', 'c'], ['a', 'd'], ['a', 'e'], ['a', 'f'], ['a', 'g'], ['z', 'z'], ['z', 'y'], ['z', 'x'], ['z', 'w'], ['z', 'v'], ['z', 'u'], ['z', 't'], ], }, { input: 'bbb&bb&aaa&aa=x&aa=y', output: [['aa', 'x'], ['aa', 'y'], ['aaa', ''], ['bb', ''], ['bbb', '']], }, { input: 'z=z&=f&=t&=x', output: [['', 'f'], ['', 't'], ['', 'x'], ['z', 'z']], }, { input: 'a🌈&a💩', output: [['a🌈', ''], ['a💩', '']], }, ]; for (const { input, output } of testData) { let i = 0; params = new URLSearchParams(input); params.sort(); params.forEach((value, key) => { const [reqKey, reqValue] = output[i++]; assert.same(key, reqKey); assert.same(value, reqValue); }); i = 0; const url = new URL(`?${ input }`, 'https://example/'); params = url.searchParams; params.sort(); params.forEach((value, key) => { const [reqKey, reqValue] = output[i++]; assert.same(key, reqKey); assert.same(value, reqValue); }); } if (DESCRIPTORS) { const url = new URL('http://example.com/?'); url.searchParams.sort(); assert.same(url.href, 'http://example.com/', 'Sorting non-existent params removes ? from URL'); assert.same(url.search, '', 'Sorting non-existent params removes ? from URL'); } }); QUnit.test('URLSearchParams#toString', assert => { const { toString } = URLSearchParams.prototype; assert.isFunction(toString); assert.arity(toString, 0); let params = new URLSearchParams(); params.append('a', 'b c'); assert.same(String(params), 'a=b+c'); params.delete('a'); params.append('a b', 'c'); assert.same(String(params), 'a+b=c'); params = new URLSearchParams(); params.append('a', ''); assert.same(String(params), 'a='); params.append('a', ''); assert.same(String(params), 'a=&a='); params.append('', 'b'); assert.same(String(params), 'a=&a=&=b'); params.append('', ''); assert.same(String(params), 'a=&a=&=b&='); params.append('', ''); assert.same(String(params), 'a=&a=&=b&=&='); params = new URLSearchParams(); params.append('', 'b'); assert.same(String(params), '=b'); params.append('', 'b'); assert.same(String(params), '=b&=b'); params = new URLSearchParams(); params.append('', ''); assert.same(String(params), '='); params.append('', ''); assert.same(String(params), '=&='); params = new URLSearchParams(); params.append('a', 'b+c'); assert.same(String(params), 'a=b%2Bc'); params.delete('a'); params.append('a+b', 'c'); assert.same(String(params), 'a%2Bb=c'); params = new URLSearchParams(); params.append('=', 'a'); assert.same(String(params), '%3D=a'); params.append('b', '='); assert.same(String(params), '%3D=a&b=%3D'); params = new URLSearchParams(); params.append('&', 'a'); assert.same(String(params), '%26=a'); params.append('b', '&'); assert.same(String(params), '%26=a&b=%26'); params = new URLSearchParams(); params.append('a', '\r'); assert.same(String(params), 'a=%0D'); params = new URLSearchParams(); params.append('a', '\n'); assert.same(String(params), 'a=%0A'); params = new URLSearchParams(); params.append('a', '\r\n'); assert.same(String(params), 'a=%0D%0A'); params = new URLSearchParams(); params.append('a', 'b%c'); assert.same(String(params), 'a=b%25c'); params.delete('a'); params.append('a%b', 'c'); assert.same(String(params), 'a%25b=c'); params = new URLSearchParams(); params.append('a', 'b\0c'); assert.same(String(params), 'a=b%00c'); params.delete('a'); params.append('a\0b', 'c'); assert.same(String(params), 'a%00b=c'); params = new URLSearchParams(); params.append('a', 'b\uD83D\uDCA9c'); assert.same(String(params), 'a=b%F0%9F%92%A9c'); params.delete('a'); params.append('a\uD83D\uDCA9b', 'c'); assert.same(String(params), 'a%F0%9F%92%A9b=c'); params = new URLSearchParams('a=b&c=d&&e&&'); assert.same(String(params), 'a=b&c=d&e='); params = new URLSearchParams('a = b &a=b&c=d%20'); assert.same(String(params), 'a+=+b+&a=b&c=d+'); params = new URLSearchParams('a=&a=b'); assert.same(String(params), 'a=&a=b'); }); QUnit.test('URLSearchParams#forEach', assert => { const { forEach } = URLSearchParams.prototype; assert.isFunction(forEach); assert.arity(forEach, 1); assert.enumerable(URLSearchParams.prototype, 'forEach'); const expectedValues = { a: '1', b: '2', c: '3' }; let params = new URLSearchParams('a=1&b=2&c=3'); let result = ''; params.forEach((value, key, that) => { assert.same(params.get(key), expectedValues[key]); assert.same(value, expectedValues[key]); assert.same(that, params); result += key; }); assert.same(result, 'abc'); new URL('http://a.b/c').searchParams.forEach(() => { assert.avoid(); }); // fails in Chrome 66- if (DESCRIPTORS) { const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4'); params = url.searchParams; result = ''; params.forEach((val, key) => { url.search = 'x=1&y=2&z=3'; result += key + val; }); assert.same(result, 'a1y2z3'); } // fails in Chrome 66- params = new URLSearchParams('a=1&b=2&c=3'); result = ''; params.forEach((value, key) => { params.delete('b'); result += key + value; }); assert.same(result, 'a1c3'); }); QUnit.test('URLSearchParams#entries', assert => { const { entries } = URLSearchParams.prototype; assert.isFunction(entries); assert.arity(entries, 0); assert.enumerable(URLSearchParams.prototype, 'entries'); const expectedValues = { a: '1', b: '2', c: '3' }; let params = new URLSearchParams('a=1&b=2&c=3'); let iterator = params.entries(); let result = ''; let entry; while (!(entry = iterator.next()).done) { const [key, value] = entry.value; assert.same(params.get(key), expectedValues[key]); assert.same(value, expectedValues[key]); result += key; } assert.same(result, 'abc'); assert.true(new URL('http://a.b/c').searchParams.entries().next().done, 'should be finished'); // fails in Chrome 66- if (DESCRIPTORS) { const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4'); iterator = url.searchParams.entries(); result = ''; while (!(entry = iterator.next()).done) { const [key, value] = entry.value; url.search = 'x=1&y=2&z=3'; result += key + value; } assert.same(result, 'a1y2z3'); } // fails in Chrome 66- params = new URLSearchParams('a=1&b=2&c=3'); iterator = params.entries(); result = ''; while (!(entry = iterator.next()).done) { params.delete('b'); const [key, value] = entry.value; result += key + value; } assert.same(result, 'a1c3'); if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().entries()), 'next').enumerable, 'enumerable .next'); }); QUnit.test('URLSearchParams#keys', assert => { const { keys } = URLSearchParams.prototype; assert.isFunction(keys); assert.arity(keys, 0); assert.enumerable(URLSearchParams.prototype, 'keys'); let iterator = new URLSearchParams('a=1&b=2&c=3').keys(); let result = ''; let entry; while (!(entry = iterator.next()).done) { result += entry.value; } assert.same(result, 'abc'); assert.true(new URL('http://a.b/c').searchParams.keys().next().done, 'should be finished'); // fails in Chrome 66- if (DESCRIPTORS) { const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4'); iterator = url.searchParams.keys(); result = ''; while (!(entry = iterator.next()).done) { const key = entry.value; url.search = 'x=1&y=2&z=3'; result += key; } assert.same(result, 'ayz'); } // fails in Chrome 66- const params = new URLSearchParams('a=1&b=2&c=3'); iterator = params.keys(); result = ''; while (!(entry = iterator.next()).done) { params.delete('b'); const key = entry.value; result += key; } assert.same(result, 'ac'); if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().keys()), 'next').enumerable, 'enumerable .next'); }); QUnit.test('URLSearchParams#values', assert => { const { values } = URLSearchParams.prototype; assert.isFunction(values); assert.arity(values, 0); assert.enumerable(URLSearchParams.prototype, 'values'); let iterator = new URLSearchParams('a=1&b=2&c=3').values(); let result = ''; let entry; while (!(entry = iterator.next()).done) { result += entry.value; } assert.same(result, '123'); assert.true(new URL('http://a.b/c').searchParams.values().next().done, 'should be finished'); // fails in Chrome 66- if (DESCRIPTORS) { const url = new URL('http://a.b/c?a=a&b=b&c=c&d=d'); iterator = url.searchParams.keys(); result = ''; while (!(entry = iterator.next()).done) { const { value } = entry; url.search = 'x=x&y=y&z=z'; result += value; } assert.same(result, 'ayz'); } // fails in Chrome 66- const params = new URLSearchParams('a=1&b=2&c=3'); iterator = params.values(); result = ''; while (!(entry = iterator.next()).done) { params.delete('b'); const key = entry.value; result += key; } assert.same(result, '13'); if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams().values()), 'next').enumerable, 'enumerable .next'); }); QUnit.test('URLSearchParams#@@iterator', assert => { const entries = URLSearchParams.prototype[Symbol.iterator]; assert.isFunction(entries); assert.arity(entries, 0); assert.same(entries, URLSearchParams.prototype.entries); const expectedValues = { a: '1', b: '2', c: '3' }; let params = new URLSearchParams('a=1&b=2&c=3'); let iterator = params[Symbol.iterator](); let result = ''; let entry; while (!(entry = iterator.next()).done) { const [key, value] = entry.value; assert.same(params.get(key), expectedValues[key]); assert.same(value, expectedValues[key]); result += key; } assert.same(result, 'abc'); assert.true(new URL('http://a.b/c').searchParams[Symbol.iterator]().next().done, 'should be finished'); // fails in Chrome 66- if (DESCRIPTORS) { const url = new URL('http://a.b/c?a=1&b=2&c=3&d=4'); iterator = url.searchParams[Symbol.iterator](); result = ''; while (!(entry = iterator.next()).done) { const [key, value] = entry.value; url.search = 'x=1&y=2&z=3'; result += key + value; } assert.same(result, 'a1y2z3'); } // fails in Chrome 66- params = new URLSearchParams('a=1&b=2&c=3'); iterator = params[Symbol.iterator](); result = ''; while (!(entry = iterator.next()).done) { params.delete('b'); const [key, value] = entry.value; result += key + value; } assert.same(result, 'a1c3'); if (DESCRIPTORS) assert.true(getOwnPropertyDescriptor(getPrototypeOf(new URLSearchParams()[Symbol.iterator]()), 'next').enumerable, 'enumerable .next'); }); QUnit.test('URLSearchParams#size', assert => { const params = new URLSearchParams('a=1&b=2&b=3'); assert.true('size' in params); assert.same(params.size, 3); if (DESCRIPTORS) { assert.true('size' in URLSearchParams.prototype); const { enumerable, configurable, get } = getOwnPropertyDescriptor(URLSearchParams.prototype, 'size'); assert.true(enumerable, 'enumerable'); // https://github.com/oven-sh/bun/issues/9251 if (!BUN) assert.true(configurable, 'configurable'); assert.throws(() => get.call([])); } });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.url.can-parse.js
JavaScript
import canParse from 'core-js-pure/stable/url/can-parse'; QUnit.test('URL.canParse', assert => { assert.isFunction(canParse); assert.arity(canParse, 1); assert.name(canParse, 'canParse'); assert.false(canParse(undefined), 'undefined'); assert.false(canParse(undefined, undefined), 'undefined, undefined'); assert.true(canParse('q:w'), 'q:w'); assert.true(canParse('q:w', undefined), 'q:w, undefined'); // assert.false(canParse(undefined, 'q:w'), 'undefined, q:w'); // fails in Chromium on Windows assert.true(canParse('q:/w'), 'q:/w'); assert.true(canParse('q:/w', undefined), 'q:/w, undefined'); assert.true(canParse(undefined, 'q:/w'), 'undefined, q:/w'); assert.false(canParse('https://login:password@examp:le.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'https://login:password@examp:le.com:8080/?a=1&b=2&a=3&c=4#fragment'); assert.true(canParse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'); assert.true(canParse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment', undefined), 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment, undefined'); assert.true(canParse('x', 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'x, https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'); assert.throws(() => canParse(), 'no args'); assert.throws(() => canParse({ toString() { throw new Error('thrower'); } }), 'conversion thrower #1'); assert.throws(() => canParse('q:w', { toString() { throw new Error('thrower'); } }), 'conversion thrower #2'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.url.js
JavaScript
/* eslint-disable es/no-object-getownpropertydescriptor, unicorn/relative-url-style -- required for testing */ import { DESCRIPTORS, NODE } from '../helpers/constants.js'; import urlTestData from '../wpt-url-resources/urltestdata.js'; import settersTestData from '../wpt-url-resources/setters.js'; import toASCIITestData from '../wpt-url-resources/toascii.js'; import URL from 'core-js-pure/stable/url'; import URLSearchParams from 'core-js-pure/stable/url-search-params'; const { hasOwnProperty } = Object.prototype; QUnit.test('URL constructor', assert => { assert.isFunction(URL); if (!NODE) assert.arity(URL, 1); assert.same(String(new URL('http://www.domain.com/a/b')), 'http://www.domain.com/a/b'); assert.same(String(new URL('/c/d', 'http://www.domain.com/a/b')), 'http://www.domain.com/c/d'); assert.same(String(new URL('b/c', 'http://www.domain.com/a/b')), 'http://www.domain.com/a/b/c'); assert.same(String(new URL('b/c', new URL('http://www.domain.com/a/b'))), 'http://www.domain.com/a/b/c'); assert.same(String(new URL({ toString: () => 'https://example.org/' })), 'https://example.org/'); assert.same(String(new URL('nonspecial://example.com/')), 'nonspecial://example.com/'); // SPECIAL_AUTHORITY_SLASHES state - special schemes without base assert.same(String(new URL('http://example.com/path')), 'http://example.com/path', 'special authority slashes with //'); assert.same(String(new URL('http:/example.com/path')), 'http://example.com/path', 'special authority slashes with single /'); assert.same(String(new URL('http:example.com/path')), 'http://example.com/path', 'special authority slashes without /'); assert.same(String(new URL('https:////example.com/path')), 'https://example.com/path', 'special authority slashes with extra /'); assert.same(String(new URL('https://測試')), 'https://xn--g6w251d/', 'unicode parsing'); assert.same(String(new URL('https://xxпривет.тест')), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing'); assert.same(String(new URL('https://xxПРИВЕТ.тест')), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing'); assert.same(String(new URL('http://Example.com/', 'https://example.org/')), 'http://example.com/'); assert.same(String(new URL('https://Example.com/', 'https://example.org/')), 'https://example.com/'); assert.same(String(new URL('nonspecial://Example.com/', 'https://example.org/')), 'nonspecial://Example.com/'); assert.same(String(new URL('http:Example.com/', 'https://example.org/')), 'http://example.com/'); assert.same(String(new URL('https:Example.com/', 'https://example.org/')), 'https://example.org/Example.com/'); assert.same(String(new URL('nonspecial:Example.com/', 'https://example.org/')), 'nonspecial:Example.com/'); assert.same(String(new URL('http://0300.168.0xF0')), 'http://192.168.0.240/'); assert.same(String(new URL('http://[20:0:0:1:0:0:0:ff]')), 'http://[20:0:0:1::ff]/'); // assert.same(String(new URL('http://257.168.0xF0')), 'http://257.168.0xf0/', 'incorrect IPv4 parsed as host'); // TypeError in Chrome and Safari assert.same(String(new URL('http://0300.168.0xG0')), 'http://0300.168.0xg0/', 'incorrect IPv4 parsed as host'); assert.same(String(new URL('file:///var/log/system.log')), 'file:///var/log/system.log', 'file scheme'); // assert.same(String(new URL('file://nnsc.nsf.net/bar/baz')), 'file://nnsc.nsf.net/bar/baz', 'file scheme'); // 'file:///bar/baz' in FF // assert.same(String(new URL('file://localhost/bar/baz')), 'file:///bar/baz', 'file scheme'); // 'file://localhost/bar/baz' in Chrome assert.throws(() => new URL(), 'TypeError: Failed to construct URL: 1 argument required, but only 0 present.'); assert.throws(() => new URL(''), 'TypeError: Failed to construct URL: Invalid URL'); // Node 19.7 // https://github.com/nodejs/node/issues/46755 // assert.throws(() => new URL('', 'about:blank'), 'TypeError: Failed to construct URL: Invalid URL'); assert.throws(() => new URL('abc'), 'TypeError: Failed to construct URL: Invalid URL'); assert.throws(() => new URL('//abc'), 'TypeError: Failed to construct URL: Invalid URL'); assert.throws(() => new URL('http:///www.domain.com/', 'abc'), 'TypeError: Failed to construct URL: Invalid base URL'); assert.throws(() => new URL('http:///www.domain.com/', null), 'TypeError: Failed to construct URL: Invalid base URL'); assert.throws(() => new URL('//abc', null), 'TypeError: Failed to construct URL: Invalid base URL'); assert.throws(() => new URL('http://[20:0:0:1:0:0:0:ff'), 'incorrect IPv6'); assert.throws(() => new URL('http://[20:0:0:1:0:0:0:fg]'), 'incorrect IPv6'); // assert.throws(() => new URL('http://a%b'), 'forbidden host code point'); // no error in FF assert.throws(() => new URL('1http://zloirock.ru'), 'incorrect scheme'); assert.throws(() => new URL('a,b://example.com'), 'comma in scheme'); assert.same(String(new URL('a+b-c.d://example.com')), 'a+b-c.d://example.com', 'valid scheme with +, -, .'); assert.same(String(new URL('relative', 'foo://host')), 'foo://host/relative', 'relative URL with non-special base with empty path'); assert.same(String(new URL('bar', 'foo://host/a/b')), 'foo://host/a/bar', 'relative URL with non-special base with path'); }); QUnit.test('URL#href', assert => { let url = new URL('http://zloirock.ru/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'href')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'href'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.href, 'http://zloirock.ru/'); if (DESCRIPTORS) { url.searchParams.append('foo', 'bar'); assert.same(url.href, 'http://zloirock.ru/?foo=bar'); url = new URL('http://zloirock.ru/foo'); url.href = 'https://測試'; assert.same(url.href, 'https://xn--g6w251d/', 'unicode parsing'); assert.same(String(url), 'https://xn--g6w251d/', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.href = 'https://xxпривет.тест'; assert.same(url.href, 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing'); assert.same(String(url), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.href = 'https://xxПРИВЕТ.тест'; assert.same(url.href, 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing'); assert.same(String(url), 'https://xn--xx-flcmn5bht.xn--e1aybc/', 'unicode parsing'); url = new URL('http://zloirock.ru/'); url.href = 'http://0300.168.0xF0'; assert.same(url.href, 'http://192.168.0.240/'); assert.same(String(url), 'http://192.168.0.240/'); url = new URL('http://zloirock.ru/'); url.href = 'http://[20:0:0:1:0:0:0:ff]'; assert.same(url.href, 'http://[20:0:0:1::ff]/'); assert.same(String(url), 'http://[20:0:0:1::ff]/'); // url = new URL('http://zloirock.ru/'); // url.href = 'http://257.168.0xF0'; // TypeError and Safari // assert.same(url.href, 'http://257.168.0xf0/', 'incorrect IPv4 parsed as host'); // `F` instead of `f` in Chrome // assert.same(String(url), 'http://257.168.0xf0/', 'incorrect IPv4 parsed as host'); // `F` instead of `f` in Chrome url = new URL('http://zloirock.ru/'); url.href = 'http://0300.168.0xG0'; assert.same(url.href, 'http://0300.168.0xg0/', 'incorrect IPv4 parsed as host'); assert.same(String(url), 'http://0300.168.0xg0/', 'incorrect IPv4 parsed as host'); url = new URL('http://192.168.0.240/'); url.href = 'file:///var/log/system.log'; assert.same(url.href, 'file:///var/log/system.log', 'file -> ip'); assert.same(String(url), 'file:///var/log/system.log', 'file -> ip'); url = new URL('file:///var/log/system.log'); url.href = 'http://0300.168.0xF0'; // Node 19.7 // https://github.com/nodejs/node/issues/46755 // assert.same(url.href, 'http://192.168.0.240/', 'file -> http'); // assert.same(String(url), 'http://192.168.0.240/', 'file -> http'); // assert.throws(() => new URL('http://zloirock.ru/').href = undefined, 'incorrect URL'); // no error in Chrome // assert.throws(() => new URL('http://zloirock.ru/').href = '', 'incorrect URL'); // no error in Chrome // assert.throws(() => new URL('http://zloirock.ru/').href = 'abc', 'incorrect URL'); // no error in Chrome // assert.throws(() => new URL('http://zloirock.ru/').href = '//abc', 'incorrect URL'); // no error in Chrome // assert.throws(() => new URL('http://zloirock.ru/').href = 'http://[20:0:0:1:0:0:0:ff', 'incorrect IPv6'); // no error in Chrome // assert.throws(() => new URL('http://zloirock.ru/').href = 'http://[20:0:0:1:0:0:0:fg]', 'incorrect IPv6'); // no error in Chrome // assert.throws(() => new URL('http://zloirock.ru/').href = 'http://a%b', 'forbidden host code point'); // no error in Chrome and FF // assert.throws(() => new URL('http://zloirock.ru/').href = '1http://zloirock.ru', 'incorrect scheme'); // no error in Chrome } // URL serializing step 3 - /. prefix for non-special URLs with null host and path starting with empty segment assert.same(new URL('x:/a/..//b').href, 'x:/.//b', '/. prefix prevents ambiguous serialization'); assert.same(new URL('x:/a/..//b').pathname, '//b', 'pathname is not affected by /. prefix'); assert.same(new URL('x:/.//b').href, 'x:/.//b', '/. prefix is idempotent'); assert.same(new URL(new URL('x:/a/..//b').href).pathname, '//b', '/. prefix round-trips correctly'); }); QUnit.test('URL#origin', assert => { const url = new URL('http://es6.zloirock.ru/tests.html'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'origin')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'origin'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); } assert.same(url.origin, 'http://es6.zloirock.ru'); assert.same(new URL('https://測試/tests').origin, 'https://xn--g6w251d'); }); QUnit.test('URL#protocol', assert => { let url = new URL('http://zloirock.ru/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'protocol')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'protocol'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.protocol, 'http:'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/'); url.protocol = 'https'; assert.same(url.protocol, 'https:'); assert.same(String(url), 'https://zloirock.ru/'); // https://nodejs.org/api/url.html#url_special_schemes // url = new URL('http://zloirock.ru/'); // url.protocol = 'fish'; // assert.same(url.protocol, 'http:'); // assert.same(url.href, 'http://zloirock.ru/'); // assert.same(String(url), 'http://zloirock.ru/'); url = new URL('http://zloirock.ru/'); url.protocol = '1http'; assert.same(url.protocol, 'http:'); assert.same(url.href, 'http://zloirock.ru/', 'incorrect scheme'); assert.same(String(url), 'http://zloirock.ru/', 'incorrect scheme'); } }); QUnit.test('URL#username', assert => { let url = new URL('http://zloirock.ru/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'username')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'username'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.username, ''); url = new URL('http://username@zloirock.ru/'); assert.same(url.username, 'username'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/'); url.username = 'username'; assert.same(url.username, 'username'); assert.same(String(url), 'http://username@zloirock.ru/'); } }); QUnit.test('URL#password', assert => { let url = new URL('http://zloirock.ru/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'password')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'password'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.password, ''); url = new URL('http://username:password@zloirock.ru/'); assert.same(url.password, 'password'); // url = new URL('http://:password@zloirock.ru/'); // TypeError in FF // assert.same(url.password, 'password'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/'); url.username = 'username'; url.password = 'password'; assert.same(url.password, 'password'); assert.same(String(url), 'http://username:password@zloirock.ru/'); // url = new URL('http://zloirock.ru/'); // url.password = 'password'; // assert.same(url.password, 'password'); // '' in FF // assert.same(String(url), 'http://:password@zloirock.ru/'); // 'http://zloirock.ru/' in FF } }); QUnit.test('URL#host', assert => { let url = new URL('http://zloirock.ru:81/path'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'host')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'host'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.host, 'zloirock.ru:81'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru:81/path'); url.host = 'example.com:82'; assert.same(url.host, 'example.com:82'); assert.same(String(url), 'http://example.com:82/path'); // url = new URL('http://zloirock.ru:81/path'); // url.host = 'other?domain.com'; // assert.same(String(url), 'http://other:81/path'); // 'http://other/?domain.com/path' in Safari url = new URL('https://www.mydomain.com:8080/path/'); url.host = 'www.otherdomain.com:80'; assert.same(url.href, 'https://www.otherdomain.com:80/path/', 'set default port for another protocol'); // url = new URL('https://www.mydomain.com:8080/path/'); // url.host = 'www.otherdomain.com:443'; // assert.same(url.href, 'https://www.otherdomain.com/path/', 'set default port'); url = new URL('http://zloirock.ru/foo'); url.host = '測試'; assert.same(url.host, 'xn--g6w251d', 'unicode parsing'); assert.same(String(url), 'http://xn--g6w251d/foo', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.host = 'xxпривет.тест'; assert.same(url.host, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing'); assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.host = 'xxПРИВЕТ.тест'; assert.same(url.host, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing'); assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.host = '0300.168.0xF0'; assert.same(url.host, '192.168.0.240'); assert.same(String(url), 'http://192.168.0.240/foo'); // url = new URL('http://zloirock.ru/foo'); // url.host = '[20:0:0:1:0:0:0:ff]'; // assert.same(url.host, '[20:0:0:1::ff]'); // ':0' in Chrome, 'zloirock.ru' in Safari // assert.same(String(url), 'http://[20:0:0:1::ff]/foo'); // 'http://[20:0/foo' in Chrome, 'http://zloirock.ru/foo' in Safari // url = new URL('file:///var/log/system.log'); // url.host = 'nnsc.nsf.net'; // does not work in FF // assert.same(url.hostname, 'nnsc.nsf.net', 'file'); // assert.same(String(url), 'file://nnsc.nsf.net/var/log/system.log', 'file'); // url = new URL('http://zloirock.ru/'); // url.host = '[20:0:0:1:0:0:0:ff'; // assert.same(url.host, 'zloirock.ru', 'incorrect IPv6'); // ':0' in Chrome // assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0/' in Chrome // url = new URL('http://zloirock.ru/'); // url.host = '[20:0:0:1:0:0:0:fg]'; // assert.same(url.host, 'zloirock.ru', 'incorrect IPv6'); // ':0' in Chrome // assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0/' in Chrome // url = new URL('http://zloirock.ru/'); // url.host = 'a%b'; // assert.same(url.host, 'zloirock.ru', 'forbidden host code point'); // '' in Chrome, 'a%b' in FF // assert.same(String(url), 'http://zloirock.ru/', 'forbidden host code point'); // 'http://a%25b/' in Chrome, 'http://a%b/' in FF } }); QUnit.test('URL#hostname', assert => { let url = new URL('http://zloirock.ru:81/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'hostname')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'hostname'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.hostname, 'zloirock.ru'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru:81/'); url.hostname = 'example.com'; assert.same(url.hostname, 'example.com'); assert.same(String(url), 'http://example.com:81/'); url = new URL('http://zloirock.ru:81/'); url.hostname = 'example.com:82'; assert.same(url.hostname, 'zloirock.ru', 'hostname with port is rejected'); assert.same(String(url), 'http://zloirock.ru:81/', 'hostname with port is rejected'); url = new URL('http://zloirock.ru/foo'); url.hostname = '測試'; assert.same(url.hostname, 'xn--g6w251d', 'unicode parsing'); assert.same(String(url), 'http://xn--g6w251d/foo', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.hostname = 'xxпривет.тест'; assert.same(url.hostname, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing'); assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.hostname = 'xxПРИВЕТ.тест'; assert.same(url.hostname, 'xn--xx-flcmn5bht.xn--e1aybc', 'unicode parsing'); assert.same(String(url), 'http://xn--xx-flcmn5bht.xn--e1aybc/foo', 'unicode parsing'); url = new URL('http://zloirock.ru/foo'); url.hostname = '0300.168.0xF0'; assert.same(url.hostname, '192.168.0.240'); assert.same(String(url), 'http://192.168.0.240/foo'); // url = new URL('http://zloirock.ru/foo'); // url.hostname = '[20:0:0:1:0:0:0:ff]'; // assert.same(url.hostname, '[20:0:0:1::ff]'); // 'zloirock.ru' in Safari // assert.same(String(url), 'http://[20:0:0:1::ff]/foo'); // 'http://zloirock.ru/foo' in Safari // url = new URL('file:///var/log/system.log'); // url.hostname = 'nnsc.nsf.net'; // does not work in FF // assert.same(url.hostname, 'nnsc.nsf.net', 'file'); // assert.same(String(url), 'file://nnsc.nsf.net/var/log/system.log', 'file'); // url = new URL('http://zloirock.ru/'); // url.hostname = '[20:0:0:1:0:0:0:ff'; // assert.same(url.hostname, 'zloirock.ru', 'incorrect IPv6'); // '' in Chrome // assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0:0:1:0:0:0:ff' in Chrome // url = new URL('http://zloirock.ru/'); // url.hostname = '[20:0:0:1:0:0:0:fg]'; // assert.same(url.hostname, 'zloirock.ru', 'incorrect IPv6'); // '' in Chrome // assert.same(String(url), 'http://zloirock.ru/', 'incorrect IPv6'); // 'http://[20:0:0:1:0:0:0:ff/' in Chrome // url = new URL('http://zloirock.ru/'); // url.hostname = 'a%b'; // assert.same(url.hostname, 'zloirock.ru', 'forbidden host code point'); // '' in Chrome, 'a%b' in FF // assert.same(String(url), 'http://zloirock.ru/', 'forbidden host code point'); // 'http://a%25b/' in Chrome, 'http://a%b/' in FF } }); QUnit.test('URL#port', assert => { let url = new URL('http://zloirock.ru:1337/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'port')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'port'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.port, '1337'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/'); url.port = 80; assert.same(url.port, ''); assert.same(String(url), 'http://zloirock.ru/'); url.port = 1337; assert.same(url.port, '1337'); assert.same(String(url), 'http://zloirock.ru:1337/'); // url.port = 'abcd'; // assert.same(url.port, '1337'); // '0' in Chrome // assert.same(String(url), 'http://zloirock.ru:1337/'); // 'http://zloirock.ru:0/' in Chrome // url.port = '5678abcd'; // assert.same(url.port, '5678'); // '1337' in FF // assert.same(String(url), 'http://zloirock.ru:5678/'); // 'http://zloirock.ru:1337/"' in FF url.port = 1234.5678; assert.same(url.port, '1234'); assert.same(String(url), 'http://zloirock.ru:1234/'); // url.port = 1e10; // assert.same(url.port, '1234'); // '0' in Chrome // assert.same(String(url), 'http://zloirock.ru:1234/'); // 'http://zloirock.ru:0/' in Chrome } }); QUnit.test('URL#pathname', assert => { let url = new URL('http://zloirock.ru/foo/bar'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'pathname')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'pathname'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.pathname, '/foo/bar'); // fails in Node 23- // url = new URL('http://example.com/a^b'); // assert.same(url.pathname, '/a%5Eb', 'caret in path is percent-encoded'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/'); url.pathname = 'bar/baz'; assert.same(url.pathname, '/bar/baz'); assert.same(String(url), 'http://zloirock.ru/bar/baz'); } }); QUnit.test('URL#search', assert => { let url = new URL('http://zloirock.ru/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'search')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'search'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.search, ''); url = new URL('http://zloirock.ru/?foo=bar'); assert.same(url.search, '?foo=bar'); // query percent-encode set assert.same(new URL('http://x/?a="<>').search, '?a=%22%3C%3E', 'query percent-encodes ", <, >'); assert.same(new URL('http://x/?a=\'').search, '?a=%27', 'special query percent-encodes \''); // fails in modern Chrome (~145) // assert.same(new URL('foo://x/?a=\'').search, '?a=\'', 'non-special query does not percent-encode \''); // space in opaque paths should not be percent-encoded // eslint-disable-next-line no-script-url -- safe assert.same(new URL('javascript:void 0').href, 'javascript:void 0', 'space preserved in opaque path'); // eslint-disable-next-line no-script-url -- safe assert.same(new URL('javascript:void 0').pathname, 'void 0', 'space preserved in opaque pathname'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/?'); assert.same(url.search, ''); assert.same(String(url), 'http://zloirock.ru/?'); url.search = 'foo=bar'; assert.same(url.search, '?foo=bar'); assert.same(String(url), 'http://zloirock.ru/?foo=bar'); url.search = '?bar=baz'; assert.same(url.search, '?bar=baz'); assert.same(String(url), 'http://zloirock.ru/?bar=baz'); url.search = ''; assert.same(url.search, ''); assert.same(String(url), 'http://zloirock.ru/'); } }); QUnit.test('URL#searchParams', assert => { let url = new URL('http://zloirock.ru/?foo=bar&bar=baz'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'searchParams')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'searchParams'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); } assert.true(url.searchParams instanceof URLSearchParams); assert.same(url.searchParams.get('foo'), 'bar'); assert.same(url.searchParams.get('bar'), 'baz'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/'); url.searchParams.append('foo', 'bar'); assert.same(String(url), 'http://zloirock.ru/?foo=bar'); url = new URL('http://zloirock.ru/'); url.search = 'foo=bar'; assert.same(url.searchParams.get('foo'), 'bar'); url = new URL('http://zloirock.ru/?foo=bar&bar=baz'); url.search = ''; assert.false(url.searchParams.has('foo')); } }); QUnit.test('URL#hash', assert => { let url = new URL('http://zloirock.ru/'); if (DESCRIPTORS) { assert.false(hasOwnProperty.call(url, 'hash')); const descriptor = Object.getOwnPropertyDescriptor(URL.prototype, 'hash'); assert.true(descriptor.enumerable); assert.true(descriptor.configurable); assert.same(typeof descriptor.get, 'function'); assert.same(typeof descriptor.set, 'function'); } assert.same(url.hash, ''); url = new URL('http://zloirock.ru/#foo'); assert.same(url.hash, '#foo'); url = new URL('http://zloirock.ru/#'); assert.same(url.hash, ''); assert.same(String(url), 'http://zloirock.ru/#'); if (DESCRIPTORS) { url = new URL('http://zloirock.ru/#'); url.hash = 'foo'; assert.same(url.hash, '#foo'); assert.same(String(url), 'http://zloirock.ru/#foo'); url.hash = ''; assert.same(url.hash, ''); assert.same(String(url), 'http://zloirock.ru/'); // url.hash = '#'; // assert.same(url.hash, ''); // assert.same(String(url), 'http://zloirock.ru/'); // 'http://zloirock.ru/#' in FF url.hash = '#foo'; assert.same(url.hash, '#foo'); assert.same(String(url), 'http://zloirock.ru/#foo'); url.hash = '#foo#bar'; assert.same(url.hash, '#foo#bar'); assert.same(String(url), 'http://zloirock.ru/#foo#bar'); url = new URL('http://zloirock.ru/'); url.hash = 'абa'; assert.same(url.hash, '#%D0%B0%D0%B1a'); // url = new URL('http://zloirock.ru/'); // url.hash = '\udc01\ud802a'; // assert.same(url.hash, '#%EF%BF%BD%EF%BF%BDa', 'unmatched surrogates'); } }); QUnit.test('URL#toJSON', assert => { const { toJSON } = URL.prototype; assert.isFunction(toJSON); assert.arity(toJSON, 0); assert.enumerable(URL.prototype, 'toJSON'); const url = new URL('http://zloirock.ru/'); assert.same(url.toJSON(), 'http://zloirock.ru/'); if (DESCRIPTORS) { url.searchParams.append('foo', 'bar'); assert.same(url.toJSON(), 'http://zloirock.ru/?foo=bar'); } }); QUnit.test('URL#toString', assert => { const { toString } = URL.prototype; assert.isFunction(toString); assert.arity(toString, 0); assert.enumerable(URL.prototype, 'toString'); const url = new URL('http://zloirock.ru/'); assert.same(url.toString(), 'http://zloirock.ru/'); if (DESCRIPTORS) { url.searchParams.append('foo', 'bar'); assert.same(url.toString(), 'http://zloirock.ru/?foo=bar'); } }); QUnit.test('URL.sham', assert => { assert.same(URL.sham, DESCRIPTORS ? undefined : true); }); // `core-js` URL implementation pass all (exclude some encoding-related) tests // from the next 3 test cases, but URLs from all of popular browsers fail a serious part of tests. // Replacing all of them does not looks like a good idea, so next test cases disabled by default. // see https://github.com/web-platform-tests/wpt/blob/master/url QUnit.skip('WPT URL constructor tests', assert => { for (const expected of urlTestData) { if (typeof expected == 'string') continue; const name = `Parsing: <${ expected.input }> against <${ expected.base }>`; if (expected.failure) { assert.throws(() => new URL(expected.input, expected.base || 'about:blank'), name); } else { const url = new URL(expected.input, expected.base || 'about:blank'); assert.same(url.href, expected.href, `${ name }: href`); assert.same(url.protocol, expected.protocol, `${ name }: protocol`); assert.same(url.username, expected.username, `${ name }: username`); assert.same(url.password, expected.password, `${ name }: password`); assert.same(url.host, expected.host, `${ name }: host`); assert.same(url.hostname, expected.hostname, `${ name }: hostname`); assert.same(url.port, expected.port, `${ name }: port`); assert.same(url.pathname, expected.pathname, `${ name }: pathname`); assert.same(url.search, expected.search, `${ name }: search`); if ('searchParams' in expected) { assert.same(url.searchParams.toString(), expected.searchParams, `${ name }: searchParams`); } assert.same(url.hash, expected.hash, `${ name }: hash`); if ('origin' in expected) { assert.same(url.origin, expected.origin, `${ name }: origin`); } } } }); // see https://github.com/web-platform-tests/wpt/blob/master/url if (DESCRIPTORS) QUnit.skip('WPT URL setters tests', assert => { for (const setter in settersTestData) { const testCases = settersTestData[setter]; for (const { href, newValue, comment, expected } of testCases) { let name = `Setting <${ href }>.${ setter } = '${ newValue }'.`; if (comment) name += ` ${ comment }`; const url = new URL(href); url[setter] = newValue; for (const attribute in expected) { assert.same(url[attribute], expected[attribute], name); } } } }); // see https://github.com/web-platform-tests/wpt/blob/master/url QUnit.skip('WPT conversion to ASCII tests', assert => { for (const { comment, input, output } of toASCIITestData) { let name = `Parsing: <${ input }>`; if (comment) name += ` ${ comment }`; if (output === null) { assert.throws(() => new URL(`https://${ input }/x`), name); } else { const url = new URL(`https://${ input }/x`); assert.same(url.host, output, name); assert.same(url.hostname, output, name); assert.same(url.pathname, '/x', name); assert.same(url.href, `https://${ output }/x`, name); } } });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/unit-pure/web.url.parse.js
JavaScript
import URL from 'core-js-pure/stable/url'; import parse from 'core-js-pure/stable/url/parse'; QUnit.test('URL.parse', assert => { assert.isFunction(parse); assert.arity(parse, 1); assert.name(parse, 'parse'); assert.same(parse(undefined), null, 'undefined'); assert.same(parse(undefined, undefined), null, 'undefined, undefined'); assert.deepEqual(parse('q:w'), new URL('q:w'), 'q:w'); assert.deepEqual(parse('q:w', undefined), new URL('q:w'), 'q:w, undefined'); assert.deepEqual(parse('q:/w'), new URL('q:/w'), 'q:/w'); assert.deepEqual(parse('q:/w', undefined), new URL('q:/w', undefined), 'q:/w, undefined'); assert.deepEqual(parse(undefined, 'q:/w'), new URL(undefined, 'q:/w'), 'undefined, q:/w'); assert.same(parse('https://login:password@examp:le.com:8080/?a=1&b=2&a=3&c=4#fragment'), null, 'https://login:password@examp:le.com:8080/?a=1&b=2&a=3&c=4#fragment'); assert.deepEqual(parse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), new URL('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'); assert.deepEqual(parse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment', undefined), new URL('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment', undefined), 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment, undefined'); // eslint-disable-next-line unicorn/relative-url-style -- required for testing assert.deepEqual(parse('x', 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), new URL('x', 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'), 'x, https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'); assert.throws(() => parse(), 'no args'); assert.throws(() => parse({ toString() { throw new Error('thrower'); } }), 'conversion thrower #1'); assert.throws(() => parse('q:w', { toString() { throw new Error('thrower'); } }), 'conversion thrower #2'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/worker/index.html
HTML
<!DOCTYPE html> <meta charset='UTF-8'> <title>Worker test</title> <script src='./worker/test.js'></script>
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/worker/runner.js
JavaScript
'use strict'; importScripts('../../packages/core-js-bundle/index.js'); postMessage(typeof core != 'undefined'); setImmediate(function () { postMessage('setImmediate'); }); // eslint-disable-next-line es/no-promise -- safe Promise.resolve().then(function () { postMessage('Promise.resolve'); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/worker/test.js
JavaScript
'use strict'; var worker = new Worker('./worker/runner.js'); worker.addEventListener('error', function (e) { // eslint-disable-next-line no-console -- output console.error(e); }); worker.addEventListener('message', function (message) { // eslint-disable-next-line no-console -- output console.log(message.data); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/wpt-url-resources/setters.js
JavaScript
// Copyright © web-platform-tests contributors // Originally from https://github.com/web-platform-tests/wpt // Available under the 3-Clause BSD License https://github.com/web-platform-tests/wpt/blob/master/LICENSE.md /* eslint-disable no-script-url -- required for testing */ export default { protocol: [ { comment: 'The empty string is not a valid scheme. Setter leaves the URL unchanged.', href: 'a://example.net', newValue: '', expected: { href: 'a://example.net', protocol: 'a:', }, }, { href: 'a://example.net', newValue: 'b', expected: { href: 'b://example.net', protocol: 'b:', }, }, { href: 'javascript:alert(1)', newValue: 'defuse', expected: { href: 'defuse:alert(1)', protocol: 'defuse:', }, }, { comment: 'Upper-case ASCII is lower-cased', href: 'a://example.net', newValue: 'B', expected: { href: 'b://example.net', protocol: 'b:', }, }, { comment: 'Non-ASCII is rejected', href: 'a://example.net', newValue: 'é', expected: { href: 'a://example.net', protocol: 'a:', }, }, { comment: 'No leading digit', href: 'a://example.net', newValue: '0b', expected: { href: 'a://example.net', protocol: 'a:', }, }, { comment: 'No leading punctuation', href: 'a://example.net', newValue: '+b', expected: { href: 'a://example.net', protocol: 'a:', }, }, { href: 'a://example.net', newValue: 'bC0+-.', expected: { href: 'bc0+-.://example.net', protocol: 'bc0+-.:', }, }, { comment: 'Only some punctuation is acceptable', href: 'a://example.net', newValue: 'b,c', expected: { href: 'a://example.net', protocol: 'a:', }, }, { comment: 'Non-ASCII is rejected', href: 'a://example.net', newValue: 'bé', expected: { href: 'a://example.net', protocol: 'a:', }, }, { comment: 'Can’t switch from URL containing username/password/port to file', href: 'http://test@example.net', newValue: 'file', expected: { href: 'http://test@example.net/', protocol: 'http:', }, }, { href: 'wss://x:x@example.net:1234', newValue: 'file', expected: { href: 'wss://x:x@example.net:1234/', protocol: 'wss:', }, }, { comment: 'Can’t switch from file URL with no host', href: 'file://localhost/', newValue: 'http', expected: { href: 'file:///', protocol: 'file:', }, }, { href: 'file:', newValue: 'wss', expected: { href: 'file:///', protocol: 'file:', }, }, { comment: 'Can’t switch from special scheme to non-special', href: 'http://example.net', newValue: 'b', expected: { href: 'http://example.net/', protocol: 'http:', }, }, { href: 'file://hi/path', newValue: 's', expected: { href: 'file://hi/path', protocol: 'file:', }, }, { href: 'https://example.net', newValue: 's', expected: { href: 'https://example.net/', protocol: 'https:', }, }, { href: 'ftp://example.net', newValue: 'test', expected: { href: 'ftp://example.net/', protocol: 'ftp:', }, }, { comment: 'Cannot-be-a-base URL doesn’t have a host, but URL in a special scheme must.', href: 'mailto:me@example.net', newValue: 'http', expected: { href: 'mailto:me@example.net', protocol: 'mailto:', }, }, { comment: 'Can’t switch from non-special scheme to special', href: 'ssh://me@example.net', newValue: 'http', expected: { href: 'ssh://me@example.net', protocol: 'ssh:', }, }, { href: 'ssh://me@example.net', newValue: 'file', expected: { href: 'ssh://me@example.net', protocol: 'ssh:', }, }, { href: 'ssh://example.net', newValue: 'file', expected: { href: 'ssh://example.net', protocol: 'ssh:', }, }, { href: 'nonsense:///test', newValue: 'https', expected: { href: 'nonsense:///test', protocol: 'nonsense:', }, }, { comment: "Stuff after the first ':' is ignored", href: 'http://example.net', newValue: 'https:foo : bar', expected: { href: 'https://example.net/', protocol: 'https:', }, }, { comment: "Stuff after the first ':' is ignored", href: 'data:text/html,<p>Test', newValue: 'view-source+data:foo : bar', expected: { href: 'view-source+data:text/html,<p>Test', protocol: 'view-source+data:', }, }, { comment: 'Port is set to null if it is the default for new scheme.', href: 'http://foo.com:443/', newValue: 'https', expected: { href: 'https://foo.com/', protocol: 'https:', port: '', }, }, ], username: [ { comment: 'No host means no username', href: 'file:///home/you/index.html', newValue: 'me', expected: { href: 'file:///home/you/index.html', username: '', }, }, { comment: 'No host means no username', href: 'unix:/run/foo.socket', newValue: 'me', expected: { href: 'unix:/run/foo.socket', username: '', }, }, { comment: 'Cannot-be-a-base means no username', href: 'mailto:you@example.net', newValue: 'me', expected: { href: 'mailto:you@example.net', username: '', }, }, { href: 'javascript:alert(1)', newValue: 'wario', expected: { href: 'javascript:alert(1)', username: '', }, }, { href: 'http://example.net', newValue: 'me', expected: { href: 'http://me@example.net/', username: 'me', }, }, { href: 'http://:secret@example.net', newValue: 'me', expected: { href: 'http://me:secret@example.net/', username: 'me', }, }, { href: 'http://me@example.net', newValue: '', expected: { href: 'http://example.net/', username: '', }, }, { href: 'http://me:secret@example.net', newValue: '', expected: { href: 'http://:secret@example.net/', username: '', }, }, { comment: 'UTF-8 percent encoding with the userinfo encode set.', href: 'http://example.net', newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé", expected: { href: "http://%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/", username: "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9", }, }, { comment: 'Bytes already percent-encoded are left as-is.', href: 'http://example.net', newValue: '%c3%89té', expected: { href: 'http://%c3%89t%C3%A9@example.net/', username: '%c3%89t%C3%A9', }, }, { href: 'sc:///', newValue: 'x', expected: { href: 'sc:///', username: '', }, }, { href: 'javascript://x/', newValue: 'wario', expected: { href: 'javascript://wario@x/', username: 'wario', }, }, { href: 'file://test/', newValue: 'test', expected: { href: 'file://test/', username: '', }, }, ], password: [ { comment: 'No host means no password', href: 'file:///home/me/index.html', newValue: 'secret', expected: { href: 'file:///home/me/index.html', password: '', }, }, { comment: 'No host means no password', href: 'unix:/run/foo.socket', newValue: 'secret', expected: { href: 'unix:/run/foo.socket', password: '', }, }, { comment: 'Cannot-be-a-base means no password', href: 'mailto:me@example.net', newValue: 'secret', expected: { href: 'mailto:me@example.net', password: '', }, }, { href: 'http://example.net', newValue: 'secret', expected: { href: 'http://:secret@example.net/', password: 'secret', }, }, { href: 'http://me@example.net', newValue: 'secret', expected: { href: 'http://me:secret@example.net/', password: 'secret', }, }, { href: 'http://:secret@example.net', newValue: '', expected: { href: 'http://example.net/', password: '', }, }, { href: 'http://me:secret@example.net', newValue: '', expected: { href: 'http://me@example.net/', password: '', }, }, { comment: 'UTF-8 percent encoding with the userinfo encode set.', href: 'http://example.net', newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé", expected: { href: "http://:%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9@example.net/", password: "%00%01%09%0A%0D%1F%20!%22%23$%&'()*+,-.%2F09%3A%3B%3C%3D%3E%3F%40AZ%5B%5C%5D%5E_%60az%7B%7C%7D~%7F%C2%80%C2%81%C3%89%C3%A9", }, }, { comment: 'Bytes already percent-encoded are left as-is.', href: 'http://example.net', newValue: '%c3%89té', expected: { href: 'http://:%c3%89t%C3%A9@example.net/', password: '%c3%89t%C3%A9', }, }, { href: 'sc:///', newValue: 'x', expected: { href: 'sc:///', password: '', }, }, { href: 'javascript://x/', newValue: 'bowser', expected: { href: 'javascript://:bowser@x/', password: 'bowser', }, }, { href: 'file://test/', newValue: 'test', expected: { href: 'file://test/', password: '', }, }, ], host: [ { comment: 'Non-special scheme', href: 'sc://x/', newValue: '\u0000', expected: { href: 'sc://x/', host: 'x', hostname: 'x', }, }, { href: 'sc://x/', newValue: '\u0009', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '\u000A', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '\u000D', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: ' ', expected: { href: 'sc://x/', host: 'x', hostname: 'x', }, }, { href: 'sc://x/', newValue: '#', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '/', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '?', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '@', expected: { href: 'sc://x/', host: 'x', hostname: 'x', }, }, { href: 'sc://x/', newValue: 'ß', expected: { href: 'sc://%C3%9F/', host: '%C3%9F', hostname: '%C3%9F', }, }, { comment: 'IDNA Nontransitional_Processing', href: 'https://x/', newValue: 'ß', expected: { href: 'https://xn--zca/', host: 'xn--zca', hostname: 'xn--zca', }, }, { comment: 'Cannot-be-a-base means no host', href: 'mailto:me@example.net', newValue: 'example.com', expected: { href: 'mailto:me@example.net', host: '', }, }, { comment: 'Cannot-be-a-base means no password', href: 'data:text/plain,Stuff', newValue: 'example.net', expected: { href: 'data:text/plain,Stuff', host: '', }, }, { href: 'http://example.net', newValue: 'example.com:8080', expected: { href: 'http://example.com:8080/', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Port number is unchanged if not specified in the new value', href: 'http://example.net:8080', newValue: 'example.com', expected: { href: 'http://example.com:8080/', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Port number is unchanged if not specified', href: 'http://example.net:8080', newValue: 'example.com:', expected: { href: 'http://example.com:8080/', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'The empty host is not valid for special schemes', href: 'http://example.net', newValue: '', expected: { href: 'http://example.net/', host: 'example.net', }, }, { comment: 'The empty host is OK for non-special schemes', href: 'view-source+http://example.net/foo', newValue: '', expected: { href: 'view-source+http:///foo', host: '', }, }, { comment: 'Path-only URLs can gain a host', href: 'a:/foo', newValue: 'example.net', expected: { href: 'a://example.net/foo', host: 'example.net', }, }, { comment: 'IPv4 address syntax is normalized', href: 'http://example.net', newValue: '0x7F000001:8080', expected: { href: 'http://127.0.0.1:8080/', host: '127.0.0.1:8080', hostname: '127.0.0.1', port: '8080', }, }, { comment: 'IPv6 address syntax is normalized', href: 'http://example.net', newValue: '[::0:01]:2', expected: { href: 'http://[::1]:2/', host: '[::1]:2', hostname: '[::1]', port: '2', }, }, { comment: 'Default port number is removed', href: 'http://example.net', newValue: 'example.com:80', expected: { href: 'http://example.com/', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Default port number is removed', href: 'https://example.net', newValue: 'example.com:443', expected: { href: 'https://example.com/', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Default port number is only removed for the relevant scheme', href: 'https://example.net', newValue: 'example.com:80', expected: { href: 'https://example.com:80/', host: 'example.com:80', hostname: 'example.com', port: '80', }, }, { comment: 'Port number is removed if new port is scheme default and existing URL has a non-default port', href: 'http://example.net:8080', newValue: 'example.com:80', expected: { href: 'http://example.com/', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a / delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com/stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a / delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com:8080/stuff', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Stuff after a ? delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com?stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a ? delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com:8080?stuff', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Stuff after a # delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com#stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a # delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com:8080#stuff', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Stuff after a \\ delimiter is ignored for special schemes', href: 'http://example.net/path', newValue: 'example.com\\stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a \\ delimiter is ignored for special schemes', href: 'http://example.net/path', newValue: 'example.com:8080\\stuff', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: '\\ is not a delimiter for non-special schemes, but still forbidden in hosts', href: 'view-source+http://example.net/path', newValue: 'example.com\\stuff', expected: { href: 'view-source+http://example.net/path', host: 'example.net', hostname: 'example.net', port: '', }, }, { comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error', href: 'view-source+http://example.net/path', newValue: 'example.com:8080stuff2', expected: { href: 'view-source+http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error', href: 'http://example.net/path', newValue: 'example.com:8080stuff2', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error', href: 'http://example.net/path', newValue: 'example.com:8080+2', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Port numbers are 16 bit integers', href: 'http://example.net/path', newValue: 'example.com:65535', expected: { href: 'http://example.com:65535/path', host: 'example.com:65535', hostname: 'example.com', port: '65535', }, }, { comment: 'Port numbers are 16 bit integers, overflowing is an error. Hostname is still set, though.', href: 'http://example.net/path', newValue: 'example.com:65536', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Broken IPv6', href: 'http://example.net/', newValue: '[google.com]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.2.3.4x]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.2.3.]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.2.]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'file://y/', newValue: 'x:123', expected: { href: 'file://y/', host: 'y', hostname: 'y', port: '', }, }, { href: 'file://y/', newValue: 'loc%41lhost', expected: { href: 'file:///', host: '', hostname: '', port: '', }, }, { href: 'file://hi/x', newValue: '', expected: { href: 'file:///x', host: '', hostname: '', port: '', }, }, { href: 'sc://test@test/', newValue: '', expected: { href: 'sc://test@test/', host: 'test', hostname: 'test', username: 'test', }, }, { href: 'sc://test:12/', newValue: '', expected: { href: 'sc://test:12/', host: 'test:12', hostname: 'test', port: '12', }, }, ], hostname: [ { comment: 'Non-special scheme', href: 'sc://x/', newValue: '\u0000', expected: { href: 'sc://x/', host: 'x', hostname: 'x', }, }, { href: 'sc://x/', newValue: '\u0009', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '\u000A', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '\u000D', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: ' ', expected: { href: 'sc://x/', host: 'x', hostname: 'x', }, }, { href: 'sc://x/', newValue: '#', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '/', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '?', expected: { href: 'sc:///', host: '', hostname: '', }, }, { href: 'sc://x/', newValue: '@', expected: { href: 'sc://x/', host: 'x', hostname: 'x', }, }, { comment: 'Cannot-be-a-base means no host', href: 'mailto:me@example.net', newValue: 'example.com', expected: { href: 'mailto:me@example.net', host: '', }, }, { comment: 'Cannot-be-a-base means no password', href: 'data:text/plain,Stuff', newValue: 'example.net', expected: { href: 'data:text/plain,Stuff', host: '', }, }, { href: 'http://example.net:8080', newValue: 'example.com', expected: { href: 'http://example.com:8080/', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'The empty host is not valid for special schemes', href: 'http://example.net', newValue: '', expected: { href: 'http://example.net/', host: 'example.net', }, }, { comment: 'The empty host is OK for non-special schemes', href: 'view-source+http://example.net/foo', newValue: '', expected: { href: 'view-source+http:///foo', host: '', }, }, { comment: 'Path-only URLs can gain a host', href: 'a:/foo', newValue: 'example.net', expected: { href: 'a://example.net/foo', host: 'example.net', }, }, { comment: 'IPv4 address syntax is normalized', href: 'http://example.net:8080', newValue: '0x7F000001', expected: { href: 'http://127.0.0.1:8080/', host: '127.0.0.1:8080', hostname: '127.0.0.1', port: '8080', }, }, { comment: 'IPv6 address syntax is normalized', href: 'http://example.net', newValue: '[::0:01]', expected: { href: 'http://[::1]/', host: '[::1]', hostname: '[::1]', port: '', }, }, { comment: 'Stuff after a : delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com:8080', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a : delimiter is ignored', href: 'http://example.net:8080/path', newValue: 'example.com:', expected: { href: 'http://example.com:8080/path', host: 'example.com:8080', hostname: 'example.com', port: '8080', }, }, { comment: 'Stuff after a / delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com/stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a ? delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com?stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a # delimiter is ignored', href: 'http://example.net/path', newValue: 'example.com#stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: 'Stuff after a \\ delimiter is ignored for special schemes', href: 'http://example.net/path', newValue: 'example.com\\stuff', expected: { href: 'http://example.com/path', host: 'example.com', hostname: 'example.com', port: '', }, }, { comment: '\\ is not a delimiter for non-special schemes, but still forbidden in hosts', href: 'view-source+http://example.net/path', newValue: 'example.com\\stuff', expected: { href: 'view-source+http://example.net/path', host: 'example.net', hostname: 'example.net', port: '', }, }, { comment: 'Broken IPv6', href: 'http://example.net/', newValue: '[google.com]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.2.3.4x]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.2.3.]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.2.]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'http://example.net/', newValue: '[::1.]', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', }, }, { href: 'file://y/', newValue: 'x:123', expected: { href: 'file://y/', host: 'y', hostname: 'y', port: '', }, }, { href: 'file://y/', newValue: 'loc%41lhost', expected: { href: 'file:///', host: '', hostname: '', port: '', }, }, { href: 'file://hi/x', newValue: '', expected: { href: 'file:///x', host: '', hostname: '', port: '', }, }, { href: 'sc://test@test/', newValue: '', expected: { href: 'sc://test@test/', host: 'test', hostname: 'test', username: 'test', }, }, { href: 'sc://test:12/', newValue: '', expected: { href: 'sc://test:12/', host: 'test:12', hostname: 'test', port: '12', }, }, ], port: [ { href: 'http://example.net', newValue: '8080', expected: { href: 'http://example.net:8080/', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Port number is removed if empty is the new value', href: 'http://example.net:8080', newValue: '', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', port: '', }, }, { comment: 'Default port number is removed', href: 'http://example.net:8080', newValue: '80', expected: { href: 'http://example.net/', host: 'example.net', hostname: 'example.net', port: '', }, }, { comment: 'Default port number is removed', href: 'https://example.net:4433', newValue: '443', expected: { href: 'https://example.net/', host: 'example.net', hostname: 'example.net', port: '', }, }, { comment: 'Default port number is only removed for the relevant scheme', href: 'https://example.net', newValue: '80', expected: { href: 'https://example.net:80/', host: 'example.net:80', hostname: 'example.net', port: '80', }, }, { comment: 'Stuff after a / delimiter is ignored', href: 'http://example.net/path', newValue: '8080/stuff', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Stuff after a ? delimiter is ignored', href: 'http://example.net/path', newValue: '8080?stuff', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Stuff after a # delimiter is ignored', href: 'http://example.net/path', newValue: '8080#stuff', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Stuff after a \\ delimiter is ignored for special schemes', href: 'http://example.net/path', newValue: '8080\\stuff', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error', href: 'view-source+http://example.net/path', newValue: '8080stuff2', expected: { href: 'view-source+http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error', href: 'http://example.net/path', newValue: '8080stuff2', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Anything other than ASCII digit stops the port parser in a setter but is not an error', href: 'http://example.net/path', newValue: '8080+2', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Port numbers are 16 bit integers', href: 'http://example.net/path', newValue: '65535', expected: { href: 'http://example.net:65535/path', host: 'example.net:65535', hostname: 'example.net', port: '65535', }, }, { comment: 'Port numbers are 16 bit integers, overflowing is an error', href: 'http://example.net:8080/path', newValue: '65536', expected: { href: 'http://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { comment: 'Port numbers are 16 bit integers, overflowing is an error', href: 'non-special://example.net:8080/path', newValue: '65536', expected: { href: 'non-special://example.net:8080/path', host: 'example.net:8080', hostname: 'example.net', port: '8080', }, }, { href: 'file://test/', newValue: '12', expected: { href: 'file://test/', port: '', }, }, { href: 'file://localhost/', newValue: '12', expected: { href: 'file:///', port: '', }, }, { href: 'non-base:value', newValue: '12', expected: { href: 'non-base:value', port: '', }, }, { href: 'sc:///', newValue: '12', expected: { href: 'sc:///', port: '', }, }, { href: 'sc://x/', newValue: '12', expected: { href: 'sc://x:12/', port: '12', }, }, { href: 'javascript://x/', newValue: '12', expected: { href: 'javascript://x:12/', port: '12', }, }, ], pathname: [ { comment: 'Cannot-be-a-base don’t have a path', href: 'mailto:me@example.net', newValue: '/foo', expected: { href: 'mailto:me@example.net', pathname: 'me@example.net', }, }, { href: 'unix:/run/foo.socket?timeout=10', newValue: '/var/log/../run/bar.socket', expected: { href: 'unix:/var/run/bar.socket?timeout=10', pathname: '/var/run/bar.socket', }, }, { href: 'https://example.net#nav', newValue: 'home', expected: { href: 'https://example.net/home#nav', pathname: '/home', }, }, { href: 'https://example.net#nav', newValue: '../home', expected: { href: 'https://example.net/home#nav', pathname: '/home', }, }, { comment: "\\ is a segment delimiter for 'special' URLs", href: 'http://example.net/home?lang=fr#nav', newValue: '\\a\\%2E\\b\\%2e.\\c', expected: { href: 'http://example.net/a/c?lang=fr#nav', pathname: '/a/c', }, }, { comment: "\\ is *not* a segment delimiter for non-'special' URLs", href: 'view-source+http://example.net/home?lang=fr#nav', newValue: '\\a\\%2E\\b\\%2e.\\c', expected: { href: 'view-source+http://example.net/\\a\\%2E\\b\\%2e.\\c?lang=fr#nav', pathname: '/\\a\\%2E\\b\\%2e.\\c', }, }, { comment: 'UTF-8 percent encoding with the default encode set. Tabs and newlines are removed.', href: 'a:/', newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé", expected: { href: "a:/%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9", pathname: "/%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E%3F@AZ[\\]^_%60az%7B|%7D~%7F%C2%80%C2%81%C3%89%C3%A9", }, }, { comment: 'Bytes already percent-encoded are left as-is, including %2E outside dotted segments.', href: 'http://example.net', newValue: '%2e%2E%c3%89té', expected: { href: 'http://example.net/%2e%2E%c3%89t%C3%A9', pathname: '/%2e%2E%c3%89t%C3%A9', }, }, { comment: '? needs to be encoded', href: 'http://example.net', newValue: '?', expected: { href: 'http://example.net/%3F', pathname: '/%3F', }, }, { comment: '# needs to be encoded', href: 'http://example.net', newValue: '#', expected: { href: 'http://example.net/%23', pathname: '/%23', }, }, { comment: '? needs to be encoded, non-special scheme', href: 'sc://example.net', newValue: '?', expected: { href: 'sc://example.net/%3F', pathname: '/%3F', }, }, { comment: '# needs to be encoded, non-special scheme', href: 'sc://example.net', newValue: '#', expected: { href: 'sc://example.net/%23', pathname: '/%23', }, }, { comment: 'File URLs and (back)slashes', href: 'file://monkey/', newValue: '\\\\', expected: { href: 'file://monkey/', pathname: '/', }, }, { comment: 'File URLs and (back)slashes', href: 'file:///unicorn', newValue: '//\\/', expected: { href: 'file:///', pathname: '/', }, }, { comment: 'File URLs and (back)slashes', href: 'file:///unicorn', newValue: '//monkey/..//', expected: { href: 'file:///', pathname: '/', }, }, ], search: [ { href: 'https://example.net#nav', newValue: 'lang=fr', expected: { href: 'https://example.net/?lang=fr#nav', search: '?lang=fr', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: 'lang=fr', expected: { href: 'https://example.net/?lang=fr#nav', search: '?lang=fr', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '?lang=fr', expected: { href: 'https://example.net/?lang=fr#nav', search: '?lang=fr', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '??lang=fr', expected: { href: 'https://example.net/??lang=fr#nav', search: '??lang=fr', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '?', expected: { href: 'https://example.net/?#nav', search: '', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '', expected: { href: 'https://example.net/#nav', search: '', }, }, { href: 'https://example.net?lang=en-US', newValue: '', expected: { href: 'https://example.net/', search: '', }, }, { href: 'https://example.net', newValue: '', expected: { href: 'https://example.net/', search: '', }, }, /* URI malformed { comment: 'UTF-8 percent encoding with the query encode set. Tabs and newlines are removed.', href: 'a:/', newValue: "\u0000\u0001\t\n\r\u001f !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007f\u0080\u0081Éé", expected: { href: "a:/?%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9", search: "?%00%01%1F%20!%22%23$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_`az{|}~%7F%C2%80%C2%81%C3%89%C3%A9", }, }, */ { comment: 'Bytes already percent-encoded are left as-is', href: 'http://example.net', newValue: '%c3%89té', expected: { href: 'http://example.net/?%c3%89t%C3%A9', search: '?%c3%89t%C3%A9', }, }, ], hash: [ { href: 'https://example.net', newValue: 'main', expected: { href: 'https://example.net/#main', hash: '#main', }, }, { href: 'https://example.net#nav', newValue: 'main', expected: { href: 'https://example.net/#main', hash: '#main', }, }, { href: 'https://example.net?lang=en-US', newValue: '##nav', expected: { href: 'https://example.net/?lang=en-US##nav', hash: '##nav', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '#main', expected: { href: 'https://example.net/?lang=en-US#main', hash: '#main', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '#', expected: { href: 'https://example.net/?lang=en-US#', hash: '', }, }, { href: 'https://example.net?lang=en-US#nav', newValue: '', expected: { href: 'https://example.net/?lang=en-US', hash: '', }, }, { href: 'http://example.net', newValue: '#foo bar', expected: { href: 'http://example.net/#foo%20bar', hash: '#foo%20bar', }, }, { href: 'http://example.net', newValue: '#foo"bar', expected: { href: 'http://example.net/#foo%22bar', hash: '#foo%22bar', }, }, { href: 'http://example.net', newValue: '#foo<bar', expected: { href: 'http://example.net/#foo%3Cbar', hash: '#foo%3Cbar', }, }, { href: 'http://example.net', newValue: '#foo>bar', expected: { href: 'http://example.net/#foo%3Ebar', hash: '#foo%3Ebar', }, }, { href: 'http://example.net', newValue: '#foo`bar', expected: { href: 'http://example.net/#foo%60bar', hash: '#foo%60bar', }, }, { comment: 'Simple percent-encoding; nuls, tabs, and newlines are removed', href: 'a:/', newValue: "\u0000\u0001\t\n\r\u001F !\"#$%&'()*+,-./09:;<=>?@AZ[\\]^_`az{|}~\u007F\u0080\u0081Éé", expected: { href: "a:/#%01%1F%20!%22#$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_%60az{|}~%7F%C2%80%C2%81%C3%89%C3%A9", hash: "#%01%1F%20!%22#$%&'()*+,-./09:;%3C=%3E?@AZ[\\]^_%60az{|}~%7F%C2%80%C2%81%C3%89%C3%A9", }, }, { comment: 'Bytes already percent-encoded are left as-is', href: 'http://example.net', newValue: '%c3%89té', expected: { href: 'http://example.net/#%c3%89t%C3%A9', hash: '#%c3%89t%C3%A9', }, }, { href: 'javascript:alert(1)', newValue: 'castle', expected: { href: 'javascript:alert(1)#castle', hash: '#castle', }, }, ], };
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/wpt-url-resources/toascii.js
JavaScript
// Copyright © web-platform-tests contributors // Originally from https://github.com/web-platform-tests/wpt // Available under the 3-Clause BSD License https://github.com/web-platform-tests/wpt/blob/master/LICENSE.md /* eslint-disable @stylistic/max-len -- ignore */ export default [ { comment: 'Label with hyphens in 3rd and 4th position', input: 'aa--', output: 'aa--', }, { input: 'a†--', output: 'xn--a---kp0a', }, { input: 'ab--c', output: 'ab--c', }, { comment: 'Label with leading hyphen', input: '-x', output: '-x', }, { input: '-†', output: 'xn----xhn', }, { input: '-x.xn--nxa', output: '-x.xn--nxa', }, { input: '-x.β', output: '-x.xn--nxa', }, { comment: 'Label with trailing hyphen', input: 'x-.xn--nxa', output: 'x-.xn--nxa', }, { input: 'x-.β', output: 'x-.xn--nxa', }, { comment: 'Empty labels', input: 'x..xn--nxa', output: 'x..xn--nxa', }, { input: 'x..β', output: 'x..xn--nxa', }, { comment: 'Invalid Punycode', input: 'xn--a', output: null, }, { input: 'xn--a.xn--nxa', output: null, }, { input: 'xn--a.β', output: null, }, { comment: 'Valid Punycode', input: 'xn--nxa.xn--nxa', output: 'xn--nxa.xn--nxa', }, { comment: 'Mixed', input: 'xn--nxa.β', output: 'xn--nxa.xn--nxa', }, { input: 'ab--c.xn--nxa', output: 'ab--c.xn--nxa', }, { input: 'ab--c.β', output: 'ab--c.xn--nxa', }, { comment: 'CheckJoiners is true', input: '\u200D.example', output: null, }, { input: 'xn--1ug.example', output: null, }, { comment: 'CheckBidi is true', input: 'يa', output: null, }, { input: 'xn--a-yoc', output: null, }, { comment: 'processing_option is Nontransitional_Processing', input: 'ශ්‍රී', output: 'xn--10cl1a0b660p', }, { input: 'نامه‌ای', output: 'xn--mgba3gch31f060k', }, { comment: 'U+FFFD', input: '\uFFFD.com', output: null, }, { comment: 'U+FFFD character encoded in Punycode', input: 'xn--zn7c.com', output: null, }, { comment: 'Label longer than 63 code points', input: 'x01234567890123456789012345678901234567890123456789012345678901x', output: 'x01234567890123456789012345678901234567890123456789012345678901x', }, { input: 'x01234567890123456789012345678901234567890123456789012345678901†', output: 'xn--x01234567890123456789012345678901234567890123456789012345678901-6963b', }, { input: 'x01234567890123456789012345678901234567890123456789012345678901x.xn--nxa', output: 'x01234567890123456789012345678901234567890123456789012345678901x.xn--nxa', }, { input: 'x01234567890123456789012345678901234567890123456789012345678901x.β', output: 'x01234567890123456789012345678901234567890123456789012345678901x.xn--nxa', }, { comment: 'Domain excluding TLD longer than 253 code points', input: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.x', output: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.x', }, { input: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--nxa', output: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--nxa', }, { input: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.β', output: '01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.01234567890123456789012345678901234567890123456789.0123456789012345678901234567890123456789012345678.xn--nxa', }, ];
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
tests/wpt-url-resources/urltestdata.js
JavaScript
// Copyright © web-platform-tests contributors // Originally from https://github.com/web-platform-tests/wpt // Available under the 3-Clause BSD License https://github.com/web-platform-tests/wpt/blob/master/LICENSE.md /* eslint-disable no-script-url -- required for testing */ export default [ '# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/script-tests/segments.js', { input: 'http://example\t.\norg', base: 'http://example.org/foo/bar', href: 'http://example.org/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://user:pass@foo:21/bar;par?b#c', base: 'http://example.org/foo/bar', href: 'http://user:pass@foo:21/bar;par?b#c', origin: 'http://foo:21', protocol: 'http:', username: 'user', password: 'pass', host: 'foo:21', hostname: 'foo', port: '21', pathname: '/bar;par', search: '?b', hash: '#c', }, { input: 'https://test:@test', base: 'about:blank', href: 'https://test@test/', origin: 'https://test', protocol: 'https:', username: 'test', password: '', host: 'test', hostname: 'test', port: '', pathname: '/', search: '', hash: '', }, { input: 'https://:@test', base: 'about:blank', href: 'https://test/', origin: 'https://test', protocol: 'https:', username: '', password: '', host: 'test', hostname: 'test', port: '', pathname: '/', search: '', hash: '', }, { input: 'non-special://test:@test/x', base: 'about:blank', href: 'non-special://test@test/x', origin: 'null', protocol: 'non-special:', username: 'test', password: '', host: 'test', hostname: 'test', port: '', pathname: '/x', search: '', hash: '', }, { input: 'non-special://:@test/x', base: 'about:blank', href: 'non-special://test/x', origin: 'null', protocol: 'non-special:', username: '', password: '', host: 'test', hostname: 'test', port: '', pathname: '/x', search: '', hash: '', }, { input: 'http:foo.com', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/foo.com', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/foo.com', search: '', hash: '', }, { input: '\t :foo.com \n', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:foo.com', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:foo.com', search: '', hash: '', }, { input: ' foo.com ', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/foo.com', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/foo.com', search: '', hash: '', }, { input: 'a:\t foo.com', base: 'http://example.org/foo/bar', href: 'a: foo.com', origin: 'null', protocol: 'a:', username: '', password: '', host: '', hostname: '', port: '', pathname: ' foo.com', search: '', hash: '', }, { input: 'http://f:21/ b ? d # e ', base: 'http://example.org/foo/bar', href: 'http://f:21/%20b%20?%20d%20#%20e', origin: 'http://f:21', protocol: 'http:', username: '', password: '', host: 'f:21', hostname: 'f', port: '21', pathname: '/%20b%20', search: '?%20d%20', hash: '#%20e', }, { input: 'lolscheme:x x#x x', base: 'about:blank', href: 'lolscheme:x x#x%20x', protocol: 'lolscheme:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'x x', search: '', hash: '#x%20x', }, { input: 'http://f:/c', base: 'http://example.org/foo/bar', href: 'http://f/c', origin: 'http://f', protocol: 'http:', username: '', password: '', host: 'f', hostname: 'f', port: '', pathname: '/c', search: '', hash: '', }, { input: 'http://f:0/c', base: 'http://example.org/foo/bar', href: 'http://f:0/c', origin: 'http://f:0', protocol: 'http:', username: '', password: '', host: 'f:0', hostname: 'f', port: '0', pathname: '/c', search: '', hash: '', }, { input: 'http://f:00000000000000/c', base: 'http://example.org/foo/bar', href: 'http://f:0/c', origin: 'http://f:0', protocol: 'http:', username: '', password: '', host: 'f:0', hostname: 'f', port: '0', pathname: '/c', search: '', hash: '', }, { input: 'http://f:00000000000000000000080/c', base: 'http://example.org/foo/bar', href: 'http://f/c', origin: 'http://f', protocol: 'http:', username: '', password: '', host: 'f', hostname: 'f', port: '', pathname: '/c', search: '', hash: '', }, { input: 'http://f:b/c', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://f: /c', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://f:\n/c', base: 'http://example.org/foo/bar', href: 'http://f/c', origin: 'http://f', protocol: 'http:', username: '', password: '', host: 'f', hostname: 'f', port: '', pathname: '/c', search: '', hash: '', }, { input: 'http://f:fifty-two/c', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://f:999999/c', base: 'http://example.org/foo/bar', failure: true, }, { input: 'non-special://f:999999/c', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://f: 21 / b ? d # e ', base: 'http://example.org/foo/bar', failure: true, }, { input: '', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '', }, { input: ' \t', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '', }, { input: ':foo.com/', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:foo.com/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:foo.com/', search: '', hash: '', }, { input: ':foo.com\\', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:foo.com/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:foo.com/', search: '', hash: '', }, { input: ':', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:', search: '', hash: '', }, { input: ':a', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:a', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:a', search: '', hash: '', }, { input: ':/', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:/', search: '', hash: '', }, { input: ':\\', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:/', search: '', hash: '', }, { input: ':#', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:#', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:', search: '', hash: '', }, { input: '#', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar#', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '', }, { input: '#/', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar#/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '#/', }, { input: '#\\', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar#\\', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '#\\', }, { input: '#;?', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar#;?', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '#;?', }, { input: '?', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar?', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '', }, { input: '/', base: 'http://example.org/foo/bar', href: 'http://example.org/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/', search: '', hash: '', }, { input: ':23', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:23', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:23', search: '', hash: '', }, { input: '/:23', base: 'http://example.org/foo/bar', href: 'http://example.org/:23', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/:23', search: '', hash: '', }, { input: '::', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/::', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/::', search: '', hash: '', }, { input: '::23', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/::23', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/::23', search: '', hash: '', }, { input: 'foo://', base: 'http://example.org/foo/bar', href: 'foo://', origin: 'null', protocol: 'foo:', username: '', password: '', host: '', hostname: '', port: '', pathname: '', search: '', hash: '', }, { input: 'http://a:b@c:29/d', base: 'http://example.org/foo/bar', href: 'http://a:b@c:29/d', origin: 'http://c:29', protocol: 'http:', username: 'a', password: 'b', host: 'c:29', hostname: 'c', port: '29', pathname: '/d', search: '', hash: '', }, { input: 'http::@c:29', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/:@c:29', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/:@c:29', search: '', hash: '', }, { input: 'http://&a:foo(b]c@d:2/', base: 'http://example.org/foo/bar', href: 'http://&a:foo(b%5Dc@d:2/', origin: 'http://d:2', protocol: 'http:', username: '&a', password: 'foo(b%5Dc', host: 'd:2', hostname: 'd', port: '2', pathname: '/', search: '', hash: '', }, { input: 'http://::@c@d:2', base: 'http://example.org/foo/bar', href: 'http://:%3A%40c@d:2/', origin: 'http://d:2', protocol: 'http:', username: '', password: '%3A%40c', host: 'd:2', hostname: 'd', port: '2', pathname: '/', search: '', hash: '', }, { input: 'http://foo.com:b@d/', base: 'http://example.org/foo/bar', href: 'http://foo.com:b@d/', origin: 'http://d', protocol: 'http:', username: 'foo.com', password: 'b', host: 'd', hostname: 'd', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://foo.com/\\@', base: 'http://example.org/foo/bar', href: 'http://foo.com//@', origin: 'http://foo.com', protocol: 'http:', username: '', password: '', host: 'foo.com', hostname: 'foo.com', port: '', pathname: '//@', search: '', hash: '', }, { input: 'http:\\\\foo.com\\', base: 'http://example.org/foo/bar', href: 'http://foo.com/', origin: 'http://foo.com', protocol: 'http:', username: '', password: '', host: 'foo.com', hostname: 'foo.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:\\\\a\\b:c\\d@foo.com\\', base: 'http://example.org/foo/bar', href: 'http://a/b:c/d@foo.com/', origin: 'http://a', protocol: 'http:', username: '', password: '', host: 'a', hostname: 'a', port: '', pathname: '/b:c/d@foo.com/', search: '', hash: '', }, { input: 'foo:/', base: 'http://example.org/foo/bar', href: 'foo:/', origin: 'null', protocol: 'foo:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'foo:/bar.com/', base: 'http://example.org/foo/bar', href: 'foo:/bar.com/', origin: 'null', protocol: 'foo:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/bar.com/', search: '', hash: '', }, { input: 'foo://///////', base: 'http://example.org/foo/bar', href: 'foo://///////', origin: 'null', protocol: 'foo:', username: '', password: '', host: '', hostname: '', port: '', pathname: '///////', search: '', hash: '', }, { input: 'foo://///////bar.com/', base: 'http://example.org/foo/bar', href: 'foo://///////bar.com/', origin: 'null', protocol: 'foo:', username: '', password: '', host: '', hostname: '', port: '', pathname: '///////bar.com/', search: '', hash: '', }, { input: 'foo:////://///', base: 'http://example.org/foo/bar', href: 'foo:////://///', origin: 'null', protocol: 'foo:', username: '', password: '', host: '', hostname: '', port: '', pathname: '//://///', search: '', hash: '', }, { input: 'c:/foo', base: 'http://example.org/foo/bar', href: 'c:/foo', origin: 'null', protocol: 'c:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/foo', search: '', hash: '', }, { input: '//foo/bar', base: 'http://example.org/foo/bar', href: 'http://foo/bar', origin: 'http://foo', protocol: 'http:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/bar', search: '', hash: '', }, { input: 'http://foo/path;a??e#f#g', base: 'http://example.org/foo/bar', href: 'http://foo/path;a??e#f#g', origin: 'http://foo', protocol: 'http:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/path;a', search: '??e', hash: '#f#g', }, { input: 'http://foo/abcd?efgh?ijkl', base: 'http://example.org/foo/bar', href: 'http://foo/abcd?efgh?ijkl', origin: 'http://foo', protocol: 'http:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/abcd', search: '?efgh?ijkl', hash: '', }, { input: 'http://foo/abcd#foo?bar', base: 'http://example.org/foo/bar', href: 'http://foo/abcd#foo?bar', origin: 'http://foo', protocol: 'http:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/abcd', search: '', hash: '#foo?bar', }, { input: '[61:24:74]:98', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/[61:24:74]:98', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/[61:24:74]:98', search: '', hash: '', }, { input: 'http:[61:27]/:foo', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/[61:27]/:foo', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/[61:27]/:foo', search: '', hash: '', }, { input: 'http://[1::2]:3:4', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://2001::1', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://2001::1]', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://2001::1]:80', base: 'http://example.org/foo/bar', failure: true, }, { input: 'http://[2001::1]', base: 'http://example.org/foo/bar', href: 'http://[2001::1]/', origin: 'http://[2001::1]', protocol: 'http:', username: '', password: '', host: '[2001::1]', hostname: '[2001::1]', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://[::127.0.0.1]', base: 'http://example.org/foo/bar', href: 'http://[::7f00:1]/', origin: 'http://[::7f00:1]', protocol: 'http:', username: '', password: '', host: '[::7f00:1]', hostname: '[::7f00:1]', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://[0:0:0:0:0:0:13.1.68.3]', base: 'http://example.org/foo/bar', href: 'http://[::d01:4403]/', origin: 'http://[::d01:4403]', protocol: 'http:', username: '', password: '', host: '[::d01:4403]', hostname: '[::d01:4403]', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://[2001::1]:80', base: 'http://example.org/foo/bar', href: 'http://[2001::1]/', origin: 'http://[2001::1]', protocol: 'http:', username: '', password: '', host: '[2001::1]', hostname: '[2001::1]', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:/example.com/', base: 'http://example.org/foo/bar', href: 'http://example.org/example.com/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'ftp:/example.com/', base: 'http://example.org/foo/bar', href: 'ftp://example.com/', origin: 'ftp://example.com', protocol: 'ftp:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'https:/example.com/', base: 'http://example.org/foo/bar', href: 'https://example.com/', origin: 'https://example.com', protocol: 'https:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'madeupscheme:/example.com/', base: 'http://example.org/foo/bar', href: 'madeupscheme:/example.com/', origin: 'null', protocol: 'madeupscheme:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'file:/example.com/', base: 'http://example.org/foo/bar', href: 'file:///example.com/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'file://example:1/', base: 'about:blank', failure: true, }, { input: 'file://example:test/', base: 'about:blank', failure: true, }, { input: 'file://example%/', base: 'about:blank', failure: true, }, { input: 'file://[example]/', base: 'about:blank', failure: true, }, { input: 'ftps:/example.com/', base: 'http://example.org/foo/bar', href: 'ftps:/example.com/', origin: 'null', protocol: 'ftps:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'ws:/example.com/', base: 'http://example.org/foo/bar', href: 'ws://example.com/', origin: 'ws://example.com', protocol: 'ws:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'wss:/example.com/', base: 'http://example.org/foo/bar', href: 'wss://example.com/', origin: 'wss://example.com', protocol: 'wss:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'data:/example.com/', base: 'http://example.org/foo/bar', href: 'data:/example.com/', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'javascript:/example.com/', base: 'http://example.org/foo/bar', href: 'javascript:/example.com/', origin: 'null', protocol: 'javascript:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'mailto:/example.com/', base: 'http://example.org/foo/bar', href: 'mailto:/example.com/', origin: 'null', protocol: 'mailto:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'http:example.com/', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/example.com/', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/example.com/', search: '', hash: '', }, { input: 'ftp:example.com/', base: 'http://example.org/foo/bar', href: 'ftp://example.com/', origin: 'ftp://example.com', protocol: 'ftp:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'https:example.com/', base: 'http://example.org/foo/bar', href: 'https://example.com/', origin: 'https://example.com', protocol: 'https:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'madeupscheme:example.com/', base: 'http://example.org/foo/bar', href: 'madeupscheme:example.com/', origin: 'null', protocol: 'madeupscheme:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'ftps:example.com/', base: 'http://example.org/foo/bar', href: 'ftps:example.com/', origin: 'null', protocol: 'ftps:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'ws:example.com/', base: 'http://example.org/foo/bar', href: 'ws://example.com/', origin: 'ws://example.com', protocol: 'ws:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'wss:example.com/', base: 'http://example.org/foo/bar', href: 'wss://example.com/', origin: 'wss://example.com', protocol: 'wss:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'data:example.com/', base: 'http://example.org/foo/bar', href: 'data:example.com/', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'javascript:example.com/', base: 'http://example.org/foo/bar', href: 'javascript:example.com/', origin: 'null', protocol: 'javascript:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'mailto:example.com/', base: 'http://example.org/foo/bar', href: 'mailto:example.com/', origin: 'null', protocol: 'mailto:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: '/a/b/c', base: 'http://example.org/foo/bar', href: 'http://example.org/a/b/c', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/a/b/c', search: '', hash: '', }, { input: '/a/ /c', base: 'http://example.org/foo/bar', href: 'http://example.org/a/%20/c', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/a/%20/c', search: '', hash: '', }, { input: '/a%2fc', base: 'http://example.org/foo/bar', href: 'http://example.org/a%2fc', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/a%2fc', search: '', hash: '', }, { input: '/a/%2f/c', base: 'http://example.org/foo/bar', href: 'http://example.org/a/%2f/c', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/a/%2f/c', search: '', hash: '', }, { input: '#β', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar#%CE%B2', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', hash: '#%CE%B2', }, { input: 'data:text/html,test#test', base: 'http://example.org/foo/bar', href: 'data:text/html,test#test', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'text/html,test', search: '', hash: '#test', }, { input: 'tel:1234567890', base: 'http://example.org/foo/bar', href: 'tel:1234567890', origin: 'null', protocol: 'tel:', username: '', password: '', host: '', hostname: '', port: '', pathname: '1234567890', search: '', hash: '', }, '# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/file.html', { input: 'file:c:\\foo\\bar.html', base: 'file:///tmp/mock/path', href: 'file:///c:/foo/bar.html', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/c:/foo/bar.html', search: '', hash: '', }, { input: ' File:c|////foo\\bar.html', base: 'file:///tmp/mock/path', href: 'file:///c:////foo/bar.html', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/c:////foo/bar.html', search: '', hash: '', }, { input: 'C|/foo/bar', base: 'file:///tmp/mock/path', href: 'file:///C:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/foo/bar', search: '', hash: '', }, { input: '/C|\\foo\\bar', base: 'file:///tmp/mock/path', href: 'file:///C:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/foo/bar', search: '', hash: '', }, { input: '//C|/foo/bar', base: 'file:///tmp/mock/path', href: 'file:///C:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/foo/bar', search: '', hash: '', }, { input: '//server/file', base: 'file:///tmp/mock/path', href: 'file://server/file', protocol: 'file:', username: '', password: '', host: 'server', hostname: 'server', port: '', pathname: '/file', search: '', hash: '', }, { input: '\\\\server\\file', base: 'file:///tmp/mock/path', href: 'file://server/file', protocol: 'file:', username: '', password: '', host: 'server', hostname: 'server', port: '', pathname: '/file', search: '', hash: '', }, { input: '/\\server/file', base: 'file:///tmp/mock/path', href: 'file://server/file', protocol: 'file:', username: '', password: '', host: 'server', hostname: 'server', port: '', pathname: '/file', search: '', hash: '', }, { input: 'file:///foo/bar.txt', base: 'file:///tmp/mock/path', href: 'file:///foo/bar.txt', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/foo/bar.txt', search: '', hash: '', }, { input: 'file:///home/me', base: 'file:///tmp/mock/path', href: 'file:///home/me', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/home/me', search: '', hash: '', }, { input: '//', base: 'file:///tmp/mock/path', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: '///', base: 'file:///tmp/mock/path', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: '///test', base: 'file:///tmp/mock/path', href: 'file:///test', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '', hash: '', }, { input: 'file://test', base: 'file:///tmp/mock/path', href: 'file://test/', protocol: 'file:', username: '', password: '', host: 'test', hostname: 'test', port: '', pathname: '/', search: '', hash: '', }, { input: 'file://localhost', base: 'file:///tmp/mock/path', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file://localhost/', base: 'file:///tmp/mock/path', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file://localhost/test', base: 'file:///tmp/mock/path', href: 'file:///test', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '', hash: '', }, { input: 'test', base: 'file:///tmp/mock/path', href: 'file:///tmp/mock/test', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/tmp/mock/test', search: '', hash: '', }, { input: 'file:test', base: 'file:///tmp/mock/path', href: 'file:///tmp/mock/test', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/tmp/mock/test', search: '', hash: '', }, '# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/script-tests/path.js', { input: 'http://example.com/././foo', base: 'about:blank', href: 'http://example.com/foo', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo', search: '', hash: '', }, { input: 'http://example.com/./.foo', base: 'about:blank', href: 'http://example.com/.foo', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/.foo', search: '', hash: '', }, { input: 'http://example.com/foo/.', base: 'about:blank', href: 'http://example.com/foo/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/', search: '', hash: '', }, { input: 'http://example.com/foo/./', base: 'about:blank', href: 'http://example.com/foo/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/', search: '', hash: '', }, { input: 'http://example.com/foo/bar/..', base: 'about:blank', href: 'http://example.com/foo/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/', search: '', hash: '', }, { input: 'http://example.com/foo/bar/../', base: 'about:blank', href: 'http://example.com/foo/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/', search: '', hash: '', }, { input: 'http://example.com/foo/..bar', base: 'about:blank', href: 'http://example.com/foo/..bar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/..bar', search: '', hash: '', }, { input: 'http://example.com/foo/bar/../ton', base: 'about:blank', href: 'http://example.com/foo/ton', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/ton', search: '', hash: '', }, { input: 'http://example.com/foo/bar/../ton/../../a', base: 'about:blank', href: 'http://example.com/a', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/a', search: '', hash: '', }, { input: 'http://example.com/foo/../../..', base: 'about:blank', href: 'http://example.com/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://example.com/foo/../../../ton', base: 'about:blank', href: 'http://example.com/ton', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/ton', search: '', hash: '', }, { input: 'http://example.com/foo/%2e', base: 'about:blank', href: 'http://example.com/foo/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/', search: '', hash: '', }, { input: 'http://example.com/foo/%2e%2', base: 'about:blank', href: 'http://example.com/foo/%2e%2', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/%2e%2', search: '', hash: '', }, { input: 'http://example.com/foo/%2e./%2e%2e/.%2e/%2e.bar', base: 'about:blank', href: 'http://example.com/%2e.bar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%2e.bar', search: '', hash: '', }, { input: 'http://example.com////../..', base: 'about:blank', href: 'http://example.com//', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '//', search: '', hash: '', }, { input: 'http://example.com/foo/bar//../..', base: 'about:blank', href: 'http://example.com/foo/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/', search: '', hash: '', }, { input: 'http://example.com/foo/bar//..', base: 'about:blank', href: 'http://example.com/foo/bar/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo/bar/', search: '', hash: '', }, { input: 'http://example.com/foo', base: 'about:blank', href: 'http://example.com/foo', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo', search: '', hash: '', }, { input: 'http://example.com/%20foo', base: 'about:blank', href: 'http://example.com/%20foo', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%20foo', search: '', hash: '', }, { input: 'http://example.com/foo%', base: 'about:blank', href: 'http://example.com/foo%', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%', search: '', hash: '', }, { input: 'http://example.com/foo%2', base: 'about:blank', href: 'http://example.com/foo%2', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%2', search: '', hash: '', }, { input: 'http://example.com/foo%2zbar', base: 'about:blank', href: 'http://example.com/foo%2zbar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%2zbar', search: '', hash: '', }, { input: 'http://example.com/foo%2©zbar', base: 'about:blank', href: 'http://example.com/foo%2%C3%82%C2%A9zbar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%2%C3%82%C2%A9zbar', search: '', hash: '', }, { input: 'http://example.com/foo%41%7a', base: 'about:blank', href: 'http://example.com/foo%41%7a', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%41%7a', search: '', hash: '', }, { input: 'http://example.com/foo\t\u0091%91', base: 'about:blank', href: 'http://example.com/foo%C2%91%91', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%C2%91%91', search: '', hash: '', }, { input: 'http://example.com/foo%00%51', base: 'about:blank', href: 'http://example.com/foo%00%51', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foo%00%51', search: '', hash: '', }, { input: 'http://example.com/(%28:%3A%29)', base: 'about:blank', href: 'http://example.com/(%28:%3A%29)', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/(%28:%3A%29)', search: '', hash: '', }, { input: 'http://example.com/%3A%3a%3C%3c', base: 'about:blank', href: 'http://example.com/%3A%3a%3C%3c', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%3A%3a%3C%3c', search: '', hash: '', }, { input: 'http://example.com/foo\tbar', base: 'about:blank', href: 'http://example.com/foobar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/foobar', search: '', hash: '', }, { input: 'http://example.com\\\\foo\\\\bar', base: 'about:blank', href: 'http://example.com//foo//bar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '//foo//bar', search: '', hash: '', }, { input: 'http://example.com/%7Ffp3%3Eju%3Dduvgw%3Dd', base: 'about:blank', href: 'http://example.com/%7Ffp3%3Eju%3Dduvgw%3Dd', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%7Ffp3%3Eju%3Dduvgw%3Dd', search: '', hash: '', }, { input: 'http://example.com/@asdf%40', base: 'about:blank', href: 'http://example.com/@asdf%40', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/@asdf%40', search: '', hash: '', }, { input: 'http://example.com/你好你好', base: 'about:blank', href: 'http://example.com/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%E4%BD%A0%E5%A5%BD%E4%BD%A0%E5%A5%BD', search: '', hash: '', }, { input: 'http://example.com/‥/foo', base: 'about:blank', href: 'http://example.com/%E2%80%A5/foo', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%E2%80%A5/foo', search: '', hash: '', }, { input: 'http://example.com//foo', base: 'about:blank', href: 'http://example.com/%EF%BB%BF/foo', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%EF%BB%BF/foo', search: '', hash: '', }, { input: 'http://example.com/‮/foo/‭/bar', base: 'about:blank', href: 'http://example.com/%E2%80%AE/foo/%E2%80%AD/bar', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/%E2%80%AE/foo/%E2%80%AD/bar', search: '', hash: '', }, '# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/script-tests/relative.js', { input: 'http://www.google.com/foo?bar=baz#', base: 'about:blank', href: 'http://www.google.com/foo?bar=baz#', origin: 'http://www.google.com', protocol: 'http:', username: '', password: '', host: 'www.google.com', hostname: 'www.google.com', port: '', pathname: '/foo', search: '?bar=baz', hash: '', }, { input: 'http://www.google.com/foo?bar=baz# »', base: 'about:blank', href: 'http://www.google.com/foo?bar=baz#%20%C2%BB', origin: 'http://www.google.com', protocol: 'http:', username: '', password: '', host: 'www.google.com', hostname: 'www.google.com', port: '', pathname: '/foo', search: '?bar=baz', hash: '#%20%C2%BB', }, { input: 'data:test# »', base: 'about:blank', href: 'data:test#%20%C2%BB', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'test', search: '', hash: '#%20%C2%BB', }, { input: 'http://www.google.com', base: 'about:blank', href: 'http://www.google.com/', origin: 'http://www.google.com', protocol: 'http:', username: '', password: '', host: 'www.google.com', hostname: 'www.google.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://192.0x00A80001', base: 'about:blank', href: 'http://192.168.0.1/', origin: 'http://192.168.0.1', protocol: 'http:', username: '', password: '', host: '192.168.0.1', hostname: '192.168.0.1', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://www/foo%2Ehtml', base: 'about:blank', href: 'http://www/foo%2Ehtml', origin: 'http://www', protocol: 'http:', username: '', password: '', host: 'www', hostname: 'www', port: '', pathname: '/foo%2Ehtml', search: '', hash: '', }, { input: 'http://www/foo/%2E/html', base: 'about:blank', href: 'http://www/foo/html', origin: 'http://www', protocol: 'http:', username: '', password: '', host: 'www', hostname: 'www', port: '', pathname: '/foo/html', search: '', hash: '', }, { input: 'http://user:pass@/', base: 'about:blank', failure: true, }, { input: 'http://%25DOMAIN:foobar@foodomain.com/', base: 'about:blank', href: 'http://%25DOMAIN:foobar@foodomain.com/', origin: 'http://foodomain.com', protocol: 'http:', username: '%25DOMAIN', password: 'foobar', host: 'foodomain.com', hostname: 'foodomain.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:\\\\www.google.com\\foo', base: 'about:blank', href: 'http://www.google.com/foo', origin: 'http://www.google.com', protocol: 'http:', username: '', password: '', host: 'www.google.com', hostname: 'www.google.com', port: '', pathname: '/foo', search: '', hash: '', }, { input: 'http://foo:80/', base: 'about:blank', href: 'http://foo/', origin: 'http://foo', protocol: 'http:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://foo:81/', base: 'about:blank', href: 'http://foo:81/', origin: 'http://foo:81', protocol: 'http:', username: '', password: '', host: 'foo:81', hostname: 'foo', port: '81', pathname: '/', search: '', hash: '', }, { input: 'httpa://foo:80/', base: 'about:blank', href: 'httpa://foo:80/', origin: 'null', protocol: 'httpa:', username: '', password: '', host: 'foo:80', hostname: 'foo', port: '80', pathname: '/', search: '', hash: '', }, { input: 'http://foo:-80/', base: 'about:blank', failure: true, }, { input: 'https://foo:443/', base: 'about:blank', href: 'https://foo/', origin: 'https://foo', protocol: 'https:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/', search: '', hash: '', }, { input: 'https://foo:80/', base: 'about:blank', href: 'https://foo:80/', origin: 'https://foo:80', protocol: 'https:', username: '', password: '', host: 'foo:80', hostname: 'foo', port: '80', pathname: '/', search: '', hash: '', }, { input: 'ftp://foo:21/', base: 'about:blank', href: 'ftp://foo/', origin: 'ftp://foo', protocol: 'ftp:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/', search: '', hash: '', }, { input: 'ftp://foo:80/', base: 'about:blank', href: 'ftp://foo:80/', origin: 'ftp://foo:80', protocol: 'ftp:', username: '', password: '', host: 'foo:80', hostname: 'foo', port: '80', pathname: '/', search: '', hash: '', }, { input: 'ws://foo:80/', base: 'about:blank', href: 'ws://foo/', origin: 'ws://foo', protocol: 'ws:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/', search: '', hash: '', }, { input: 'ws://foo:81/', base: 'about:blank', href: 'ws://foo:81/', origin: 'ws://foo:81', protocol: 'ws:', username: '', password: '', host: 'foo:81', hostname: 'foo', port: '81', pathname: '/', search: '', hash: '', }, { input: 'ws://foo:443/', base: 'about:blank', href: 'ws://foo:443/', origin: 'ws://foo:443', protocol: 'ws:', username: '', password: '', host: 'foo:443', hostname: 'foo', port: '443', pathname: '/', search: '', hash: '', }, { input: 'ws://foo:815/', base: 'about:blank', href: 'ws://foo:815/', origin: 'ws://foo:815', protocol: 'ws:', username: '', password: '', host: 'foo:815', hostname: 'foo', port: '815', pathname: '/', search: '', hash: '', }, { input: 'wss://foo:80/', base: 'about:blank', href: 'wss://foo:80/', origin: 'wss://foo:80', protocol: 'wss:', username: '', password: '', host: 'foo:80', hostname: 'foo', port: '80', pathname: '/', search: '', hash: '', }, { input: 'wss://foo:81/', base: 'about:blank', href: 'wss://foo:81/', origin: 'wss://foo:81', protocol: 'wss:', username: '', password: '', host: 'foo:81', hostname: 'foo', port: '81', pathname: '/', search: '', hash: '', }, { input: 'wss://foo:443/', base: 'about:blank', href: 'wss://foo/', origin: 'wss://foo', protocol: 'wss:', username: '', password: '', host: 'foo', hostname: 'foo', port: '', pathname: '/', search: '', hash: '', }, { input: 'wss://foo:815/', base: 'about:blank', href: 'wss://foo:815/', origin: 'wss://foo:815', protocol: 'wss:', username: '', password: '', host: 'foo:815', hostname: 'foo', port: '815', pathname: '/', search: '', hash: '', }, { input: 'http:/example.com/', base: 'about:blank', href: 'http://example.com/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'ftp:/example.com/', base: 'about:blank', href: 'ftp://example.com/', origin: 'ftp://example.com', protocol: 'ftp:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'https:/example.com/', base: 'about:blank', href: 'https://example.com/', origin: 'https://example.com', protocol: 'https:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'madeupscheme:/example.com/', base: 'about:blank', href: 'madeupscheme:/example.com/', origin: 'null', protocol: 'madeupscheme:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'file:/example.com/', base: 'about:blank', href: 'file:///example.com/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'ftps:/example.com/', base: 'about:blank', href: 'ftps:/example.com/', origin: 'null', protocol: 'ftps:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'ws:/example.com/', base: 'about:blank', href: 'ws://example.com/', origin: 'ws://example.com', protocol: 'ws:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'wss:/example.com/', base: 'about:blank', href: 'wss://example.com/', origin: 'wss://example.com', protocol: 'wss:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'data:/example.com/', base: 'about:blank', href: 'data:/example.com/', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'javascript:/example.com/', base: 'about:blank', href: 'javascript:/example.com/', origin: 'null', protocol: 'javascript:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'mailto:/example.com/', base: 'about:blank', href: 'mailto:/example.com/', origin: 'null', protocol: 'mailto:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/example.com/', search: '', hash: '', }, { input: 'http:example.com/', base: 'about:blank', href: 'http://example.com/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'ftp:example.com/', base: 'about:blank', href: 'ftp://example.com/', origin: 'ftp://example.com', protocol: 'ftp:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'https:example.com/', base: 'about:blank', href: 'https://example.com/', origin: 'https://example.com', protocol: 'https:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'madeupscheme:example.com/', base: 'about:blank', href: 'madeupscheme:example.com/', origin: 'null', protocol: 'madeupscheme:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'ftps:example.com/', base: 'about:blank', href: 'ftps:example.com/', origin: 'null', protocol: 'ftps:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'ws:example.com/', base: 'about:blank', href: 'ws://example.com/', origin: 'ws://example.com', protocol: 'ws:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'wss:example.com/', base: 'about:blank', href: 'wss://example.com/', origin: 'wss://example.com', protocol: 'wss:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'data:example.com/', base: 'about:blank', href: 'data:example.com/', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'javascript:example.com/', base: 'about:blank', href: 'javascript:example.com/', origin: 'null', protocol: 'javascript:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, { input: 'mailto:example.com/', base: 'about:blank', href: 'mailto:example.com/', origin: 'null', protocol: 'mailto:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'example.com/', search: '', hash: '', }, '# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/segments-userinfo-vs-host.html', { input: 'http:@www.example.com', base: 'about:blank', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:/@www.example.com', base: 'about:blank', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://@www.example.com', base: 'about:blank', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:a:b@www.example.com', base: 'about:blank', href: 'http://a:b@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: 'a', password: 'b', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:/a:b@www.example.com', base: 'about:blank', href: 'http://a:b@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: 'a', password: 'b', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://a:b@www.example.com', base: 'about:blank', href: 'http://a:b@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: 'a', password: 'b', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://@pple.com', base: 'about:blank', href: 'http://pple.com/', origin: 'http://pple.com', protocol: 'http:', username: '', password: '', host: 'pple.com', hostname: 'pple.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http::b@www.example.com', base: 'about:blank', href: 'http://:b@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: 'b', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:/:b@www.example.com', base: 'about:blank', href: 'http://:b@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: 'b', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://:b@www.example.com', base: 'about:blank', href: 'http://:b@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: 'b', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:/:@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http://user@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http:@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http:/@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http://@/www.example.com', base: 'about:blank', failure: true, }, { input: 'https:@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http:a:b@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http:/a:b@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http://a:b@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http::@/www.example.com', base: 'about:blank', failure: true, }, { input: 'http:a:@www.example.com', base: 'about:blank', href: 'http://a@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: 'a', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:/a:@www.example.com', base: 'about:blank', href: 'http://a@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: 'a', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://a:@www.example.com', base: 'about:blank', href: 'http://a@www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: 'a', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://www.@pple.com', base: 'about:blank', href: 'http://www.@pple.com/', origin: 'http://pple.com', protocol: 'http:', username: 'www.', password: '', host: 'pple.com', hostname: 'pple.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http:@:www.example.com', base: 'about:blank', failure: true, }, { input: 'http:/@:www.example.com', base: 'about:blank', failure: true, }, { input: 'http://@:www.example.com', base: 'about:blank', failure: true, }, { input: 'http://:@www.example.com', base: 'about:blank', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, '# Others', { input: '/', base: 'http://www.example.com/test', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: '/test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/test.txt', search: '', hash: '', }, { input: '.', base: 'http://www.example.com/test', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: '..', base: 'http://www.example.com/test', href: 'http://www.example.com/', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/test.txt', search: '', hash: '', }, { input: './test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/test.txt', search: '', hash: '', }, { input: '../test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/test.txt', search: '', hash: '', }, { input: '../aaa/test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/aaa/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/aaa/test.txt', search: '', hash: '', }, { input: '../../test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/test.txt', search: '', hash: '', }, { input: '中/test.txt', base: 'http://www.example.com/test', href: 'http://www.example.com/%E4%B8%AD/test.txt', origin: 'http://www.example.com', protocol: 'http:', username: '', password: '', host: 'www.example.com', hostname: 'www.example.com', port: '', pathname: '/%E4%B8%AD/test.txt', search: '', hash: '', }, { input: 'http://www.example2.com', base: 'http://www.example.com/test', href: 'http://www.example2.com/', origin: 'http://www.example2.com', protocol: 'http:', username: '', password: '', host: 'www.example2.com', hostname: 'www.example2.com', port: '', pathname: '/', search: '', hash: '', }, { input: '//www.example2.com', base: 'http://www.example.com/test', href: 'http://www.example2.com/', origin: 'http://www.example2.com', protocol: 'http:', username: '', password: '', host: 'www.example2.com', hostname: 'www.example2.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:...', base: 'http://www.example.com/test', href: 'file:///...', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/...', search: '', hash: '', }, { input: 'file:..', base: 'http://www.example.com/test', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:a', base: 'http://www.example.com/test', href: 'file:///a', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/a', search: '', hash: '', }, '# Based on http://trac.webkit.org/browser/trunk/LayoutTests/fast/url/host.html', 'Basic canonicalization, uppercase should be converted to lowercase', { input: 'http://ExAmPlE.CoM', base: 'http://other.com/', href: 'http://example.com/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://example example.com', base: 'http://other.com/', failure: true, }, { input: 'http://Goo%20 goo%7C|.com', base: 'http://other.com/', failure: true, }, { input: 'http://[]', base: 'http://other.com/', failure: true, }, { input: 'http://[:]', base: 'http://other.com/', failure: true, }, 'U+3000 is mapped to U+0020 (space) which is disallowed', { input: 'http://GOO\u00A0\u3000goo.com', base: 'http://other.com/', failure: true, }, 'Other types of space (no-break, zero-width, zero-width-no-break) are name-prepped away to nothing. U+200B, U+2060, and U+FEFF, are ignored', { input: 'http://GOO\u200B\u2060\uFEFFgoo.com', base: 'http://other.com/', href: 'http://googoo.com/', origin: 'http://googoo.com', protocol: 'http:', username: '', password: '', host: 'googoo.com', hostname: 'googoo.com', port: '', pathname: '/', search: '', hash: '', }, 'Leading and trailing C0 control or space', { input: '\u0000\u001B\u0004\u0012 http://example.com/\u001F \u000D ', base: 'about:blank', href: 'http://example.com/', origin: 'http://example.com', protocol: 'http:', username: '', password: '', host: 'example.com', hostname: 'example.com', port: '', pathname: '/', search: '', hash: '', }, 'Ideographic full stop (full-width period for Chinese, etc.) should be treated as a dot. U+3002 is mapped to U+002E (dot)', { input: 'http://www.foo。bar.com', base: 'http://other.com/', href: 'http://www.foo.bar.com/', origin: 'http://www.foo.bar.com', protocol: 'http:', username: '', password: '', host: 'www.foo.bar.com', hostname: 'www.foo.bar.com', port: '', pathname: '/', search: '', hash: '', }, 'Invalid unicode characters should fail... U+FDD0 is disallowed; %ef%b7%90 is U+FDD0', { input: 'http://\uFDD0zyx.com', base: 'http://other.com/', failure: true, }, 'This is the same as previous but escaped', { input: 'http://%ef%b7%90zyx.com', base: 'http://other.com/', failure: true, }, 'U+FFFD', { input: 'https://\uFFFD', base: 'about:blank', failure: true, }, { input: 'https://%EF%BF%BD', base: 'about:blank', failure: true, }, { input: 'https://x/\uFFFD?\uFFFD#\uFFFD', base: 'about:blank', href: 'https://x/%EF%BF%BD?%EF%BF%BD#%EF%BF%BD', origin: 'https://x', protocol: 'https:', username: '', password: '', host: 'x', hostname: 'x', port: '', pathname: '/%EF%BF%BD', search: '?%EF%BF%BD', hash: '#%EF%BF%BD', }, "Test name prepping, fullwidth input should be converted to ASCII and NOT IDN-ized. This is 'Go' in fullwidth UTF-8/UTF-16.", { input: 'http://Go.com', base: 'http://other.com/', href: 'http://go.com/', origin: 'http://go.com', protocol: 'http:', username: '', password: '', host: 'go.com', hostname: 'go.com', port: '', pathname: '/', search: '', hash: '', }, 'URL spec forbids the following. https://www.w3.org/Bugs/Public/show_bug.cgi?id=24257', { input: 'http://%41.com', base: 'http://other.com/', failure: true, }, { input: 'http://%ef%bc%85%ef%bc%94%ef%bc%91.com', base: 'http://other.com/', failure: true, }, '...%00 in fullwidth should fail (also as escaped UTF-8 input)', { input: 'http://%00.com', base: 'http://other.com/', failure: true, }, { input: 'http://%ef%bc%85%ef%bc%90%ef%bc%90.com', base: 'http://other.com/', failure: true, }, 'Basic IDN support, UTF-8 and UTF-16 input should be converted to IDN', { input: 'http://你好你好', base: 'http://other.com/', href: 'http://xn--6qqa088eba/', origin: 'http://xn--6qqa088eba', protocol: 'http:', username: '', password: '', host: 'xn--6qqa088eba', hostname: 'xn--6qqa088eba', port: '', pathname: '/', search: '', hash: '', }, { input: 'https://faß.ExAmPlE/', base: 'about:blank', href: 'https://xn--fa-hia.example/', origin: 'https://xn--fa-hia.example', protocol: 'https:', username: '', password: '', host: 'xn--fa-hia.example', hostname: 'xn--fa-hia.example', port: '', pathname: '/', search: '', hash: '', }, { input: 'sc://faß.ExAmPlE/', base: 'about:blank', href: 'sc://fa%C3%9F.ExAmPlE/', origin: 'null', protocol: 'sc:', username: '', password: '', host: 'fa%C3%9F.ExAmPlE', hostname: 'fa%C3%9F.ExAmPlE', port: '', pathname: '/', search: '', hash: '', }, 'Invalid escaped characters should fail and the percents should be escaped. https://www.w3.org/Bugs/Public/show_bug.cgi?id=24191', { input: 'http://%zz%66%a.com', base: 'http://other.com/', failure: true, }, 'If we get an invalid character that has been escaped.', { input: 'http://%25', base: 'http://other.com/', failure: true, }, { input: 'http://hello%00', base: 'http://other.com/', failure: true, }, 'Escaped numbers should be treated like IP addresses if they are.', /* { input: 'http://%30%78%63%30%2e%30%32%35%30.01', base: 'http://other.com/', href: 'http://192.168.0.1/', origin: 'http://192.168.0.1', protocol: 'http:', username: '', password: '', host: '192.168.0.1', hostname: '192.168.0.1', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://%30%78%63%30%2e%30%32%35%30.01%2e', base: 'http://other.com/', href: 'http://192.168.0.1/', origin: 'http://192.168.0.1', protocol: 'http:', username: '', password: '', host: '192.168.0.1', hostname: '192.168.0.1', port: '', pathname: '/', search: '', hash: '', }, */ { input: 'http://192.168.0.257', base: 'http://other.com/', failure: true, }, 'Invalid escaping in hosts causes failure', { input: 'http://%3g%78%63%30%2e%30%32%35%30%2E.01', base: 'http://other.com/', failure: true, }, 'A space in a host causes failure', { input: 'http://192.168.0.1 hello', base: 'http://other.com/', failure: true, }, { input: 'https://x x:12', base: 'about:blank', failure: true, }, 'Fullwidth and escaped UTF-8 fullwidth should still be treated as IP', { input: 'http://0Xc0.0250.01', base: 'http://other.com/', href: 'http://192.168.0.1/', origin: 'http://192.168.0.1', protocol: 'http:', username: '', password: '', host: '192.168.0.1', hostname: '192.168.0.1', port: '', pathname: '/', search: '', hash: '', }, 'Domains with empty labels', { input: 'http://./', base: 'about:blank', href: 'http://./', origin: 'http://.', protocol: 'http:', username: '', password: '', host: '.', hostname: '.', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://../', base: 'about:blank', href: 'http://../', origin: 'http://..', protocol: 'http:', username: '', password: '', host: '..', hostname: '..', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://0..0x300/', base: 'about:blank', href: 'http://0..0x300/', origin: 'http://0..0x300', protocol: 'http:', username: '', password: '', host: '0..0x300', hostname: '0..0x300', port: '', pathname: '/', search: '', hash: '', }, 'Broken IPv6', { input: 'http://[www.google.com]/', base: 'about:blank', failure: true, }, { input: 'http://[google.com]', base: 'http://other.com/', failure: true, }, { input: 'http://[::1.2.3.4x]', base: 'http://other.com/', failure: true, }, { input: 'http://[::1.2.3.]', base: 'http://other.com/', failure: true, }, { input: 'http://[::1.2.]', base: 'http://other.com/', failure: true, }, { input: 'http://[::1.]', base: 'http://other.com/', failure: true, }, 'Misc Unicode', { input: 'http://foo:💩@example.com/bar', base: 'http://other.com/', href: 'http://foo:%F0%9F%92%A9@example.com/bar', origin: 'http://example.com', protocol: 'http:', username: 'foo', password: '%F0%9F%92%A9', host: 'example.com', hostname: 'example.com', port: '', pathname: '/bar', search: '', hash: '', }, '# resolving a fragment against any scheme succeeds', { input: '#', base: 'test:test', href: 'test:test#', origin: 'null', protocol: 'test:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'test', search: '', hash: '', }, { input: '#x', base: 'mailto:x@x.com', href: 'mailto:x@x.com#x', origin: 'null', protocol: 'mailto:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'x@x.com', search: '', hash: '#x', }, { input: '#x', base: 'data:,', href: 'data:,#x', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: ',', search: '', hash: '#x', }, { input: '#x', base: 'about:blank', href: 'about:blank#x', origin: 'null', protocol: 'about:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'blank', search: '', hash: '#x', }, { input: '#', base: 'test:test?test', href: 'test:test?test#', origin: 'null', protocol: 'test:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'test', search: '?test', hash: '', }, '# multiple @ in authority state', { input: 'https://@test@test@example:800/', base: 'http://doesnotmatter/', href: 'https://%40test%40test@example:800/', origin: 'https://example:800', protocol: 'https:', username: '%40test%40test', password: '', host: 'example:800', hostname: 'example', port: '800', pathname: '/', search: '', hash: '', }, { input: 'https://@@@example', base: 'http://doesnotmatter/', href: 'https://%40%40@example/', origin: 'https://example', protocol: 'https:', username: '%40%40', password: '', host: 'example', hostname: 'example', port: '', pathname: '/', search: '', hash: '', }, 'non-az-09 characters', { input: 'http://`{}:`{}@h/`{}?`{}', base: 'http://doesnotmatter/', href: 'http://%60%7B%7D:%60%7B%7D@h/%60%7B%7D?`{}', origin: 'http://h', protocol: 'http:', username: '%60%7B%7D', password: '%60%7B%7D', host: 'h', hostname: 'h', port: '', pathname: '/%60%7B%7D', search: '?`{}', hash: '', }, "byte is ' and url is special", { input: "http://host/?'", base: 'about:blank', href: 'http://host/?%27', origin: 'http://host', protocol: 'http:', username: '', password: '', host: 'host', hostname: 'host', port: '', pathname: '/', search: '?%27', hash: '', }, { input: "notspecial://host/?'", base: 'about:blank', href: "notspecial://host/?'", origin: 'null', protocol: 'notspecial:', username: '', password: '', host: 'host', hostname: 'host', port: '', pathname: '/', search: "?'", hash: '', }, '# Credentials in base', { input: '/some/path', base: 'http://user@example.org/smth', href: 'http://user@example.org/some/path', origin: 'http://example.org', protocol: 'http:', username: 'user', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/some/path', search: '', hash: '', }, { input: '', base: 'http://user:pass@example.org:21/smth', href: 'http://user:pass@example.org:21/smth', origin: 'http://example.org:21', protocol: 'http:', username: 'user', password: 'pass', host: 'example.org:21', hostname: 'example.org', port: '21', pathname: '/smth', search: '', hash: '', }, { input: '/some/path', base: 'http://user:pass@example.org:21/smth', href: 'http://user:pass@example.org:21/some/path', origin: 'http://example.org:21', protocol: 'http:', username: 'user', password: 'pass', host: 'example.org:21', hostname: 'example.org', port: '21', pathname: '/some/path', search: '', hash: '', }, '# a set of tests designed by zcorpan for relative URLs with unknown schemes', { input: 'i', base: 'sc:sd', failure: true, }, { input: 'i', base: 'sc:sd/sd', failure: true, }, { input: 'i', base: 'sc:/pa/pa', href: 'sc:/pa/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pa/i', search: '', hash: '', }, { input: 'i', base: 'sc://ho/pa', href: 'sc://ho/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: 'ho', hostname: 'ho', port: '', pathname: '/i', search: '', hash: '', }, { input: 'i', base: 'sc:///pa/pa', href: 'sc:///pa/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pa/i', search: '', hash: '', }, { input: '../i', base: 'sc:sd', failure: true, }, { input: '../i', base: 'sc:sd/sd', failure: true, }, { input: '../i', base: 'sc:/pa/pa', href: 'sc:/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/i', search: '', hash: '', }, { input: '../i', base: 'sc://ho/pa', href: 'sc://ho/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: 'ho', hostname: 'ho', port: '', pathname: '/i', search: '', hash: '', }, { input: '../i', base: 'sc:///pa/pa', href: 'sc:///i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/i', search: '', hash: '', }, { input: '/i', base: 'sc:sd', failure: true, }, { input: '/i', base: 'sc:sd/sd', failure: true, }, { input: '/i', base: 'sc:/pa/pa', href: 'sc:/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/i', search: '', hash: '', }, { input: '/i', base: 'sc://ho/pa', href: 'sc://ho/i', origin: 'null', protocol: 'sc:', username: '', password: '', host: 'ho', hostname: 'ho', port: '', pathname: '/i', search: '', hash: '', }, { input: '/i', base: 'sc:///pa/pa', href: 'sc:///i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/i', search: '', hash: '', }, { input: '?i', base: 'sc:sd', failure: true, }, { input: '?i', base: 'sc:sd/sd', failure: true, }, { input: '?i', base: 'sc:/pa/pa', href: 'sc:/pa/pa?i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pa/pa', search: '?i', hash: '', }, { input: '?i', base: 'sc://ho/pa', href: 'sc://ho/pa?i', origin: 'null', protocol: 'sc:', username: '', password: '', host: 'ho', hostname: 'ho', port: '', pathname: '/pa', search: '?i', hash: '', }, { input: '?i', base: 'sc:///pa/pa', href: 'sc:///pa/pa?i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pa/pa', search: '?i', hash: '', }, { input: '#i', base: 'sc:sd', href: 'sc:sd#i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'sd', search: '', hash: '#i', }, { input: '#i', base: 'sc:sd/sd', href: 'sc:sd/sd#i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'sd/sd', search: '', hash: '#i', }, { input: '#i', base: 'sc:/pa/pa', href: 'sc:/pa/pa#i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pa/pa', search: '', hash: '#i', }, { input: '#i', base: 'sc://ho/pa', href: 'sc://ho/pa#i', origin: 'null', protocol: 'sc:', username: '', password: '', host: 'ho', hostname: 'ho', port: '', pathname: '/pa', search: '', hash: '#i', }, { input: '#i', base: 'sc:///pa/pa', href: 'sc:///pa/pa#i', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pa/pa', search: '', hash: '#i', }, '# make sure that relative URL logic works on known typically non-relative schemes too', { input: 'about:/../', base: 'about:blank', href: 'about:/', origin: 'null', protocol: 'about:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'data:/../', base: 'about:blank', href: 'data:/', origin: 'null', protocol: 'data:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'javascript:/../', base: 'about:blank', href: 'javascript:/', origin: 'null', protocol: 'javascript:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'mailto:/../', base: 'about:blank', href: 'mailto:/', origin: 'null', protocol: 'mailto:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, '# unknown schemes and their hosts', { input: 'sc://ñ.test/', base: 'about:blank', href: 'sc://%C3%B1.test/', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1.test', hostname: '%C3%B1.test', port: '', pathname: '/', search: '', hash: '', }, { input: "sc://\u001F!\"$&'()*+,-.;<=>^_`{|}~/", base: 'about:blank', href: "sc://%1F!\"$&'()*+,-.;<=>^_`{|}~/", origin: 'null', protocol: 'sc:', username: '', password: '', host: "%1F!\"$&'()*+,-.;<=>^_`{|}~", hostname: "%1F!\"$&'()*+,-.;<=>^_`{|}~", port: '', pathname: '/', search: '', hash: '', }, { input: 'sc://\u0000/', base: 'about:blank', failure: true, }, { input: 'sc:// /', base: 'about:blank', failure: true, }, /* { input: 'sc://%/', base: 'about:blank', href: 'sc://%/', protocol: 'sc:', username: '', password: '', host: '%', hostname: '%', port: '', pathname: '/', search: '', hash: '', }, */ { input: 'sc://@/', base: 'about:blank', failure: true, }, { input: 'sc://tes@s:t@/', base: 'about:blank', failure: true, }, { input: 'sc://:/', base: 'about:blank', failure: true, }, { input: 'sc://:12/', base: 'about:blank', failure: true, }, { input: 'sc://[/', base: 'about:blank', failure: true, }, { input: 'sc://\\/', base: 'about:blank', failure: true, }, { input: 'sc://]/', base: 'about:blank', failure: true, }, { input: 'x', base: 'sc://ñ', href: 'sc://%C3%B1/x', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1', hostname: '%C3%B1', port: '', pathname: '/x', search: '', hash: '', }, '# unknown schemes and backslashes', { input: 'sc:\\../', base: 'about:blank', href: 'sc:\\../', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '\\../', search: '', hash: '', }, '# unknown scheme with path looking like a password', { input: 'sc::a@example.net', base: 'about:blank', href: 'sc::a@example.net', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: ':a@example.net', search: '', hash: '', }, '# unknown scheme with bogus percent-encoding', { input: 'wow:%NBD', base: 'about:blank', href: 'wow:%NBD', origin: 'null', protocol: 'wow:', username: '', password: '', host: '', hostname: '', port: '', pathname: '%NBD', search: '', hash: '', }, { input: 'wow:%1G', base: 'about:blank', href: 'wow:%1G', origin: 'null', protocol: 'wow:', username: '', password: '', host: '', hostname: '', port: '', pathname: '%1G', search: '', hash: '', }, '# Hosts and percent-encoding', { input: 'ftp://example.com%80/', base: 'about:blank', failure: true, }, { input: 'ftp://example.com%A0/', base: 'about:blank', failure: true, }, { input: 'https://example.com%80/', base: 'about:blank', failure: true, }, { input: 'https://example.com%A0/', base: 'about:blank', failure: true, }, /* { input: 'ftp://%e2%98%83', base: 'about:blank', href: 'ftp://xn--n3h/', origin: 'ftp://xn--n3h', protocol: 'ftp:', username: '', password: '', host: 'xn--n3h', hostname: 'xn--n3h', port: '', pathname: '/', search: '', hash: '', }, { input: 'https://%e2%98%83', base: 'about:blank', href: 'https://xn--n3h/', origin: 'https://xn--n3h', protocol: 'https:', username: '', password: '', host: 'xn--n3h', hostname: 'xn--n3h', port: '', pathname: '/', search: '', hash: '', }, */ '# tests from jsdom/whatwg-url designed for code coverage', { input: 'http://127.0.0.1:10100/relative_import.html', base: 'about:blank', href: 'http://127.0.0.1:10100/relative_import.html', origin: 'http://127.0.0.1:10100', protocol: 'http:', username: '', password: '', host: '127.0.0.1:10100', hostname: '127.0.0.1', port: '10100', pathname: '/relative_import.html', search: '', hash: '', }, { input: 'http://facebook.com/?foo=%7B%22abc%22', base: 'about:blank', href: 'http://facebook.com/?foo=%7B%22abc%22', origin: 'http://facebook.com', protocol: 'http:', username: '', password: '', host: 'facebook.com', hostname: 'facebook.com', port: '', pathname: '/', search: '?foo=%7B%22abc%22', hash: '', }, { input: 'https://localhost:3000/jqueryui@1.2.3', base: 'about:blank', href: 'https://localhost:3000/jqueryui@1.2.3', origin: 'https://localhost:3000', protocol: 'https:', username: '', password: '', host: 'localhost:3000', hostname: 'localhost', port: '3000', pathname: '/jqueryui@1.2.3', search: '', hash: '', }, '# tab/LF/CR', { input: 'h\tt\nt\rp://h\to\ns\rt:9\t0\n0\r0/p\ta\nt\rh?q\tu\ne\rry#f\tr\na\rg', base: 'about:blank', href: 'http://host:9000/path?query#frag', origin: 'http://host:9000', protocol: 'http:', username: '', password: '', host: 'host:9000', hostname: 'host', port: '9000', pathname: '/path', search: '?query', hash: '#frag', }, '# Stringification of URL.searchParams', { input: '?a=b&c=d', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar?a=b&c=d', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '?a=b&c=d', searchParams: 'a=b&c=d', hash: '', }, { input: '??a=b&c=d', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar??a=b&c=d', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '??a=b&c=d', searchParams: '%3Fa=b&c=d', hash: '', }, '# Scheme only', { input: 'http:', base: 'http://example.org/foo/bar', href: 'http://example.org/foo/bar', origin: 'http://example.org', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/foo/bar', search: '', searchParams: '', hash: '', }, { input: 'http:', base: 'https://example.org/foo/bar', failure: true, }, { input: 'sc:', base: 'https://example.org/foo/bar', href: 'sc:', origin: 'null', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '', search: '', searchParams: '', hash: '', }, '# Percent encoding of fragments', { input: 'http://foo.bar/baz?qux#foo\bbar', base: 'about:blank', href: 'http://foo.bar/baz?qux#foo%08bar', origin: 'http://foo.bar', protocol: 'http:', username: '', password: '', host: 'foo.bar', hostname: 'foo.bar', port: '', pathname: '/baz', search: '?qux', searchParams: 'qux=', hash: '#foo%08bar', }, { input: 'http://foo.bar/baz?qux#foo"bar', base: 'about:blank', href: 'http://foo.bar/baz?qux#foo%22bar', origin: 'http://foo.bar', protocol: 'http:', username: '', password: '', host: 'foo.bar', hostname: 'foo.bar', port: '', pathname: '/baz', search: '?qux', searchParams: 'qux=', hash: '#foo%22bar', }, { input: 'http://foo.bar/baz?qux#foo<bar', base: 'about:blank', href: 'http://foo.bar/baz?qux#foo%3Cbar', origin: 'http://foo.bar', protocol: 'http:', username: '', password: '', host: 'foo.bar', hostname: 'foo.bar', port: '', pathname: '/baz', search: '?qux', searchParams: 'qux=', hash: '#foo%3Cbar', }, { input: 'http://foo.bar/baz?qux#foo>bar', base: 'about:blank', href: 'http://foo.bar/baz?qux#foo%3Ebar', origin: 'http://foo.bar', protocol: 'http:', username: '', password: '', host: 'foo.bar', hostname: 'foo.bar', port: '', pathname: '/baz', search: '?qux', searchParams: 'qux=', hash: '#foo%3Ebar', }, { input: 'http://foo.bar/baz?qux#foo`bar', base: 'about:blank', href: 'http://foo.bar/baz?qux#foo%60bar', origin: 'http://foo.bar', protocol: 'http:', username: '', password: '', host: 'foo.bar', hostname: 'foo.bar', port: '', pathname: '/baz', search: '?qux', searchParams: 'qux=', hash: '#foo%60bar', }, '# IPv4 parsing (via https://github.com/nodejs/node/pull/10317)', { input: 'http://192.168.257', base: 'http://other.com/', href: 'http://192.168.1.1/', origin: 'http://192.168.1.1', protocol: 'http:', username: '', password: '', host: '192.168.1.1', hostname: '192.168.1.1', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://192.168.257.com', base: 'http://other.com/', href: 'http://192.168.257.com/', origin: 'http://192.168.257.com', protocol: 'http:', username: '', password: '', host: '192.168.257.com', hostname: '192.168.257.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://256', base: 'http://other.com/', href: 'http://0.0.1.0/', origin: 'http://0.0.1.0', protocol: 'http:', username: '', password: '', host: '0.0.1.0', hostname: '0.0.1.0', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://256.com', base: 'http://other.com/', href: 'http://256.com/', origin: 'http://256.com', protocol: 'http:', username: '', password: '', host: '256.com', hostname: '256.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://999999999', base: 'http://other.com/', href: 'http://59.154.201.255/', origin: 'http://59.154.201.255', protocol: 'http:', username: '', password: '', host: '59.154.201.255', hostname: '59.154.201.255', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://999999999.com', base: 'http://other.com/', href: 'http://999999999.com/', origin: 'http://999999999.com', protocol: 'http:', username: '', password: '', host: '999999999.com', hostname: '999999999.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://10000000000', base: 'http://other.com/', failure: true, }, { input: 'http://10000000000.com', base: 'http://other.com/', href: 'http://10000000000.com/', origin: 'http://10000000000.com', protocol: 'http:', username: '', password: '', host: '10000000000.com', hostname: '10000000000.com', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://4294967295', base: 'http://other.com/', href: 'http://255.255.255.255/', origin: 'http://255.255.255.255', protocol: 'http:', username: '', password: '', host: '255.255.255.255', hostname: '255.255.255.255', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://4294967296', base: 'http://other.com/', failure: true, }, { input: 'http://0xffffffff', base: 'http://other.com/', href: 'http://255.255.255.255/', origin: 'http://255.255.255.255', protocol: 'http:', username: '', password: '', host: '255.255.255.255', hostname: '255.255.255.255', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://0xffffffff1', base: 'http://other.com/', failure: true, }, { input: 'http://256.256.256.256', base: 'http://other.com/', failure: true, }, { input: 'http://256.256.256.256.256', base: 'http://other.com/', href: 'http://256.256.256.256.256/', origin: 'http://256.256.256.256.256', protocol: 'http:', username: '', password: '', host: '256.256.256.256.256', hostname: '256.256.256.256.256', port: '', pathname: '/', search: '', hash: '', }, { input: 'https://0x.0x.0', base: 'about:blank', href: 'https://0.0.0.0/', origin: 'https://0.0.0.0', protocol: 'https:', username: '', password: '', host: '0.0.0.0', hostname: '0.0.0.0', port: '', pathname: '/', search: '', hash: '', }, 'More IPv4 parsing (via https://github.com/jsdom/whatwg-url/issues/92)', { input: 'https://0x100000000/test', base: 'about:blank', failure: true, }, { input: 'https://256.0.0.1/test', base: 'about:blank', failure: true, }, "# file URLs containing percent-encoded Windows drive letters (shouldn't work)", { input: 'file:///C%3A/', base: 'about:blank', href: 'file:///C%3A/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C%3A/', search: '', hash: '', }, { input: 'file:///C%7C/', base: 'about:blank', href: 'file:///C%7C/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C%7C/', search: '', hash: '', }, '# file URLs relative to other file URLs (via https://github.com/jsdom/whatwg-url/pull/60)', { input: 'pix/submit.gif', base: 'file:///C:/Users/Domenic/Dropbox/GitHub/tmpvar/jsdom/test/level2/html/files/anchor.html', href: 'file:///C:/Users/Domenic/Dropbox/GitHub/tmpvar/jsdom/test/level2/html/files/pix/submit.gif', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/Users/Domenic/Dropbox/GitHub/tmpvar/jsdom/test/level2/html/files/pix/submit.gif', search: '', hash: '', }, { input: '..', base: 'file:///C:/', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: '..', base: 'file:///', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, '# More file URL tests by zcorpan and annevk', { input: '/', base: 'file:///C:/a/b', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: '//d:', base: 'file:///C:/a/b', href: 'file:///d:', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/d:', search: '', hash: '', }, { input: '//d:/..', base: 'file:///C:/a/b', href: 'file:///d:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/d:/', search: '', hash: '', }, { input: '..', base: 'file:///ab:/', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: '..', base: 'file:///1:/', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: '', base: 'file:///test?test#test', href: 'file:///test?test', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '?test', hash: '', }, { input: 'file:', base: 'file:///test?test#test', href: 'file:///test?test', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '?test', hash: '', }, { input: '?x', base: 'file:///test?test#test', href: 'file:///test?x', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '?x', hash: '', }, { input: 'file:?x', base: 'file:///test?test#test', href: 'file:///test?x', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '?x', hash: '', }, { input: '#x', base: 'file:///test?test#test', href: 'file:///test?test#x', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '?test', hash: '#x', }, { input: 'file:#x', base: 'file:///test?test#test', href: 'file:///test?test#x', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test', search: '?test', hash: '#x', }, '# File URLs and many (back)slashes', { input: 'file:\\\\//', base: 'about:blank', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:\\\\\\\\', base: 'about:blank', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:\\\\\\\\?fox', base: 'about:blank', href: 'file:///?fox', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '?fox', hash: '', }, { input: 'file:\\\\\\\\#guppy', base: 'about:blank', href: 'file:///#guppy', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '#guppy', }, { input: 'file://spider///', base: 'about:blank', href: 'file://spider/', protocol: 'file:', username: '', password: '', host: 'spider', hostname: 'spider', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:\\\\localhost//', base: 'about:blank', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:///localhost//cat', base: 'about:blank', href: 'file:///localhost//cat', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/localhost//cat', search: '', hash: '', }, { input: 'file://\\/localhost//cat', base: 'about:blank', href: 'file:///localhost//cat', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/localhost//cat', search: '', hash: '', }, { input: 'file://localhost//a//../..//', base: 'about:blank', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: '/////mouse', base: 'file:///elephant', href: 'file:///mouse', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/mouse', search: '', hash: '', }, { input: '\\//pig', base: 'file://lion/', href: 'file:///pig', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pig', search: '', hash: '', }, { input: '\\/localhost//pig', base: 'file://lion/', href: 'file:///pig', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pig', search: '', hash: '', }, { input: '//localhost//pig', base: 'file://lion/', href: 'file:///pig', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/pig', search: '', hash: '', }, { input: '/..//localhost//pig', base: 'file://lion/', href: 'file://lion/localhost//pig', protocol: 'file:', username: '', password: '', host: 'lion', hostname: 'lion', port: '', pathname: '/localhost//pig', search: '', hash: '', }, { input: 'file://', base: 'file://ape/', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, '# File URLs with non-empty hosts', { input: '/rooibos', base: 'file://tea/', href: 'file://tea/rooibos', protocol: 'file:', username: '', password: '', host: 'tea', hostname: 'tea', port: '', pathname: '/rooibos', search: '', hash: '', }, { input: '/?chai', base: 'file://tea/', href: 'file://tea/?chai', protocol: 'file:', username: '', password: '', host: 'tea', hostname: 'tea', port: '', pathname: '/', search: '?chai', hash: '', }, "# Windows drive letter handling with the 'file:' base URL", { input: 'C|', base: 'file://host/dir/file', href: 'file:///C:', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:', search: '', hash: '', }, { input: 'C|#', base: 'file://host/dir/file', href: 'file:///C:#', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:', search: '', hash: '', }, { input: 'C|?', base: 'file://host/dir/file', href: 'file:///C:?', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:', search: '', hash: '', }, { input: 'C|/', base: 'file://host/dir/file', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: 'C|\n/', base: 'file://host/dir/file', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: 'C|\\', base: 'file://host/dir/file', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: 'C', base: 'file://host/dir/file', href: 'file://host/dir/C', protocol: 'file:', username: '', password: '', host: 'host', hostname: 'host', port: '', pathname: '/dir/C', search: '', hash: '', }, { input: 'C|a', base: 'file://host/dir/file', href: 'file://host/dir/C|a', protocol: 'file:', username: '', password: '', host: 'host', hostname: 'host', port: '', pathname: '/dir/C|a', search: '', hash: '', }, '# Windows drive letter quirk in the file slash state', { input: '/c:/foo/bar', base: 'file:///c:/baz/qux', href: 'file:///c:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/c:/foo/bar', search: '', hash: '', }, { input: '/c|/foo/bar', base: 'file:///c:/baz/qux', href: 'file:///c:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/c:/foo/bar', search: '', hash: '', }, { input: 'file:\\c:\\foo\\bar', base: 'file:///c:/baz/qux', href: 'file:///c:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/c:/foo/bar', search: '', hash: '', }, { input: '/c:/foo/bar', base: 'file://host/path', href: 'file:///c:/foo/bar', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/c:/foo/bar', search: '', hash: '', }, '# Windows drive letter quirk with not empty host', { input: 'file://example.net/C:/', base: 'about:blank', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: 'file://1.2.3.4/C:/', base: 'about:blank', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: 'file://[1::8]/C:/', base: 'about:blank', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, '# Windows drive letter quirk (no host)', { input: 'file:/C|/', base: 'about:blank', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, { input: 'file://C|/', base: 'about:blank', href: 'file:///C:/', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/C:/', search: '', hash: '', }, '# file URLs without base URL by Rimas Misevičius', { input: 'file:', base: 'about:blank', href: 'file:///', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: 'file:?q=v', base: 'about:blank', href: 'file:///?q=v', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '?q=v', hash: '', }, { input: 'file:#frag', base: 'about:blank', href: 'file:///#frag', protocol: 'file:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '#frag', }, '# IPv6 tests', { input: 'http://[1:0::]', base: 'http://example.net/', href: 'http://[1::]/', origin: 'http://[1::]', protocol: 'http:', username: '', password: '', host: '[1::]', hostname: '[1::]', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://[0:1:2:3:4:5:6:7:8]', base: 'http://example.net/', failure: true, }, { input: 'https://[0::0::0]', base: 'about:blank', failure: true, }, { input: 'https://[0:.0]', base: 'about:blank', failure: true, }, { input: 'https://[0:0:]', base: 'about:blank', failure: true, }, { input: 'https://[0:1:2:3:4:5:6:7.0.0.0.1]', base: 'about:blank', failure: true, }, { input: 'https://[0:1.00.0.0.0]', base: 'about:blank', failure: true, }, { input: 'https://[0:1.290.0.0.0]', base: 'about:blank', failure: true, }, { input: 'https://[0:1.23.23]', base: 'about:blank', failure: true, }, '# Empty host', { input: 'http://?', base: 'about:blank', failure: true, }, { input: 'http://#', base: 'about:blank', failure: true, }, 'Port overflow (2^32 + 81)', { input: 'http://f:4294967377/c', base: 'http://example.org/', failure: true, }, 'Port overflow (2^64 + 81)', { input: 'http://f:18446744073709551697/c', base: 'http://example.org/', failure: true, }, 'Port overflow (2^128 + 81)', { input: 'http://f:340282366920938463463374607431768211537/c', base: 'http://example.org/', failure: true, }, '# Non-special-URL path tests', { input: 'sc://ñ', base: 'about:blank', href: 'sc://%C3%B1', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1', hostname: '%C3%B1', port: '', pathname: '', search: '', hash: '', }, { input: 'sc://ñ?x', base: 'about:blank', href: 'sc://%C3%B1?x', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1', hostname: '%C3%B1', port: '', pathname: '', search: '?x', hash: '', }, { input: 'sc://ñ#x', base: 'about:blank', href: 'sc://%C3%B1#x', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1', hostname: '%C3%B1', port: '', pathname: '', search: '', hash: '#x', }, { input: '#x', base: 'sc://ñ', href: 'sc://%C3%B1#x', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1', hostname: '%C3%B1', port: '', pathname: '', search: '', hash: '#x', }, { input: '?x', base: 'sc://ñ', href: 'sc://%C3%B1?x', origin: 'null', protocol: 'sc:', username: '', password: '', host: '%C3%B1', hostname: '%C3%B1', port: '', pathname: '', search: '?x', hash: '', }, { input: 'sc://?', base: 'about:blank', href: 'sc://?', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '', search: '', hash: '', }, { input: 'sc://#', base: 'about:blank', href: 'sc://#', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '', search: '', hash: '', }, { input: '///', base: 'sc://x/', href: 'sc:///', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/', search: '', hash: '', }, { input: '////', base: 'sc://x/', href: 'sc:////', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '//', search: '', hash: '', }, { input: '////x/', base: 'sc://x/', href: 'sc:////x/', protocol: 'sc:', username: '', password: '', host: '', hostname: '', port: '', pathname: '//x/', search: '', hash: '', }, { input: 'tftp://foobar.com/someconfig;mode=netascii', base: 'about:blank', href: 'tftp://foobar.com/someconfig;mode=netascii', origin: 'null', protocol: 'tftp:', username: '', password: '', host: 'foobar.com', hostname: 'foobar.com', port: '', pathname: '/someconfig;mode=netascii', search: '', hash: '', }, { input: 'telnet://user:pass@foobar.com:23/', base: 'about:blank', href: 'telnet://user:pass@foobar.com:23/', origin: 'null', protocol: 'telnet:', username: 'user', password: 'pass', host: 'foobar.com:23', hostname: 'foobar.com', port: '23', pathname: '/', search: '', hash: '', }, { input: 'ut2004://10.10.10.10:7777/Index.ut2', base: 'about:blank', href: 'ut2004://10.10.10.10:7777/Index.ut2', origin: 'null', protocol: 'ut2004:', username: '', password: '', host: '10.10.10.10:7777', hostname: '10.10.10.10', port: '7777', pathname: '/Index.ut2', search: '', hash: '', }, { input: 'redis://foo:bar@somehost:6379/0?baz=bam&qux=baz', base: 'about:blank', href: 'redis://foo:bar@somehost:6379/0?baz=bam&qux=baz', origin: 'null', protocol: 'redis:', username: 'foo', password: 'bar', host: 'somehost:6379', hostname: 'somehost', port: '6379', pathname: '/0', search: '?baz=bam&qux=baz', hash: '', }, { input: 'rsync://foo@host:911/sup', base: 'about:blank', href: 'rsync://foo@host:911/sup', origin: 'null', protocol: 'rsync:', username: 'foo', password: '', host: 'host:911', hostname: 'host', port: '911', pathname: '/sup', search: '', hash: '', }, { input: 'git://github.com/foo/bar.git', base: 'about:blank', href: 'git://github.com/foo/bar.git', origin: 'null', protocol: 'git:', username: '', password: '', host: 'github.com', hostname: 'github.com', port: '', pathname: '/foo/bar.git', search: '', hash: '', }, { input: 'irc://myserver.com:6999/channel?passwd', base: 'about:blank', href: 'irc://myserver.com:6999/channel?passwd', origin: 'null', protocol: 'irc:', username: '', password: '', host: 'myserver.com:6999', hostname: 'myserver.com', port: '6999', pathname: '/channel', search: '?passwd', hash: '', }, { input: 'dns://fw.example.org:9999/foo.bar.org?type=TXT', base: 'about:blank', href: 'dns://fw.example.org:9999/foo.bar.org?type=TXT', origin: 'null', protocol: 'dns:', username: '', password: '', host: 'fw.example.org:9999', hostname: 'fw.example.org', port: '9999', pathname: '/foo.bar.org', search: '?type=TXT', hash: '', }, { input: 'ldap://localhost:389/ou=People,o=JNDITutorial', base: 'about:blank', href: 'ldap://localhost:389/ou=People,o=JNDITutorial', origin: 'null', protocol: 'ldap:', username: '', password: '', host: 'localhost:389', hostname: 'localhost', port: '389', pathname: '/ou=People,o=JNDITutorial', search: '', hash: '', }, { input: 'git+https://github.com/foo/bar', base: 'about:blank', href: 'git+https://github.com/foo/bar', origin: 'null', protocol: 'git+https:', username: '', password: '', host: 'github.com', hostname: 'github.com', port: '', pathname: '/foo/bar', search: '', hash: '', }, { input: 'urn:ietf:rfc:2648', base: 'about:blank', href: 'urn:ietf:rfc:2648', origin: 'null', protocol: 'urn:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'ietf:rfc:2648', search: '', hash: '', }, { input: 'tag:joe@example.org,2001:foo/bar', base: 'about:blank', href: 'tag:joe@example.org,2001:foo/bar', origin: 'null', protocol: 'tag:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'joe@example.org,2001:foo/bar', search: '', hash: '', }, '# percent encoded hosts in non-special-URLs', { input: 'non-special://%E2%80%A0/', base: 'about:blank', href: 'non-special://%E2%80%A0/', protocol: 'non-special:', username: '', password: '', host: '%E2%80%A0', hostname: '%E2%80%A0', port: '', pathname: '/', search: '', hash: '', }, { input: 'non-special://H%4fSt/path', base: 'about:blank', href: 'non-special://H%4fSt/path', protocol: 'non-special:', username: '', password: '', host: 'H%4fSt', hostname: 'H%4fSt', port: '', pathname: '/path', search: '', hash: '', }, '# IPv6 in non-special-URLs', { input: 'non-special://[1:2:0:0:5:0:0:0]/', base: 'about:blank', href: 'non-special://[1:2:0:0:5::]/', protocol: 'non-special:', username: '', password: '', host: '[1:2:0:0:5::]', hostname: '[1:2:0:0:5::]', port: '', pathname: '/', search: '', hash: '', }, { input: 'non-special://[1:2:0:0:0:0:0:3]/', base: 'about:blank', href: 'non-special://[1:2::3]/', protocol: 'non-special:', username: '', password: '', host: '[1:2::3]', hostname: '[1:2::3]', port: '', pathname: '/', search: '', hash: '', }, { input: 'non-special://[1:2::3]:80/', base: 'about:blank', href: 'non-special://[1:2::3]:80/', protocol: 'non-special:', username: '', password: '', host: '[1:2::3]:80', hostname: '[1:2::3]', port: '80', pathname: '/', search: '', hash: '', }, { input: 'non-special://[:80/', base: 'about:blank', failure: true, }, { input: 'blob:https://example.com:443/', base: 'about:blank', href: 'blob:https://example.com:443/', protocol: 'blob:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'https://example.com:443/', search: '', hash: '', }, { input: 'blob:d3958f5c-0777-0845-9dcf-2cb28783acaf', base: 'about:blank', href: 'blob:d3958f5c-0777-0845-9dcf-2cb28783acaf', protocol: 'blob:', username: '', password: '', host: '', hostname: '', port: '', pathname: 'd3958f5c-0777-0845-9dcf-2cb28783acaf', search: '', hash: '', }, 'Invalid IPv4 radix digits', { input: 'http://0177.0.0.0189', base: 'about:blank', href: 'http://0177.0.0.0189/', protocol: 'http:', username: '', password: '', host: '0177.0.0.0189', hostname: '0177.0.0.0189', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://0x7f.0.0.0x7g', base: 'about:blank', href: 'http://0x7f.0.0.0x7g/', protocol: 'http:', username: '', password: '', host: '0x7f.0.0.0x7g', hostname: '0x7f.0.0.0x7g', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://0X7F.0.0.0X7G', base: 'about:blank', href: 'http://0x7f.0.0.0x7g/', protocol: 'http:', username: '', password: '', host: '0x7f.0.0.0x7g', hostname: '0x7f.0.0.0x7g', port: '', pathname: '/', search: '', hash: '', }, 'Invalid IPv4 portion of IPv6 address', { input: 'http://[::127.0.0.0.1]', base: 'about:blank', failure: true, }, 'Uncompressed IPv6 addresses with 0', { input: 'http://[0:1:0:1:0:1:0:1]', base: 'about:blank', href: 'http://[0:1:0:1:0:1:0:1]/', protocol: 'http:', username: '', password: '', host: '[0:1:0:1:0:1:0:1]', hostname: '[0:1:0:1:0:1:0:1]', port: '', pathname: '/', search: '', hash: '', }, { input: 'http://[1:0:1:0:1:0:1:0]', base: 'about:blank', href: 'http://[1:0:1:0:1:0:1:0]/', protocol: 'http:', username: '', password: '', host: '[1:0:1:0:1:0:1:0]', hostname: '[1:0:1:0:1:0:1:0]', port: '', pathname: '/', search: '', hash: '', }, 'Percent-encoded query and fragment', { input: 'http://example.org/test?\u0022', base: 'about:blank', href: 'http://example.org/test?%22', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?%22', hash: '', }, { input: 'http://example.org/test?\u0023', base: 'about:blank', href: 'http://example.org/test?#', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '', hash: '', }, { input: 'http://example.org/test?\u003C', base: 'about:blank', href: 'http://example.org/test?%3C', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?%3C', hash: '', }, { input: 'http://example.org/test?\u003E', base: 'about:blank', href: 'http://example.org/test?%3E', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?%3E', hash: '', }, { input: 'http://example.org/test?\u2323', base: 'about:blank', href: 'http://example.org/test?%E2%8C%A3', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?%E2%8C%A3', hash: '', }, { input: 'http://example.org/test?%23%23', base: 'about:blank', href: 'http://example.org/test?%23%23', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?%23%23', hash: '', }, /* { input: 'http://example.org/test?%GH', base: 'about:blank', href: 'http://example.org/test?%GH', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?%GH', hash: '', }, */ { input: 'http://example.org/test?a#%EF', base: 'about:blank', href: 'http://example.org/test?a#%EF', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?a', hash: '#%EF', }, { input: 'http://example.org/test?a#%GH', base: 'about:blank', href: 'http://example.org/test?a#%GH', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?a', hash: '#%GH', }, 'URLs that require a non-about:blank base. (Also serve as invalid base tests.)', { input: 'a', base: 'about:blank', failure: true, }, { input: 'a/', base: 'about:blank', failure: true, }, { input: 'a//', base: 'about:blank', failure: true, }, "Bases that don't fail to parse but fail to be bases", { input: 'test-a-colon.html', base: 'a:', failure: true, }, { input: 'test-a-colon-b.html', base: 'a:b', failure: true, }, 'Other base URL tests, that must succeed', { input: 'test-a-colon-slash.html', base: 'a:/', href: 'a:/test-a-colon-slash.html', protocol: 'a:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test-a-colon-slash.html', search: '', hash: '', }, { input: 'test-a-colon-slash-slash.html', base: 'a://', href: 'a:///test-a-colon-slash-slash.html', protocol: 'a:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test-a-colon-slash-slash.html', search: '', hash: '', }, { input: 'test-a-colon-slash-b.html', base: 'a:/b', href: 'a:/test-a-colon-slash-b.html', protocol: 'a:', username: '', password: '', host: '', hostname: '', port: '', pathname: '/test-a-colon-slash-b.html', search: '', hash: '', }, { input: 'test-a-colon-slash-slash-b.html', base: 'a://b', href: 'a://b/test-a-colon-slash-slash-b.html', protocol: 'a:', username: '', password: '', host: 'b', hostname: 'b', port: '', pathname: '/test-a-colon-slash-slash-b.html', search: '', hash: '', }, 'Null code point in fragment', { input: 'http://example.org/test?a#b\u0000c', base: 'about:blank', href: 'http://example.org/test?a#bc', protocol: 'http:', username: '', password: '', host: 'example.org', hostname: 'example.org', port: '', pathname: '/test', search: '?a', hash: '#bc', }, ];
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/build-local.mjs
JavaScript
import { isExists, copyBlogPosts, copyBabelStandalone, copyCommonFiles, buildWeb, getCurrentBranch, buildAndCopyCoreJS, } from './scripts/helpers.mjs'; import { join } from 'node:path'; const BUILD_SRC_DIR = './'; async function hasDocsLocal(srcDir) { const target = join(srcDir, 'docs/web/docs'); console.log(`Checking if docs exist in "${ target }"...`); if (!await isExists(target)) { throw new Error(`Docs not found in "${ target }".`); } } try { console.time('Finished in'); const targetBranch = await getCurrentBranch(BUILD_SRC_DIR); const version = { branch: targetBranch, label: targetBranch }; await hasDocsLocal(BUILD_SRC_DIR); await buildAndCopyCoreJS(version, BUILD_SRC_DIR); await copyBabelStandalone(BUILD_SRC_DIR); await copyBlogPosts(BUILD_SRC_DIR); await copyCommonFiles(BUILD_SRC_DIR); await buildWeb(targetBranch, BUILD_SRC_DIR, true); console.timeEnd('Finished in'); } catch (error) { console.error(error); }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/build.mjs
JavaScript
import { expandVersionsConfig, getDefaultVersion } from './scripts/helpers.mjs'; import fm from 'front-matter'; import { JSDOM } from 'jsdom'; import { Marked } from 'marked'; import { gfmHeadingId, getHeadingList } from 'marked-gfm-heading-id'; import markedAlert from 'marked-alert'; import config from './config/config.mjs'; import { argv, fs } from 'zx'; const { copy, mkdir, readFile, readJson, readdir, writeFile } = fs; const branchArg = argv._.find(item => item.startsWith('branch=')); const BRANCH = branchArg ? branchArg.slice('branch='.length) : undefined; const LOCAL = argv._.includes('local'); const BASE = LOCAL && BRANCH ? '/core-js/website/dist/' : BRANCH ? `/branches/${ BRANCH }/` : '/'; const DEFAULT_VERSION = await getDefaultVersion(config.versionsFile, BRANCH); let htmlFileName = ''; let docsMenu = ''; let isBlog = false; let isDocs = false; async function getAllMdFiles(dir) { const entries = await readdir(dir, { withFileTypes: true }); const files = []; for (const entry of entries) { const fullPath = path.join(dir, entry.name); if (entry.isDirectory()) { const subFiles = await getAllMdFiles(fullPath); files.push(...subFiles); } else if (entry.isFile() && entry.name.endsWith('.md')) { files.push(fullPath); } } return files; } async function buildDocsMenu(item) { if (Object.hasOwn(item, 'children')) { let result = `<li class="collapsible"><a href="#">${ item.title }</a><ul>`; for (const child of item.children) { result += await buildDocsMenu(child); } result += '</ul></li>'; return result; } return `<li><a href="${ item.url }" class="with-docs-version" data-default-version="${ DEFAULT_VERSION }">${ item.title }</a></li>`; } const docsMenus = []; const docsMenuItems = []; async function getDocsMenuItems(version) { if (docsMenuItems[version]) return docsMenuItems[version]; echo(chalk.green(`Getting menu items from file for version: ${ version }`)); const jsonPath = BRANCH ? `${ config.docsDir }docs/menu.json` : `${ config.docsDir }${ version }/docs/menu.json`; try { const docsMenuJson = await readJson(jsonPath); docsMenuItems[version] = docsMenuJson === '' ? [] : docsMenuJson; return docsMenuItems[version]; } catch { echo(chalk.yellow(`Menu JSON file not found: ${ jsonPath }`)); return []; } } async function buildDocsMenuForVersion(version) { if (docsMenus[version]) return docsMenus[version]; echo(chalk.green(`Building docs menu for version: ${ version }`)); const menuItems = await getDocsMenuItems(version); if (!menuItems.length) return ''; let menu = '<ul><li>{versions-menu}</li>'; for (const item of menuItems) { menu += await buildDocsMenu(item); } menu += '</ul>'; docsMenus[version] = menu; return menu; } function getBundlesPath(version) { return path.join(config.bundlesPath, version.branch ?? version.tag); } async function buildVersionsMenuList(versions, currentVersion, section) { let versionsMenuHtml = '<div class="dropdown-block">'; for (const v of versions) { const activityClass = v.label === currentVersion && !v.default ? ' class="active"' : ''; const defaultBadge = v.default ? ' (default)' : ''; const versionPath = v.default ? '' : `${ v.path }/`; versionsMenuHtml += `<a href="./${ versionPath }${ section }"${ activityClass }>${ v.label }${ defaultBadge }</a>`; } versionsMenuHtml += '</div>'; return versionsMenuHtml; } async function buildVersionsMenu(versions, currentVersion, section) { const innerMenu = await buildVersionsMenuList(versions, currentVersion, section); return `<div class="dropdown versions-menu"><div class="dropdown-wrapper"><a href="#" class="current">${ currentVersion }</a>${ innerMenu }</div><div class="backdrop"></div></div>`; } let fileMetadata = {}; function metadata(markdown) { const { attributes, body } = fm(markdown); fileMetadata = {}; for (const prop of Object.keys(attributes)) { fileMetadata[prop] = attributes[prop]; } return body; } const markedInline = new Marked(); const linkRenderer = { link({ href, text }) { const htmlContent = markedInline.parseInline(text); const isExternal = /^https?:\/\//.test(href); const isAnchor = href.startsWith('#'); if (isAnchor) href = htmlFileName.replace('.html', '') + href.toLowerCase(); let html = `<a href="${ href }"`; if (isExternal) html += ' target="_blank"'; html += `>${ htmlContent }</a>`; return html; }, }; const marked = new Marked(); marked.use(markedAlert(), gfmHeadingId({ prefix: 'h-' })); marked.use({ hooks: { preprocess: metadata } }); marked.use({ renderer: linkRenderer }); const markedWithContents = new Marked(); markedWithContents.use(markedAlert(), gfmHeadingId({ prefix: 'h-' })); markedWithContents.use({ hooks: { preprocess: metadata, postprocess: buildMenus, }, renderer: linkRenderer, }); function buildMenus(html) { const headings = getHeadingList().filter(({ level }) => level > 1); let result = '<div class="wrapper">'; if (isBlog || isDocs) { result += `<div class="docs-menu sticky"><div class="container"><div class="docs-links">${ isBlog ? blogMenuCache : docsMenu }</div><div class="mobile-trigger"></div></div></div>`; } result += `<div class="content">${ html }</div>`; if (headings.length && !Object.hasOwn(fileMetadata, 'disableContentMenu')) { result += `<div class="table-of-contents sticky"><div class="container"><div class="mobile-trigger"></div><div class="toc-links"> ${ headings.map(({ id, raw, level }) => `<div class="toc-link"><a href="${ htmlFileName.replace('.html', '') }#${ id }" class="h${ level } with-docs-version scroll-to" data-hash="#${ id }" data-default-version="${ DEFAULT_VERSION }">${ raw }</a></div>`).join('\n') } </div></div></div>`; } return result; } let blogMenuCache = ''; async function buildBlogMenu() { if (blogMenuCache !== '') return blogMenuCache; const mdFiles = await getAllMdFiles(config.blogDir); mdFiles.reverse(); let index = '---\ndisableContentMenu: true\n---\n'; let menu = '<ul>'; for (const mdPath of mdFiles) { if (mdPath.endsWith('index.md')) continue; const content = await readFileContent(mdPath); const tokens = marked.lexer(content); const firstH1 = tokens.find(token => token.type === 'heading' && token.depth === 1); if (!firstH1) { echo(chalk.yellow(`H1 not found in ${ mdPath }`)); continue; } let htmlContent = await marked.parse(content); htmlContent = htmlContent.replace(/<h1>[^<]*<\/h1>/i, ''); const hrIndex = htmlContent.search(/<hr>/i); const preview = hrIndex !== -1 ? htmlContent.slice(0, hrIndex) : htmlContent; const match = mdPath.match(/(?<date>\d{4}-\d{2}-\d{2})-/); const date = match?.groups?.date ?? ''; const fileName = mdPath.replace(config.blogDir, '').replace(/\.md$/i, ''); menu += `<li><a href="./blog/${ fileName }">${ date }: ${ firstH1.text }</a></li>`; index += `## [${ firstH1.text }](./blog/${ fileName })\n\n`; if (date) index += `*${ date }*\n\n`; index += `${ preview }\n\n`; } menu += '</ul>'; blogMenuCache = menu; const blogIndexPath = path.join(config.blogDir, 'index.md'); await writeFile(blogIndexPath, index, 'utf8'); echo(chalk.green(`File created: ${ blogIndexPath }`)); return menu; } async function getVersionFromMdFile(mdPath) { const match = mdPath.match(/\/web\/(?<version>[^/]+)\/docs\//); return match?.groups?.version ?? DEFAULT_VERSION; } async function readFileContent(filePath) { const content = await readFile(filePath, 'utf8'); return content.toString(); } async function buildPlaygrounds(template, versions) { for (const version of versions) { await buildPlayground(template, version, versions); } } async function buildPlayground(template, version, versions) { const bundlesPath = getBundlesPath(version); const bundleScript = `<script nomodule src="${ bundlesPath }/${ config.bundleName }"></script>`; const bundleESModulesScript = `<script type="module" src="${ bundlesPath }/${ config.bundleNameESModules }"></script>`; const babelScript = '<script src="./babel.min.js"></script>'; const playgroundContent = await readFileContent(`${ config.srcDir }playground.html`); const versionsMenu = await buildVersionsMenu(versions, version.label, 'playground'); let playground = template.replace('{content}', playgroundContent); playground = playground.replace('{base}', BASE); playground = playground.replace('{title}', 'Playground - '); playground = playground.replace('{core-js-bundle}', bundleScript); playground = playground.replace('{core-js-bundle-esmodules}', bundleESModulesScript); playground = playground.replace('{babel-script}', babelScript); const playgroundWithVersion = playground.replace('{versions-menu}', versionsMenu); const playgroundFilePath = path.join(config.resultDir, version.path, 'playground.html'); if (version.default) { const defaultVersionsMenu = await buildVersionsMenu(versions, version.label, 'playground'); const defaultVersionPlayground = playground.replace('{versions-menu}', defaultVersionsMenu); const defaultPlaygroundPath = path.join(config.resultDir, 'playground.html'); await writeFile(defaultPlaygroundPath, defaultVersionPlayground, 'utf8'); echo(chalk.green(`File created: ${ defaultPlaygroundPath }`)); } else { await mkdir(path.dirname(playgroundFilePath), { recursive: true }); await writeFile(playgroundFilePath, playgroundWithVersion, 'utf8'); echo(chalk.green(`File created: ${ playgroundFilePath }`)); } } async function createDocsIndexes(versions) { if (BRANCH) versions = [{ path: '' }]; for (const version of versions) { if (version.default && versions.length > 1) continue; const versionPath = version.path; const menuItems = await getDocsMenuItems(versionPath); if (!menuItems.length) continue; const firstDocPath = path.join(config.resultDir, `${ menuItems[0].url }.html`.replace(`{docs-version}${ BRANCH ? '/' : '' }`, versionPath)); const indexFilePath = path.join(config.resultDir, `${ versionPath }/docs/`, 'index.html'); await copy(firstDocPath, indexFilePath); echo(chalk.green(`File created: ${ indexFilePath }`)); } } async function getVersions() { if (BRANCH) { return [{ branch: BRANCH, default: true, label: BRANCH, path: BRANCH, }]; } const versions = await readJson(config.versionsFile); echo(chalk.green('Got versions from file')); return expandVersionsConfig(versions); } function getTitle(content) { const match = /^# (?<title>.+)$/m.exec(content); return match?.groups?.title ? `${ match.groups.title } - ` : ''; } async function build() { const template = await readFileContent(config.templatePath); await buildBlogMenu(); const mdFiles = await getAllMdFiles(config.docsDir); const versions = await getVersions(); const [defaultVersion] = versions; const bundlesPath = getBundlesPath(defaultVersion); const bundleScript = `<script nomodule src="${ bundlesPath }/${ config.bundleName }"></script>`; const bundleESModulesScript = `<script type="module" src="${ bundlesPath }/${ config.bundleNameESModules }"></script>`; let currentVersion = ''; let versionsMenu = ''; let isChangelog; for (let i = 0; i < mdFiles.length; i++) { const mdPath = mdFiles[i]; const content = await readFileContent(mdPath); isDocs = mdPath.includes('/docs'); isChangelog = mdPath.includes('/changelog'); isBlog = mdPath.includes('/blog'); const title = getTitle(content); const versionFromMdFile = await getVersionFromMdFile(mdPath); if (currentVersion !== versionFromMdFile) { currentVersion = versionFromMdFile; docsMenu = await buildDocsMenuForVersion(currentVersion); versionsMenu = await buildVersionsMenu(versions, currentVersion, 'docs/'); } htmlFileName = mdPath.replace(config.docsDir, '').replace(/\.md$/i, '.html'); const htmlFilePath = path.join(config.resultDir, htmlFileName); const htmlContent = isDocs || isBlog || isChangelog ? markedWithContents.parse(content) : marked.parse(content); let resultHtml = template.replace('{content}', htmlContent.replaceAll('$', '&#36;')); resultHtml = resultHtml.replace('{title}', title); resultHtml = resultHtml.replace('{base}', BASE); resultHtml = resultHtml.replace('{core-js-bundle}', bundleScript); resultHtml = resultHtml.replace('{core-js-bundle-esmodules}', bundleESModulesScript); resultHtml = resultHtml.replaceAll('{versions-menu}', versionsMenu); resultHtml = resultHtml.replaceAll('{current-version}', currentVersion); if (isDocs || isBlog || isChangelog) { const resultDOM = new JSDOM(resultHtml); const { document } = resultDOM.window; document.querySelectorAll('h2[id], h3[id], h4[id], h5[id], h6[id]').forEach(heading => { const newHeading = heading.cloneNode(true); const anchor = document.createElement('a'); anchor.className = 'anchor'; anchor.href = `${ htmlFileName.replace('.html', '') }#${ newHeading.id }`; anchor.innerHTML = '<svg viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>'; newHeading.append(anchor); newHeading.classList.add('with-anchor'); resultHtml = resultHtml.split(heading.outerHTML).join(newHeading.outerHTML); }); } resultHtml = resultHtml.replaceAll('{docs-version}', currentVersion); await mkdir(path.dirname(htmlFilePath), { recursive: true }); await writeFile(htmlFilePath, resultHtml, 'utf8'); echo(chalk.green(`File created: ${ htmlFilePath }`)); } await buildPlaygrounds(template, versions); await createDocsIndexes(versions); } await build().catch(console.error);
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/clean.mjs
JavaScript
await fs.rm('website/dist/', { force: true, recursive: true }); echo(chalk.green('Old copies removed'));
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/config/config.mjs
JavaScript
export default { docsDir: 'docs/web/', blogDir: 'docs/web/blog/', resultDir: 'website/dist/', templatesDir: 'website/templates/', templatePath: 'website/templates/index.html', srcDir: 'website/src/', versionsFile: 'website/config/versions.json', bundlesPath: './bundles', bundleName: 'core-js-bundle.js', bundleNameESModules: 'core-js-bundle-esmodules.js', };
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/copy.mjs
JavaScript
const { copy } = fs; await copy('website/templates/assets', 'website/dist/assets'); await copy('website/templates/bundles', 'website/dist/bundles'); await copy('website/templates/babel.min.js', 'website/dist/babel.min.js'); echo(chalk.green('Assets copied'));
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/index.mjs
JavaScript
await import('./clean.mjs'); await $`npm run build --prefix website`; await import('./build.mjs'); await import('./copy.mjs');
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/scripts/helpers.mjs
JavaScript
/* eslint-disable no-console -- needed for logging */ import childProcess from 'node:child_process'; import { constants } from 'node:fs'; import { cp, access, readdir, readFile } from 'node:fs/promises'; import { join } from 'node:path'; import { promisify } from 'node:util'; const exec = promisify(childProcess.exec); const BABEL_PATH = 'website/node_modules/@babel/standalone/babel.min.js'; export async function isExists(target) { try { await access(target, constants.F_OK); return true; } catch { return false; } } export async function hasDocs(version, execDir) { const target = version.branch ? `origin/${ version.branch }` : version.tag; console.log(`Checking if docs exist in "${ target }"...`); try { await exec(`git ls-tree -r --name-only ${ target } | grep "docs/web/docs/"`, { cwd: execDir }); } catch { throw new Error(`Docs not found in "${ target }".`); } } export async function installDependencies(execDir) { console.log('Installing dependencies...'); console.time('Installed dependencies'); const nodeModulesPath = join(execDir, 'node_modules'); if (!await isExists(nodeModulesPath)) { await exec('npm ci', { cwd: execDir }); } console.timeEnd('Installed dependencies'); } export async function copyBabelStandalone(srcDir) { console.log('Copying Babel standalone...'); await installDependencies(`${ srcDir }website`); console.time('Copied Babel standalone'); const babelPath = join(srcDir, BABEL_PATH); const destPath = join(srcDir, 'website/src/public/babel.min.js'); await cp(babelPath, destPath); console.timeEnd('Copied Babel standalone'); } export async function copyBlogPosts(srcDir) { console.log('Copying blog posts...'); console.time('Copied blog posts'); const fromDir = join(srcDir, 'docs/'); const toDir = join(srcDir, 'docs/web/blog/'); const entries = await readdir(fromDir, { withFileTypes: true }); for (const entry of entries) { if (entry.isFile()) { const srcFile = join(fromDir, entry.name); const destFile = join(toDir, entry.name); await cp(srcFile, destFile); } } console.timeEnd('Copied blog posts'); } export async function copyCommonFiles(srcDir) { console.log('Copying common files...'); console.time('Copied common files'); const toDir = join(srcDir, 'docs/web/'); await cp(`${ srcDir }CHANGELOG.md`, `${ toDir }changelog.md`); await cp(`${ srcDir }CONTRIBUTING.md`, `${ toDir }contributing.md`); await cp(`${ srcDir }SECURITY.md`, `${ toDir }security.md`); console.timeEnd('Copied common files'); } export async function buildAndCopyCoreJS(version, srcDir, cacheDir = null, checkout = false) { async function bundlePackage(esModules) { await exec(`npm run bundle-package${ esModules ? ' esmodules' : '' }`, { cwd: srcDir }); const bundleName = `core-js-bundle${ esModules ? '-esmodules' : '' }.js`; const srcPath = join(srcDir, 'packages/core-js-bundle/minified.js'); const destPath = join(srcDir, 'website/src/public/bundles/', target, bundleName); await cp(srcPath, destPath); if (cacheDir !== null) { const cachePath = join(cacheDir, target, bundleName); await cp(srcPath, cachePath); } } const target = version.branch ?? version.tag; console.log(`Building and copying core-js for ${ target }`); const targetBundlePath = join(cacheDir ?? '', target); if (cacheDir !== null && await isExists(targetBundlePath)) { console.time('Core JS bundles copied'); const bundlePath = join(targetBundlePath, 'core-js-bundle.js'); const destBundlePath = join(srcDir, 'website/src/public/bundles/', target, 'core-js-bundle.js'); await cp(bundlePath, destBundlePath); const esmodulesBundlePath = join(targetBundlePath, 'core-js-bundle-esmodules.js'); const esmodulesDestBundlePath = join(srcDir, 'website/src/public/bundles/', target, 'core-js-bundle-esmodules.js'); await cp(esmodulesBundlePath, esmodulesDestBundlePath); console.timeEnd('Core JS bundles copied'); return; } console.time('Core JS bundles built'); if (checkout) { await checkoutVersion(version, srcDir); } await installDependencies(srcDir); await bundlePackage(false); await bundlePackage(true); console.timeEnd('Core JS bundles built'); } export async function checkoutVersion(version, execDir) { if (version.branch) { await exec(`git checkout origin/${ version.branch }`, { cwd: execDir }); } else { await exec(`git checkout ${ version.tag }`, { cwd: execDir }); } } export async function buildWeb(branch, execDir, local = false) { console.log('Building web...'); console.time('Built web'); let command = 'npm run build-website'; if (branch) command += ` branch=${ branch }`; if (local) command += ' local'; const stdout = await exec(command, { cwd: execDir }); console.timeEnd('Built web'); return stdout; } export async function getCurrentBranch(execDir) { console.log('Getting current branch...'); console.time('Got current branch'); const { stdout } = await exec('git rev-parse --abbrev-ref HEAD', { cwd: execDir }); console.timeEnd('Got current branch'); return stdout.trim(); } export async function getDefaultVersion(versionFile, defaultVersion = null) { if (defaultVersion) return defaultVersion; const versions = await readJSON(versionFile); return versions.find(v => v.default)?.label; } export async function readJSON(filePath) { const buffer = await readFile(filePath, 'utf8'); return JSON.parse(buffer); } export function expandVersionsConfig(config) { let defaultIndex = null; const $config = config.map(({ label, branch, path, tag, default: $default }, index) => { if ($default) { if (defaultIndex !== null) throw new Error('Duplicate default'); defaultIndex = index; } return { branch, default: false, label, path: path ?? label, tag, }; }); if (defaultIndex === null) throw new Error('Missed default'); return [{ ...$config[defaultIndex], default: true }, ...$config]; }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/scripts/runner.mjs
JavaScript
/* eslint-disable no-console -- needed for logging */ import { hasDocs, copyBlogPosts, copyBabelStandalone, copyCommonFiles, buildWeb, getDefaultVersion, readJSON, buildAndCopyCoreJS, expandVersionsConfig, } from './helpers.mjs'; import childProcess from 'node:child_process'; import { cp, readdir, readlink } from 'node:fs/promises'; import { promisify } from 'node:util'; import { resolve, join } from 'node:path'; const exec = promisify(childProcess.exec); const SRC_DIR = 'core-js'; const BUILDS_ROOT_DIR = 'builds'; const BUILD_RESULT_DIR = 'result'; const BUNDLES_DIR = 'bundles'; const REPO = 'https://github.com/zloirock/core-js.git'; const BUILDER_BRANCH = 'master'; const args = process.argv; const lastArg = args.at(-1); const BRANCH = lastArg.startsWith('branch=') ? lastArg.slice('branch='.length) : undefined; const BUILD_ID = new Date().toISOString().replaceAll(/\D/g, '-') + Math.random().toString(36).slice(2, 8); const BUILD_DIR = `${ BUILDS_ROOT_DIR }/${ BUILD_ID }/`; const BUILD_SRC_DIR = `${ BUILD_DIR }${ SRC_DIR }/`; const BUILD_DOCS_DIR = `${ BUILD_DIR }builder/`; const SITE_FILES_DIR = `${ BUILD_SRC_DIR }/website/dist/`; const VERSIONS_FILE = `${ BUILD_SRC_DIR }website/config/versions.json`; async function copyWeb() { console.log('Copying web...'); console.time('Copied web'); const toDir = `${ BUILD_DIR }${ BUILD_RESULT_DIR }/`; await cp(SITE_FILES_DIR, toDir, { recursive: true }); console.timeEnd('Copied web'); } async function createBuildDir() { console.log(`Creating build directory "${ BUILD_DIR }"`); console.time(`Created build directory ${ BUILD_DIR }`); await exec(`mkdir -p ${ BUILD_DIR }`); await exec(`mkdir -p ${ BUILD_DOCS_DIR }`); console.timeEnd(`Created build directory ${ BUILD_DIR }`); } async function installDependencies(dir = BUILD_SRC_DIR) { console.log('Installing dependencies...'); console.time('Installed dependencies'); await exec('npm ci', { cwd: dir }); console.timeEnd('Installed dependencies'); } async function cloneRepo() { console.log('Cloning core-js repository...'); console.time('Cloned core-js repository'); await exec(`git clone ${ REPO } ${ SRC_DIR }`, { cwd: BUILD_DIR }); console.timeEnd('Cloned core-js repository'); } async function switchToLatestBuild() { console.log('Switching to the latest build...'); console.time('Switched to the latest build'); const absoluteBuildPath = resolve(`${ BUILD_DIR }${ BUILD_RESULT_DIR }`); const absoluteLatestPath = resolve('./latest'); console.log(absoluteBuildPath, absoluteLatestPath); await exec('rm -f ./latest'); await exec(`ln -sf ${ absoluteBuildPath } ${ absoluteLatestPath }`); console.timeEnd('Switched to the latest build'); } async function clearBuildDir() { console.log(`Clearing build directory "${ BUILD_SRC_DIR }"`); console.time(`Cleared build directories ${ BUILD_SRC_DIR } and ${ BUILD_DOCS_DIR }`); await exec(`rm -rf ${ BUILD_SRC_DIR }`); await exec(`rm -rf ${ BUILD_DOCS_DIR }`); console.timeEnd(`Cleared build directories ${ BUILD_SRC_DIR } and ${ BUILD_DOCS_DIR }`); } async function copyDocs(from, to, recursive = true) { console.log(`Copying docs from "${ from }" to "${ to }"`); console.time(`Copied docs from "${ from }" to "${ to }"`); await cp(from, to, { recursive }); console.timeEnd(`Copied docs from "${ from }" to "${ to }"`); } async function copyDocsToBuilder(version) { const target = version.branch ?? version.tag; console.log(`Copying docs to builder for "${ target }"`); console.time(`Copied docs to builder for "${ target }"`); await checkoutVersion(version); const fromDir = `${ BUILD_SRC_DIR }docs/web/docs/`; const toDir = `${ BUILD_DOCS_DIR }${ version.path ?? version.label }/docs/`; await copyDocs(fromDir, toDir); console.timeEnd(`Copied docs to builder for "${ target }"`); } async function copyBuilderDocs() { console.log('Copying builder docs...'); console.time('Copied builder docs'); const fromDir = `${ BUILD_DOCS_DIR }`; const toDir = `${ BUILD_SRC_DIR }docs/web/`; await copyDocs(fromDir, toDir); console.timeEnd('Copied builder docs'); } async function prepareBuilder(targetBranch) { console.log('Preparing builder...'); console.time('Prepared builder'); await exec(`git checkout origin/${ targetBranch }`, { cwd: BUILD_SRC_DIR }); await installDependencies(); if (!BRANCH) await exec(`rm -rf ${ BUILD_SRC_DIR }docs/web/docs/`); console.timeEnd('Prepared builder'); } async function switchBranchToLatestBuild(name) { console.log(`Switching branch "${ name }" to the latest build...`); console.time(`Switched branch "${ name }" to the latest build`); const absoluteBuildPath = resolve(`${ BUILD_DIR }${ BUILD_RESULT_DIR }`); const absoluteLatestPath = resolve(`./branches/${ name }`); await exec(`rm -f ./branches/${ name }`); await exec(`ln -sf ${ absoluteBuildPath } ${ absoluteLatestPath }`); console.timeEnd(`Switched branch "${ name }" to the latest build`); } async function checkoutVersion(version) { if (version.branch) { await exec(`git checkout origin/${ version.branch }`, { cwd: BUILD_SRC_DIR }); } else { await exec(`git checkout ${ version.tag }`, { cwd: BUILD_SRC_DIR }); } } async function getExcludedBuilds() { const branchBuilds = await readdir('./branches/'); const excluded = new Set(); for (const name of branchBuilds) { const link = await readlink(`./branches/${ name }`); if (!link) continue; const parts = link.split('/'); const id = parts.at(-2); excluded.add(id); } const latestBuildLink = await readlink('./latest'); if (latestBuildLink) { const parts = latestBuildLink.split('/'); const id = parts.at(-2); excluded.add(id); } return Array.from(excluded); } async function clearOldBuilds() { console.log('Clearing old builds...'); console.time('Cleared old builds'); const excluded = await getExcludedBuilds(); const builds = await readdir(BUILDS_ROOT_DIR); for (const build of builds) { if (!excluded.includes(build)) { await exec(`rm -rf ${ join('./', BUILDS_ROOT_DIR, '/', build) }`); console.log(`Build removed: "${ join('./', BUILDS_ROOT_DIR, '/', build) }"`); } } console.timeEnd('Cleared old builds'); } async function createLastDocsLink() { console.log('Creating last docs link...'); console.time('Created last docs link'); const defaultVersion = await getDefaultVersion(VERSIONS_FILE); const absoluteBuildPath = resolve(`${ BUILD_DIR }${ BUILD_RESULT_DIR }/${ defaultVersion }/docs/`); const absoluteLastDocsPath = resolve(`${ BUILD_DIR }${ BUILD_RESULT_DIR }/docs/`); await exec(`ln -s ${ absoluteBuildPath } ${ absoluteLastDocsPath }`); console.timeEnd('Created last docs link'); } async function getVersions(targetBranch) { console.log('Getting versions...'); console.time('Got versions'); await exec(`git checkout origin/${ targetBranch }`, { cwd: BUILD_SRC_DIR }); const versions = await readJSON(VERSIONS_FILE); console.timeEnd('Got versions'); return expandVersionsConfig(versions); } try { console.time('Finished in'); await createBuildDir(); await cloneRepo(); const targetBranch = BRANCH || BUILDER_BRANCH; if (!BRANCH) { const versions = await getVersions(targetBranch); for (const version of versions) { if (version.default) continue; await copyDocsToBuilder(version); await buildAndCopyCoreJS(version, BUILD_SRC_DIR, BUNDLES_DIR, true); } } else { const version = { branch: targetBranch, label: targetBranch }; await hasDocs(version, BUILD_SRC_DIR); await buildAndCopyCoreJS(version, BUILD_SRC_DIR, BUNDLES_DIR, true); } await prepareBuilder(targetBranch); await copyBabelStandalone(BUILD_SRC_DIR); await copyBlogPosts(BUILD_SRC_DIR); await copyCommonFiles(BUILD_SRC_DIR); if (!BRANCH) { await copyBuilderDocs(); } await buildWeb(BRANCH, BUILD_SRC_DIR); await copyWeb(); await createLastDocsLink(); if (!BRANCH) { await switchToLatestBuild(); } else { await switchBranchToLatestBuild(targetBranch); } await clearBuildDir(); await clearOldBuilds(); console.timeEnd('Finished in'); } catch (error) { console.error(error); }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/scripts/runner.sh
Shell
#!/bin/bash LOCK_FILE=./runner.lock PID_FILE=./runner.pid export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" kill_old_build() { if [ -f "$PID_FILE" ]; then OLD_PID=$(cat "$PID_FILE") if ps -p "$OLD_PID" > /dev/null 2>&1; then kill -TERM -"$OLD_PID" echo "Previous build $OLD_PID in progress. Terminating..." sleep 2 if ps -p "$OLD_PID" > /dev/null 2>&1; then kill -KILL -"$OLD_PID" echo "PID $OLD_PID still alive, sending SIGKILL!" fi fi rm -f "$LOCK_FILE" "$PID_FILE" fi } kill_old_build if ! ln -s "$$" "$LOCK_FILE" 2>/dev/null; then echo "Another build still running, exit" exit 1 fi CLEANED=0 cleanup() { if [ "$CLEANED" -eq 0 ]; then CLEANED=1 echo "Cleaning up from $$" rm -f "$LOCK_FILE" "$PID_FILE" if [ -n "$NODE_PID" ] && ps -p "$NODE_PID" > /dev/null 2>&1; then kill -TERM -"$NODE_PID" 2>/dev/null || true kill -KILL -"$NODE_PID" 2>/dev/null || true fi fi } trap cleanup EXIT HUP INT TERM echo "Lock acquired by $$, starting build..." BRANCH_ARG="" if [ -n "$1" ]; then BRANCH_ARG="branch=$1" fi if [ -z "$BRANCH_ARG" ]; then setsid node ./runner.mjs & else setsid node ./runner.mjs "$BRANCH_ARG" & fi NODE_PID=$! echo "$NODE_PID" > "$PID_FILE" wait $NODE_PID EXIT_CODE=$? exit $EXIT_CODE
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/index.html
HTML
<!DOCTYPE html> <html lang="en" class="theme-dark"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>{title}core-js</title> <link rel="apple-touch-icon" sizes="180x180" href="apple-touch-icon.png"> <link rel="icon" type="image/png" sizes="32x32" href="favicon-32x32.png"> <link rel="icon" type="image/png" sizes="16x16" href="favicon-16x16.png"> <base href="{base}" /> <script> var theme = localStorage.getItem('theme'); if (theme === null) { if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { theme = 'theme-dark'; } else { theme = 'theme-light'; } } var html = document.querySelector('html'); setTheme(theme); function setTheme(theme) { localStorage.setItem('theme', theme); html.className = ''; html.classList.add(theme); } </script> {core-js-bundle-esmodules} {core-js-bundle} <script type="module" src="js/main.js"></script> <script type="module" src="js/content-menu.js"></script> <script type="module" src="js/playground.js"></script> </head> <body> <header> <nav> <div class="logo"> <a href="https://core-js.io/"><img src="images/core-js.png" alt="core-js"></a> </div> <div id="menu"> <div class="menu-items"> <div class="menu-item highlightable"><a href="./blog/" tabindex="1">Blog</a></div> <div class="menu-item highlightable"><a href="./docs/" tabindex="3">Docs</a></div> <div class="menu-item highlightable"><a href="./playground" tabindex="2">Playground</a></div> <div class="menu-item highlightable"><a href="./changelog" tabindex="4">Changelog</a></div> <div class="socials"> <div class="menu-item"> <a href="https://github.com/zloirock/core-js/" target="_blank" tabindex="5"> <span class="icon"> <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24"><g data-name="github"><path d="M12 1A10.89 10.89 0 0 0 1 11.77 10.79 10.79 0 0 0 8.52 22c.55.1.75-.23.75-.52v-1.83c-3.06.65-3.71-1.44-3.71-1.44a2.86 2.86 0 0 0-1.22-1.58c-1-.66.08-.65.08-.65a2.31 2.31 0 0 1 1.68 1.11 2.37 2.37 0 0 0 3.2.89 2.33 2.33 0 0 1 .7-1.44c-2.44-.27-5-1.19-5-5.32a4.15 4.15 0 0 1 1.11-2.91 3.78 3.78 0 0 1 .11-2.84s.93-.29 3 1.1a10.68 10.68 0 0 1 5.5 0c2.1-1.39 3-1.1 3-1.1a3.78 3.78 0 0 1 .11 2.84A4.15 4.15 0 0 1 19 11.2c0 4.14-2.58 5.05-5 5.32a2.5 2.5 0 0 1 .75 2v2.95c0 .35.2.63.75.52A10.8 10.8 0 0 0 23 11.77 10.89 10.89 0 0 0 12 1"/></g></svg> </span> </a> </div> <div class="menu-item"> <a href="https://x.com/thecorejs" target="_blank" tabindex="6"> <span class="icon"> <svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 50 50"><path d="M 5.9199219 6 L 20.582031 27.375 L 6.2304688 44 L 9.4101562 44 L 21.986328 29.421875 L 31.986328 44 L 44 44 L 28.681641 21.669922 L 42.199219 6 L 39.029297 6 L 27.275391 19.617188 L 17.933594 6 L 5.9199219 6 z M 9.7167969 8 L 16.880859 8 L 40.203125 42 L 33.039062 42 L 9.7167969 8 z"/></svg> </span> </a> </div> <!-- <div class="menu-item">--> <!-- <a href="#" tabindex="7">--> <!-- <span class="icon"><svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 16 16"><path d="M13.545 2.907a13.2 13.2 0 0 0-3.257-1.011.05.05 0 0 0-.052.025c-.141.25-.297.577-.406.833a12.2 12.2 0 0 0-3.658 0 8 8 0 0 0-.412-.833.05.05 0 0 0-.052-.025c-1.125.194-2.22.534-3.257 1.011a.04.04 0 0 0-.021.018C.356 6.024-.213 9.047.066 12.032q.003.022.021.037a13.3 13.3 0 0 0 3.995 2.02.05.05 0 0 0 .056-.019q.463-.63.818-1.329a.05.05 0 0 0-.01-.059l-.018-.011a9 9 0 0 1-1.248-.595.05.05 0 0 1-.02-.066l.015-.019q.127-.095.248-.195a.05.05 0 0 1 .051-.007c2.619 1.196 5.454 1.196 8.041 0a.05.05 0 0 1 .053.007q.121.1.248.195a.05.05 0 0 1-.004.085 8 8 0 0 1-1.249.594.05.05 0 0 0-.03.03.05.05 0 0 0 .003.041c.24.465.515.909.817 1.329a.05.05 0 0 0 .056.019 13.2 13.2 0 0 0 4.001-2.02.05.05 0 0 0 .021-.037c.334-3.451-.559-6.449-2.366-9.106a.03.03 0 0 0-.02-.019m-8.198 7.307c-.789 0-1.438-.724-1.438-1.612s.637-1.613 1.438-1.613c.807 0 1.45.73 1.438 1.613 0 .888-.637 1.612-1.438 1.612m5.316 0c-.788 0-1.438-.724-1.438-1.612s.637-1.613 1.438-1.613c.807 0 1.451.73 1.438 1.613 0 .888-.631 1.612-1.438 1.612"/></svg></span>--> <!-- </a>--> <!-- </div>--> </div> <div class="menu-item"> <a href="#" class="theme-switcher"> <span class="theme-switcher-title">Theme</span> <span class="icon light"> <svg data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> <path stroke-linecap="round" stroke-linejoin="round" d="M12 3v2.25m6.364.386-1.591 1.591M21 12h-2.25m-.386 6.364-1.591-1.591M12 18.75V21m-4.773-4.227-1.591 1.591M5.25 12H3m4.227-4.773L5.636 5.636M15.75 12a3.75 3.75 0 1 1-7.5 0 3.75 3.75 0 0 1 7.5 0Z"></path> </svg> </span> <span class="icon dark"> <svg data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> <path stroke-linecap="round" stroke-linejoin="round" d="M21.752 15.002A9.72 9.72 0 0 1 18 15.75c-5.385 0-9.75-4.365-9.75-9.75 0-1.33.266-2.597.748-3.752A9.753 9.753 0 0 0 3 11.25C3 16.635 7.365 21 12.75 21a9.753 9.753 0 0 0 9.002-5.998Z"></path> </svg> </span> </a> </div> </div> <div class="burger"> <a href="#" id="menu-switcher"><span></span><span></span><span></span></a> </div> <div class="backdrop"></div> </div> </nav> </header> <main> <div class="main box"> {content} </div> </main> <footer> <div class="footer"> <div class="copyright"> <div class="footer-logo"><img src="images/core-js.png" alt="core-js"></div> © CoreJS Company </div> <div class="resources"> <div class="resource-item title">Resources</div> <div class="resource-item"><a href="./blog/">Blog</a></div> <div class="resource-item"><a href="./docs/">Docs</a></div> <div class="resource-item"><a href="./playground">Playground</a></div> <div class="resource-item"><a href="./changelog">Changelog</a></div> <div class="resource-item"><a href="./contributing">Contributing</a></div> <div class="resource-item"><a href="./security">Security Policy</a></div> </div> <div class="community"> <div class="resource-item title">Community</div> <div class="community-item"><a href="https://github.com/zloirock/core-js/" target="_blank">GitHub</a></div> <div class="community-item"><a href="https://x.com/thecorejs" target="_blank">X</a></div> <!-- <div class="community-item"><a href="#" target="_blank">Discord</a></div>--> </div> </div> </footer> <div id="tooltip" role="tooltip"> <div id="tooltip-text"></div> <div id="tooltip-arrow" data-popper-arrow></div> </div> </body> </html>
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/js/content-menu.js
JavaScript
import scrollToElement from './scroll-to.js'; document.addEventListener('DOMContentLoaded', () => { const triggers = document.querySelectorAll('.scroll-to'); const menuItems = document.querySelectorAll('.toc-link'); const offset = 10; function unactiveAllMenuItems() { menuItems.forEach(item => { item.classList.remove('active'); }); } function activateMenu(targetHash) { document.querySelector(`a[data-hash="${ targetHash }"]`).parentElement.classList.add('active'); } function getBlocksBoundaries() { const targetBoundaries = {}; triggers.forEach(trigger => { const targetHash = trigger.dataset.hash; const element = document.querySelector(targetHash); if (element) { targetBoundaries[targetHash] = { top: element.getBoundingClientRect().top + window.scrollY }; } }); return targetBoundaries; } function observeMenu() { const scroll = window.scrollY; const targetBoundaries = getBlocksBoundaries(); for (const [hash, target] of Object.entries(targetBoundaries)) { if (target.top > scroll && target.top < scroll + window.innerHeight / 2) { unactiveAllMenuItems(); activateMenu(hash); return; } } } function isIE() { return window.MSInputMethodContext && document.documentMode; } triggers.forEach(trigger => { trigger.addEventListener('click', function (e) { if (!isIE()) { e.preventDefault(); const { hash } = this.dataset; const href = this.getAttribute('href'); const target = document.querySelector(hash); if (target) { scrollToElement(target, offset); history.pushState(null, null, href); } } }, false); }); document.addEventListener('scroll', observeMenu); });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/js/hljs-run.js
JavaScript
export default class RunButtonPlugin { ORIGIN = location.origin; PATH = location.pathname; BASE_URL = document.querySelector('base')?.getAttribute('href'); RELATIVE_PATH = this.PATH.replace(this.BASE_URL, ''); PLAYGROUND_URL = 'playground'; text = '<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6">' + '<path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.347a1.125 1.125 0 0 1 0 ' + '1.972l-11.54 6.347a1.125 1.125 0 0 1-1.667-.986V5.653Z" />' + '</svg>'; 'after:highlightElement'({ el, result, text }) { if (result.language !== 'js') return; if (el.parentElement.querySelector('.hljs-run-button')) return; const runButton = document.createElement('a'); runButton.href = '#'; runButton.innerHTML = this.text; runButton.classList.add('hljs-run-button'); runButton.addEventListener('click', event => { event.preventDefault(); const urlParams = new URLSearchParams(); urlParams.set('code', text); const hash = urlParams.toString(); const hasVersion = this.RELATIVE_PATH !== '' && !this.RELATIVE_PATH.startsWith('docs/') && !this.RELATIVE_PATH.startsWith('index'); const version = hasVersion ? `${ this.RELATIVE_PATH.split('/')[0] }/` : ''; location.href = `${ this.ORIGIN }${ this.BASE_URL }${ version }${ this.PLAYGROUND_URL }#${ hash }`; }); const wrapper = document.createElement('div'); wrapper.classList.add('hljs-run'); wrapper.appendChild(runButton); el.appendChild(wrapper); } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/js/main.js
JavaScript
import '../scss/app.scss'; import hljs from 'highlight.js/lib/core'; import javascript from 'highlight.js/lib/languages/javascript'; import typescript from 'highlight.js/lib/languages/typescript'; import json from 'highlight.js/lib/languages/json'; import bash from 'highlight.js/lib/languages/bash'; import plaintext from 'highlight.js/lib/languages/plaintext'; import RunButtonPlugin from './hljs-run.js'; hljs.registerLanguage('js', javascript); hljs.registerLanguage('ts', typescript); hljs.registerLanguage('json', json); hljs.registerLanguage('sh', bash); hljs.registerLanguage('plaintext', plaintext); let initialized = false; function init() { if (initialized) return; initialized = true; const menuSwitcher = document.getElementById('menu-switcher'); const menuBackdrop = document.querySelector('#menu > .backdrop'); const menu = document.querySelector('#menu'); const collapsibleTrigger = document.querySelectorAll('.collapsible > a'); const dropdownTriggers = document.querySelectorAll('.dropdown .dropdown-wrapper > a'); const versionsMenu = document.querySelectorAll('.versions-menu'); const currentVersions = document.querySelectorAll('.versions-menu a.current'); const dropdownBackdrops = document.querySelectorAll('.dropdown .backdrop'); const themeSwitcher = document.querySelector('.theme-switcher'); const docsVersionLinks = document.querySelectorAll('.with-docs-version'); const docsMenuItems = document.querySelectorAll('.docs-menu li > a'); const docsCollapsibleMenuItems = document.querySelectorAll('.docs-menu .docs-links ul > li.collapsible'); const contentMenu = document.querySelector('.table-of-contents'); const contentMenuTrigger = document.querySelector('.table-of-contents .mobile-trigger'); const sectionMenu = document.querySelector('.docs-menu'); const sectionMenuTrigger = document.querySelector('.docs-menu .mobile-trigger'); const mainMenuItems = document.querySelectorAll('.menu-item.highlightable > a'); let isDocs, docsVersion; const currentPath = getRelativePath(); function toggleMenu() { menu.classList.toggle('active'); } menuBackdrop.addEventListener('click', () => { toggleMenu(); }, false); menuSwitcher.addEventListener('click', e => { e.preventDefault(); toggleMenu(); }, false); collapsibleTrigger.forEach(el => { el.addEventListener('click', function (e) { e.preventDefault(); this.parentElement.classList.toggle('active'); }); }); dropdownTriggers.forEach(el => { el.addEventListener('click', function (e) { e.preventDefault(); this.parentElement.parentElement.classList.toggle('active'); }); }); currentVersions.length && currentVersions.forEach(version => { version.addEventListener('click', e => { e.preventDefault(); }); }); dropdownBackdrops.forEach(el => { el.addEventListener('click', function () { this.parentElement.classList.remove('active'); }); }); function getRelativePath() { const path = location.pathname; const base = document.querySelector('base')?.getAttribute('href') || ''; return path.replace(base, ''); } function isDocsPage() { if (isDocs !== undefined) return isDocs; isDocs = currentPath.startsWith('docs/') || currentPath.includes('/docs/'); return isDocs; } function hasCurrentVersion() { if (docsVersion !== undefined) return docsVersion; docsVersion = !currentPath.startsWith('docs/') && !currentPath.startsWith('playground'); return docsVersion; } function setDefaultVersion() { versionsMenu.forEach(menuItem => { const currentVersion = menuItem.querySelector('a.current'); currentVersion.innerHTML = `${ currentVersion.innerHTML } (default)`; const versionsMenuLinks = menuItem.querySelectorAll('.dropdown-block a'); versionsMenuLinks.forEach(link => link.classList.remove('active')); versionsMenuLinks[0].classList.add('active'); }); } function processVersions() { const hasVersion = hasCurrentVersion(); if (!hasVersion) setDefaultVersion(); if (!isDocsPage()) return; if (hasVersion) return; docsVersionLinks.forEach(link => { const defaultVersion = link.getAttribute('data-default-version'); const re = new RegExp(`${ defaultVersion }/`); const newLink = link.getAttribute('href').replace(re, ''); link.setAttribute('href', newLink); }); } function setActiveDocsMenuItem(item) { item.classList.add('active'); let parent = item.parentElement; while (parent && !parent.classList.contains('docs-menu')) { if (parent.tagName === 'LI' && parent.classList.contains('collapsible')) { parent.classList.add('active'); } parent = parent.parentElement; } } function highlightActiveDocsMenuItem() { if (!isDocsPage()) return; let found = false; for (const link of docsMenuItems) { const href = link.getAttribute('href'); if (href && href === currentPath) { setActiveDocsMenuItem(link); found = true; break; } } !found && setActiveDocsMenuItem(docsMenuItems[0]); } function openFirstCollapsibleMenuItem() { if (!isDocsPage()) return; docsCollapsibleMenuItems[0].classList.add('active'); } function highlightMainMenu() { const path = getRelativePath(); for (const item of mainMenuItems) { const href = item.getAttribute('href').replace('./', ''); if (path.includes(href)) { item.classList.add('active'); return; } } } themeSwitcher.addEventListener('click', e => { e.preventDefault(); const html = document.querySelector('html'); const isDark = html.classList.contains('theme-dark'); // eslint-disable-next-line no-undef, sonarjs/no-reference-error -- global function isDark ? setTheme('theme-light') : setTheme('theme-dark'); }); contentMenuTrigger && contentMenuTrigger.addEventListener('click', e => { e.preventDefault(); contentMenu.classList.toggle('active'); if (contentMenu.classList.contains('active') && sectionMenu && sectionMenu.classList.contains('active')) { sectionMenu.classList.remove('active'); } }); sectionMenuTrigger && sectionMenuTrigger.addEventListener('click', e => { e.preventDefault(); sectionMenu.classList.toggle('active'); if (sectionMenu.classList.contains('active') && contentMenu && contentMenu.classList.contains('active')) { contentMenu.classList.remove('active'); } }); hljs.addPlugin(new RunButtonPlugin()); hljs.highlightAll(); processVersions(); highlightActiveDocsMenuItem(); openFirstCollapsibleMenuItem(); highlightMainMenu(); } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/js/playground.js
JavaScript
/* global Babel -- global scope directive */ import hljs from 'highlight.js/lib/core'; import javascript from 'highlight.js/lib/languages/javascript'; import { createPopper } from '@popperjs/core'; hljs.registerLanguage('javascript', javascript); const hash = location.hash.slice(1); const pageParams = new URLSearchParams(hash); const defaultCode = `import 'core-js/actual'; await Promise.try(() => 42); // => 42 Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5] [1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2] Iterator.concat([1, 2], function * (i) { while (true) yield i++; }(3)) .drop(1).take(5) .filter(it => it % 2) .map(it => it ** 2) .toArray(); // => [9, 25] structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])`; const specSymbols = { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', '\'': '&apos;', }; let initialized = false; function init() { if (initialized) return; initialized = true; const codeInput = document.querySelector('#code-input'); const codeOutput = document.querySelector('#code-output'); const runButtons = document.querySelectorAll('.run-button'); const linkButtons = document.querySelectorAll('.link-button'); const resultBlock = document.querySelector('.result'); const backLinkBlock = document.querySelector('.back-link'); const backLink = document.querySelector('.back-link a'); const tooltip = document.querySelector('#tooltip'); const tooltipText = document.querySelector('#tooltip-text'); if (!codeInput) return; function writeResult(text, type = 'log') { const serializedText = serializeLog(text).replaceAll(/["&'<>]/g, it => specSymbols[it]); resultBlock.innerHTML += `<div class="console ${ type }">${ serializedText }</div>`; } Babel.registerPlugin('playground-plugin', babel => { const { types: t } = babel; return { visitor: { ExpressionStatement(path) { const { expression, trailingComments } = path.node; if (trailingComments?.[0]?.value.startsWith(' =>')) { if ( t.isCallExpression(expression) && t.isMemberExpression(expression.callee) && expression.callee.object.name === 'console' ) return; path.replaceWith( t.callExpression( t.memberExpression(t.identifier('console'), t.identifier('log')), [t.clone(expression)], ), ); } }, ImportDeclaration(path) { const { node } = path; if (!node.specifiers.length && /^core-js(?:\/|$)/.test(node.source.value)) { path.remove(); } }, }, }; }); function runCode(code) { const origConsole = globalThis.console; const console = { log: (...args) => { args.forEach(arg => { writeResult(arg, 'log'); }); origConsole.log(...args); }, warn: (...args) => { args.forEach(arg => { writeResult(arg, 'warn'); }); origConsole.warn(...args); }, error: (...args) => { args.forEach(arg => { writeResult(arg, 'error'); }); origConsole.error(...args); }, }; try { code = Babel.transform(code, { plugins: ['playground-plugin'] }).code; code = Babel.transform(`(async function () { ${ code } \n})().catch(console.error)`, { presets: ['env'] }).code; // eslint-disable-next-line no-new-func -- it's needed to run code with monkey-patched console const executeCode = new Function('console', code); executeCode(console); } catch (error) { writeResult(`Error: ${ error.message }`, 'error'); } } function serializeLog(value, visited = new WeakSet()) { if (typeof value == 'string') return JSON.stringify(value); if (typeof value == 'function') return `[Function ${ value.name || 'anonymous' }]`; if (typeof value != 'object' || value === null) return String(value); if (value instanceof Promise) { return 'Promise { <value> }'; } if (value instanceof ArrayBuffer) { return `ArrayBuffer(${ value.byteLength })`; } if (value instanceof DataView) { return `DataView(${ value.byteLength })`; } if (ArrayBuffer.isView(value)) { const type = value.constructor.name; const objFormat = Array.from(value, (v, i) => `"${ i }": ${ serializeLog(v, visited) }`); return `${ type } { ${ objFormat.join(', ') } }`; } if (globalThis.Blob && value instanceof Blob) { return `Blob { size: ${ value.size }, type: "${ value.type }" }`; } if (value instanceof Error) { return `${ value.name || 'Error' }: ${ value.message }`; } if (value instanceof Date) { return `Date "${ String(value) }"`; } if (value instanceof RegExp) { return `RegExp ${ String(value) }`; } if (visited.has(value)) return '[Circular]'; visited.add(value); try { if (value instanceof Set) { const arr = Array.from(value, v => serializeLog(v, visited)); return `Set { ${ arr.join(', ') } }`; } if (value instanceof Map) { const arr = Array.from( value, ([k, v]) => `${ serializeLog(k, visited) } => ${ serializeLog(v, visited) }`, ); return `Map { ${ arr.join(', ') } }`; } if (Array.isArray(value)) { const arr = value.map(v => serializeLog(v, visited)); return `[${ arr.join(', ') }]`; } const isPlain = Object.getPrototypeOf(value) === Object.prototype || Object.getPrototypeOf(value) === null; const keys = Reflect.ownKeys(value); const props = keys.map(k => { // eslint-disable-next-line unicorn/no-instanceof-builtins -- it's needed here const displayKey = Object(k) instanceof Symbol ? `[${ String(k) }]` : k; return `${ displayKey }: ${ serializeLog(value[k], visited) }`; }); return isPlain ? `{ ${ props.join(', ') } }` : `${ value.constructor?.name ?? 'Object' } { ${ props.join(', ') } }`; } finally { visited.delete(value); } } function elementInViewport(el) { const rect = el.getBoundingClientRect(); return ( rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth) ); } function copyToClipboard(text) { if (navigator.clipboard && window.isSecureContext) { return navigator.clipboard.writeText(text); } const textArea = document.createElement('textarea'); textArea.value = text; textArea.classList.add('copy-fallback'); document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { if (!document.execCommand('copy')) { throw new Error('Copy command was unsuccessful'); } } finally { document.body.removeChild(textArea); } } function showTooltip(element, message, time = 3000) { tooltipText.innerHTML = message; tooltip.setAttribute('data-show', ''); createPopper(element, tooltip, { placement: 'bottom' }); setTimeout(() => { tooltip.removeAttribute('data-show'); }, time); } codeInput.addEventListener('input', () => { codeOutput.removeAttribute('data-highlighted'); let val = codeInput.value; if (val.at(-1) === '\n') val += ' '; codeOutput.textContent = val; hljs.highlightElement(codeOutput); }); codeInput.addEventListener('scroll', () => { codeOutput.scrollTop = codeInput.scrollTop; codeOutput.scrollLeft = codeInput.scrollLeft; }); runButtons.forEach(runButton => { runButton.addEventListener('click', e => { e.preventDefault(); resultBlock.innerHTML = ''; runCode(codeInput.value); if (!elementInViewport(resultBlock)) { window.scrollTo({ top: resultBlock.getBoundingClientRect().top + window.scrollY, behavior: 'smooth', }); } }); }); linkButtons.forEach(linkButton => { linkButton.addEventListener('click', e => { e.preventDefault(); pageParams.set('code', codeInput.value); location.hash = String(pageParams); try { copyToClipboard(String(location)); showTooltip(linkButton, 'Link copied'); } catch { showTooltip(linkButton, 'Can\'t copy link. Please copy the link manually'); } }); }); setInterval(() => { localStorage.setItem('code', codeInput.value); }, 2000); codeOutput.textContent = codeInput.value; hljs.highlightElement(codeOutput); let event; if (typeof Event === 'function') { event = new Event('input', { bubbles: true }); } else { event = document.createEvent('Event'); event.initEvent('input', true, true); } if (pageParams.has('code')) { codeInput.value = pageParams.get('code'); codeInput.dispatchEvent(event); } else { const code = localStorage.getItem('code'); codeInput.value = code && code !== '' ? code : defaultCode; codeInput.dispatchEvent(event); } if (document.referrer !== '') { backLinkBlock.classList.add('active'); backLink.addEventListener('click', e => { e.preventDefault(); history.back(); }); } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/js/scroll-to.js
JavaScript
export default function scrollToElement(element, offset = 0) { if (typeof element !== 'object') { element = document.querySelector(element); } if (element) { const y = element.getBoundingClientRect().top + window.scrollY - offset; window.scrollTo({ top: y, behavior: 'smooth' }); } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/playground.html
HTML
<div class="playground-menu"> <div class="title"> <div class="back-link"> <a href="#" class="back"> <span class="icon"> <svg data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"> <path stroke-linecap="round" stroke-linejoin="round" d="M12 9.75 14.25 12m0 0 2.25 2.25M14.25 12l2.25-2.25M14.25 12 12 14.25m-2.58 4.92-6.374-6.375a1.125 1.125 0 0 1 0-1.59L9.42 4.83c.21-.211.497-.33.795-.33H19.5a2.25 2.25 0 0 1 2.25 2.25v10.5a2.25 2.25 0 0 1-2.25 2.25h-9.284c-.298 0-.585-.119-.795-.33Z"></path> </svg> </span> Back </a> <div class="dummy"> <svg xmlns="http://www.w3.org/2000/svg" width="300.000000pt" height="297.000000pt" viewBox="0 0 300.000000 297.000000" preserveAspectRatio="xMidYMid meet"><g transform="translate(0.000000,297.000000) scale(0.100000,-0.100000)" fill="current" stroke="none"><path d="M1310 2900 l0 -59 44 -26 c28 -16 45 -34 48 -50 6 -30 2 -35 -29 -35 -78 0 -120 -104 -62 -156 10 -9 19 -20 19 -24 0 -4 -21 -20 -47 -37 -27 -17 -59 -50 -73 -72 -14 -22 -30 -41 -36 -41 -6 0 -35 17 -65 38 l-54 38 -3 127 c-2 119 -4 127 -22 127 -19 0 -20 -7 -20 -135 l0 -135 80 -52 c60 -40 80 -59 80 -75 0 -28 -1 -28 -106 -2 -82 21 -86 23 -145 87 -52 57 -62 64 -74 51 -12 -12 -6 -23 50 -85 l64 -72 108 -26 c97 -24 123 -27 258 -24 l150 3 5 140 c4 116 8 140 20 140 13 0 15 -24 18 -144 l3 -143 162 7 c103 4 191 14 242 26 78 19 82 21 147 91 59 63 66 75 53 87 -12 13 -22 6 -74 -51 -57 -62 -65 -67 -138 -87 -59 -16 -79 -18 -85 -8 -16 25 -6 38 67 87 l75 51 0 134 c0 128 -1 135 -20 135 -19 0 -20 -7 -20 -127 l0 -128 -62 -40 c-58 -37 -62 -38 -72 -20 -20 34 -87 104 -107 110 -23 8 -25 28 -3 46 60 49 20 159 -57 159 -34 0 -38 6 -30 38 5 17 22 35 49 50 42 23 42 24 42 83 0 46 -3 59 -15 59 -11 0 -15 -12 -15 -49 0 -40 -4 -53 -22 -65 -30 -21 -45 -20 -75 4 -33 26 -89 26 -132 -1 -29 -17 -38 -19 -62 -8 -27 11 -29 15 -29 65 0 41 -4 54 -15 54 -12 0 -15 -13 -15 -60z"/><path d="M1148 2213 c-15 -15 -24 -15 -89 -4 l-72 13 -90 -90 c-68 -68 -88 -94 -83 -108 6 -15 22 -3 95 70 l88 88 45 -7 c77 -12 77 -11 18 -140 l-54 -116 247 -247 247 -247 246 246 246 246 -51 111 c-28 61 -51 116 -51 121 0 10 13 15 69 26 32 7 38 3 121 -80 61 -61 93 -86 104 -82 9 4 16 10 16 14 0 5 -42 50 -94 102 l-94 93 -72 -13 c-66 -11 -74 -11 -85 4 -9 13 -28 17 -84 17 -42 0 -71 -4 -71 -10 0 -6 14 -67 31 -136 18 -68 29 -127 26 -131 -18 -18 -35 17 -61 123 -39 162 -34 156 -109 152 l-62 -3 -5 -340 c-5 -312 -6 -340 -22 -343 -17 -3 -18 20 -20 340 l-3 343 -66 3 c-45 2 -69 -1 -76 -10 -6 -7 -25 -70 -43 -140 -30 -115 -43 -142 -62 -123 -3 3 9 64 27 135 18 71 30 132 27 135 -3 3 -31 5 -62 5 -39 0 -61 -5 -72 -17z"/><path d="M360 1821 l-355 -350 34 -35 c35 -37 41 -37 79 -2 l23 20 377 -375 377 -376 243 15 244 14 24 -23 25 -23 -188 -188 -187 -188 -31 30 c-17 17 -36 30 -41 30 -18 0 -144 -100 -144 -113 0 -15 221 -237 235 -237 11 0 115 134 115 147 0 4 -14 22 -32 40 l-32 34 187 187 187 187 185 -185 c102 -102 185 -189 185 -194 0 -6 -14 -24 -30 -41 l-30 -31 52 -72 c29 -39 58 -71 63 -72 6 0 64 54 130 120 l120 121 -25 19 c-14 11 -49 37 -78 57 l-52 37 -35 -34 -35 -34 -185 184 c-102 102 -185 190 -185 196 0 6 9 19 20 29 18 16 33 17 237 6 120 -6 231 -14 248 -16 27 -5 55 20 407 372 l378 377 28 -27 28 -27 34 35 34 36 -352 351 -351 352 -36 -34 -35 -34 27 -28 27 -29 -376 -377 -376 -377 15 -244 14 -244 -25 -26 -26 -26 -25 25 -25 25 16 245 15 244 -371 371 c-203 203 -370 375 -370 381 0 6 9 19 20 29 11 10 20 23 20 30 0 11 -51 65 -61 65 -2 0 -164 -157 -359 -349z m405 19 l69 -70 -204 -205 c-112 -113 -209 -205 -215 -205 -6 0 -41 31 -79 69 l-69 69 209 206 c115 113 211 205 214 206 3 0 37 -31 75 -70z m1855 -224 l115 -116 -73 -72 -72 -73 -207 207 -208 208 69 69 69 70 96 -89 c53 -49 148 -141 211 -204z m-1588 -43 c60 -59 108 -112 108 -118 0 -6 -36 -46 -80 -90 -77 -76 -80 -78 -105 -65 -24 13 -28 12 -57 -18 -31 -31 -32 -31 -13 -52 19 -21 18 -21 -68 -108 l-87 -87 -110 110 c-60 60 -110 114 -110 120 0 10 400 415 410 415 2 0 53 -48 112 -107z m1356 -420 l-113 -113 -85 85 c-79 79 -84 86 -71 106 12 20 10 25 -18 53 -28 28 -33 29 -53 17 -19 -12 -27 -7 -106 72 l-85 86 113 111 113 112 208 -208 209 -209 -112 -112z m-1089 153 l53 -54 -7 -151 c-4 -83 -12 -154 -17 -157 -11 -7 -258 234 -258 251 0 13 152 165 165 165 6 0 35 -24 64 -54z m559 -29 l82 -82 -130 -130 c-71 -71 -132 -126 -136 -123 -3 4 -10 75 -16 159 l-10 152 53 53 c30 30 58 54 64 54 6 0 47 -37 93 -83z m-733 -287 c71 -71 127 -132 124 -135 -3 -3 -75 -10 -159 -15 l-154 -11 -60 61 -61 60 85 85 c46 47 87 85 90 85 3 0 64 -58 135 -130z m975 45 l85 -85 -61 -60 -60 -61 -147 10 c-81 6 -152 13 -158 17 -10 6 236 264 251 264 3 0 44 -38 90 -85z"/></g></svg> </div> </div> <div class="playground-versions">{versions-menu}</div> </div> <div class="playground-controls"> <button class="run-button">Run</button> <button class="link-button">Link</button> </div> <div class="playground-notes"> <span class="icon icon-md"> <svg viewBox="0 0 16 16" width="16" height="16" aria-hidden="true"><path d="M0 1.75C0 .784.784 0 1.75 0h12.5C15.216 0 16 .784 16 1.75v9.5A1.75 1.75 0 0 1 14.25 13H8.06l-2.573 2.573A1.458 1.458 0 0 1 3 14.543V13H1.75A1.75 1.75 0 0 1 0 11.25Zm1.75-.25a.25.25 0 0 0-.25.25v9.5c0 .138.112.25.25.25h2a.75.75 0 0 1 .75.75v2.19l2.72-2.72a.749.749 0 0 1 .53-.22h6.5a.25.25 0 0 0 .25-.25v-9.5a.25.25 0 0 0-.25-.25Zm7 2.25v2.5a.75.75 0 0 1-1.5 0v-2.5a.75.75 0 0 1 1.5 0ZM9 9a1 1 0 1 1-2 0 1 1 0 0 1 2 0Z"></path></svg> </span> <span>Use <code>console.log()</code> or <code>// =></code> for output</span> </div> </div> <div class="sandbox-wrapper"> <div class="editor"> <textarea id="code-input" class="input" spellcheck="false"></textarea> <div id="code-output" class="output language-javascript"></div> <div class="controls-float"> <a href="#" class="run-button"> <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"><path stroke-linecap="round" stroke-linejoin="round" d="M5.25 5.653c0-.856.917-1.398 1.667-.986l11.54 6.347a1.125 1.125 0 0 1 0 1.972l-11.54 6.347a1.125 1.125 0 0 1-1.667-.986V5.653Z" /></svg> </a> <a href="#" class="link-button"> <svg data-slot="icon" fill="none" stroke-width="1.5" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path stroke-linecap="round" stroke-linejoin="round" d="M13.19 8.688a4.5 4.5 0 0 1 1.242 7.244l-4.5 4.5a4.5 4.5 0 0 1-6.364-6.364l1.757-1.757m13.35-.622 1.757-1.757a4.5 4.5 0 0 0-6.364-6.364l-4.5 4.5a4.5 4.5 0 0 0 1.242 7.244"></path></svg> </a> </div> </div> <div class="result"></div> </div> {babel-script}
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/app.scss
SCSS
@use "includes/variables-dark"; @use "includes/themes"; @use "includes/themify"; @use "includes/themed"; @use "includes/reset"; @use "includes/forms"; @use "includes/mixins"; @use "includes/base"; @use "includes/markdown"; @use "parts/header"; @use "parts/main"; @use "parts/footer"; @use "parts/code"; @use "parts/playground"; @use "parts/tooltip";
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/base.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; @use "../includes/themed" as *; html { font-size: 14px; line-height: 1.8; @include media("min", "lg") { font-size: 16px; } @include media("min", "xxl") { font-size: 18px; } } body { display: flex; flex-direction: column; min-height: 100vh; font-family: Helvetica, sans-serif; font-weight: 400; font-style: normal; @include themify($themes) { background-color: themed('background-color'); color: themed('font-color'); } } a { @include themify($themes) { color: themed('link-color'); } &:hover, &:focus { @include themify($themes) { color: themed('link-color-hover'); } } } h1, h2, h3, h4, h5, h6 { position: relative; font-weight: 600; text-align: left; @include themify($themes) { color: themed('font-color-light'); } &.with-anchor { .anchor { display: none; width: 1.2rem; margin-left: 0.5rem; height: 1.5rem; svg { @include themify($themes) { fill: themed('link-color2'); } } &:hover svg { @include themify($themes) { fill: themed('link-color2-hover'); } } } &:hover .anchor { display: inline-block; } } } h1 { font-size: 2.25rem; margin: 0 1rem 1rem; text-align: center; @include themify($themes) { border-bottom: 1px solid themed('border-color-lighter'); } } h2 { font-size: 2rem; } h3 { font-size: 1.875rem; } h4 { font-size: 1.5rem; } p { padding: 0.5rem 0; } pre { padding: 1rem 0; } blockquote { padding: 0 1rem; margin-bottom: 1rem; @include themify($themes) { background-color: themed('box-light'); border-left: 1px solid themed('success'); } } ul { padding-left: 1rem; list-style-type: disc; } svg { width: 100%; height: auto; } table { tr { &:nth-child(odd) { @include themify($themes) { background-color: themed('background-highlight'); } } &:nth-child(even) { @include themify($themes) { background-color: themed('background-light'); } } th { padding: 0.25rem 0.375rem; } } @include media("max", "lg") { display: block; overflow-x: auto; white-space: nowrap; } } .box { border-radius: 1rem; @include themify($themes) { background-color: themed('box-color'); } } .icon { display: block; line-height: 0; width: 24px; height: 24px; &.icon-md { width: 1rem; height: 1rem; } } details { summary { cursor: pointer; @include themify($themes) { color: themed('link-color2'); } } summary:after { content: ''; display: inline-block; line-height: 0; width: 0.5rem; height: 0.5rem; transform: rotate(45deg); margin-left: 0.5rem; vertical-align: 2px; @include themify($themes) { border-right: 2px solid themed('link-color2'); border-bottom: 2px solid themed('link-color2'); } } &[open] summary:after { vertical-align: -3px; transform: rotate(-135deg); } summary:hover { @include themify($themes) { color: themed('link-color2-hover'); } &:after { @include themify($themes) { border-right: 2px solid themed('link-color2-hover'); border-bottom: 2px solid themed('link-color2-hover'); } } } } hr { margin: 2rem; }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/forms.scss
SCSS
@use "../includes/themes" as *; @use "../includes/themify" as *; @use "../includes/themed" as *; button { border-radius: 0.5rem; cursor: pointer; padding: 1rem; line-height: 1; font-weight: 600; @include themify($themes) { background-color: transparent; border: 1px solid themed('background-highlight'); color: themed('link-color'); } &:focus, &:hover { @include themify($themes) { background-color: themed('button-color-hover'); color: themed('link-color-hover'); } } &.big { border-radius: 2rem; font-size: 1.25rem; padding: 1rem; } &.full-width { width: 100%; } } input { width: 100%; padding: 0 2rem 0 0; font-size: 1rem; line-height: 3rem; border-radius: 8px; border: 0; outline: 0; @include themify($themes) { color: themed('form-font-color'); background-color: themed('background-light'); } } .form-item { display: flex; align-items: center; padding: 0 2rem; margin-bottom: 0.5rem; border-radius: 8px; @include themify($themes) { background-color: themed('background-light'); } .icon { width: 1.25rem; height: 1.25rem; margin-right: 0.75rem; svg { width: 100%; height: auto; opacity: 0.3; @include themify($themes) { color: themed('form-font-color'); } } } } select { width: 100%; height: 3rem; font-size: 1rem; border-radius: 8px; border: 0; outline: 0; appearance: none; @include themify($themes) { color: themed('form-font-color'); background-color: themed('background-light'); } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/markdown.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; @use "../includes/themed" as *; .markdown-alert { padding-left: 1rem; margin-bottom: 1rem; &.markdown-alert-note { @include themify($themes) { border-left: 1px solid themed('neutral'); } .markdown-alert-title { @include themify($themes) { color: themed('neutral'); } } svg { @include themify($themes) { fill: themed('neutral'); } } } &.markdown-alert-tip { @include themify($themes) { border-left: 1px solid themed('success'); } .markdown-alert-title { @include themify($themes) { color: themed('success'); } } svg { @include themify($themes) { fill: themed('success'); } } } &.markdown-alert-important { @include themify($themes) { border-left: 1px solid themed('success'); } .markdown-alert-title { @include themify($themes) { color: themed('success'); } } svg { @include themify($themes) { fill: themed('success'); } } } &.markdown-alert-warning { @include themify($themes) { border-left: 1px solid themed('warning'); } .markdown-alert-title { @include themify($themes) { color: themed('warning'); } } svg { @include themify($themes) { fill: themed('warning'); } } } &.markdown-alert-caution { @include themify($themes) { border-left: 1px solid themed('warning'); } .markdown-alert-title { @include themify($themes) { color: themed('warning'); } } svg { @include themify($themes) { fill: themed('warning'); } } } .markdown-alert-title { font-weight: 700; vertical-align: middle; svg { width: 16px; height: 16px; padding-right: 0.5rem; } } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/mixins.scss
SCSS
$sizes: ( "xs": 0px, "sm": 480px, "md": 767px, "lg": 1024px, "xl": 1439px, "xxl": 1920px, ); @function getPreviousSize($currentSize) { $keys: map-keys($sizes); $index: index($keys, $currentSize) - 1; $value: map-values($sizes); @return nth($value, $index); } @mixin media($minmax, $media) { @each $size, $resolution in $sizes { @if $media == $size { @if ($minmax == "max") { @media only screen and (#{$minmax}-width: $resolution) { @content; } } @else if ($minmax == "min") { @media only screen and (#{$minmax}-width: $resolution + 1) { @content; } } @else { @if (index(map-keys($sizes), $media) > 1) { @media only screen and (min-width: getPreviousSize($media) + 1) and (max-width: $resolution + 1) { @content; } } @else { @media only screen and (max-width: $resolution) { @content; } } } } } } @mixin wrapper() { width: 100%; @include media('min', 'xl') { max-width: 90%; } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/reset.scss
SCSS
html, body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, form, fieldset, input, textarea, p, blockquote, th, td, figure, figcaption, address { margin: 0; padding: 0; box-sizing: border-box; } html { overflow-y: scroll; } article, aside, details, figcaption, figure, footer, header, hgroup, nav, section, summary { display: block; margin: 0; padding: 0; } table { border-spacing: 1px; margin: 1rem 0; th, td { vertical-align: middle; padding: 0.25rem; } } caption, th { text-align: left; } ul, ol { list-style: none; } a { text-decoration: none; } a:link, a:visited, a:active { -webkit-transition: 0.1s color ease; -moz-transition: 0.1s color ease; -o-transition: 0.1s color ease; transition: 0.1s color ease; } a:hover, a:focus { cursor: pointer; text-decoration: none; } input[type="text"], input[type="password"], input[type="number"], input[type="email"], input[type="tel"], textarea { appearance: none; outline: none; } @-webkit-keyframes autofill { to { background: transparent; } } input:-webkit-autofill, textarea:-webkit-autofill, select:-webkit-autofill { -webkit-animation-name: autofill; -webkit-animation-fill-mode: both; } svg { overflow: auto; vertical-align: inherit; } img { max-width: 100%; } * { outline: none; }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/themed.scss
SCSS
@use "sass:map"; @use "../includes/themify" as *; @function themed($key) { @return map.get($theme-map, $key); }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/themes.scss
SCSS
@use 'variables-dark' as dark; @use 'variables-light' as light; @use "mixins" as *; $themes: ( 'dark': ( 'font-color': dark.$foreground, 'font-color-light': dark.$font, 'font-color-dark': dark.$dark, 'comment-color': dark.$comment, 'font-success': dark.$green, 'font-warning': dark.$orange, 'font-error': dark.$red, 'font-note': rgba(dark.$foreground, 0.7), 'button-color': dark.$bg, 'button-color-hover': dark.$selection, 'box-color': dark.$bg, 'box-light': dark.$selection, 'background-color': dark.$dark, 'background-light': dark.$secondary, 'background-highlight': dark.$highlight, 'link-color': rgba(dark.$foreground, 0.7), 'link-color-hover': dark.$foreground, 'link-color2': rgba(dark.$link, 0.7), 'link-color2-hover': dark.$link, 'border-color': dark.$dark, 'border-color-light': dark.$secondary, 'border-color-lighter': dark.$selection, 'form-font-color': dark.$foreground, 'form-hint-color': dark.$foreground, 'success': dark.$green, 'warning': dark.$orange, 'error': dark.$red, 'neutral': dark.$comment, 'section': dark.$pink, 'meta': dark.$purple, 'function': dark.$cyan, ), 'light': ( 'font-color': light.$foreground, 'font-color-light': light.$font, 'font-color-dark': light.$dark, 'comment-color': light.$comment, 'font-success': light.$green, 'font-warning': light.$orange, 'font-error': light.$red, 'font-note': rgba(light.$foreground, 0.7), 'button-color': light.$foreground, 'button-color-hover': light.$selection, 'box-color': light.$bg, 'box-light': light.$selection, 'background-color': light.$dark, 'background-light': light.$secondary, 'background-highlight': light.$highlight, 'link-color': rgba(light.$foreground, 0.7), 'link-color-hover': light.$foreground, 'link-color2': rgba(light.$link, 0.7), 'link-color2-hover': light.$link, 'border-color': light.$dark, 'border-color-light': light.$secondary, 'border-color-lighter': light.$highlight, 'form-font-color': light.$foreground, 'form-hint-color': light.$foreground, 'success': light.$green, 'warning': light.$orange, 'error': light.$red, 'neutral': light.$comment, 'section': light.$pink, 'meta': light.$purple, 'function': light.$cyan, ) );
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/themify.scss
SCSS
$theme-map: (); @use "sass:map"; @use 'themes' as *; @mixin themify($themes: $themes) { @each $theme, $map in $themes { .theme-#{$theme} & { $theme-map: () !global; @each $key, $submap in $map { $value: map.get(map.get($themes, $theme), '#{$key}'); $theme-map: map.merge($theme-map, ($key: $value)) !global; } @content; $theme-map: null !global; } } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/variables-dark.scss
SCSS
$bg: #282a36; $current_line: #44475a; $foreground: #fafaf4; $comment: #6272a4; $cyan: #8be9fd; $green: #50fa7b; $orange: #ffb86c; $pink: #ff79c6; $purple: #bd93f9; $red: #ff5555; $link: #f1fa8c; $font: #ffffff; $selection: #44475a; $secondary: #2e313f; $dark: #191a21; $highlight: #44475a; $disabled: #6D6D6D;
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/includes/variables-light.scss
SCSS
$bg: #eceff4; $current_line: #e5e9f0; $foreground: #1f232c; $comment: #4c566a; $cyan: #0184bc; $green: #50a14f; $orange: #c18401; $pink: #a626a4; $purple: #986801; $red: #e45649; $link: #286ff3; $font: #1f232c; $selection: #fafafa; $secondary: #ffffff; $dark: #eceff4; $highlight: #d8dee9; $disabled: #a3be8c40;
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/parts/code.scss
SCSS
@use "../includes/themed" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; .hljs { display: block; overflow-x: auto; padding: 0.5em; @include themify($themes) { background-color: themed('box-color'); color: themed('font-color'); } } .hljs-comment, .hljs-quote { font-style: italic; @include themify($themes) { color: themed('comment-color'); } } .hljs-keyword, .hljs-selector-tag, .hljs-literal, .hljs-section, .hljs-link { @include themify($themes) { color: themed('section'); } } .hljs-string, .hljs-title, .hljs-name, .hljs-type, .hljs-attribute, .hljs-symbol, .hljs-bullet, .hljs-addition { @include themify($themes) { color: themed('success'); } } .hljs-number, .hljs-meta, .hljs-built_in, .hljs-builtin-name, .hljs-params { @include themify($themes) { color: themed('meta'); } } .hljs-class .hljs-title, .hljs-strong { font-weight: bold; @include themify($themes) { color: themed('link-color2-hover'); } } .hljs-emphasis { font-style: italic; } .hljs-function .hljs-title { @include themify($themes) { color: themed('function'); } } .hljs-tag, .hljs-deletion { @include themify($themes) { color: themed('font-error'); } } .hljs-variable, .hljs-template-variable, .hljs-selector-attr, .hljs-selector-pseudo { @include themify($themes) { color: themed('font-warning'); } } .hljs-doctag { @include themify($themes) { color: themed('font-warning'); } } .hljs-bullet { @include themify($themes) { color: themed('meta'); } } .hljs-code, .hljs-formula { @include themify($themes) { color: themed('section'); } } .hljs-link { text-decoration: underline; } .hljs-selector-id { @include themify($themes) { color: themed('link-color2-hover'); } } .hljs-selector-class { @include themify($themes) { color: themed('function'); } } .hljs::selection, .hljs span::selection { @include themify($themes) { background: themed('button-color-hover'); } } code { position: relative; overflow-x: auto; max-width: 100%; display: inline-block; vertical-align: middle; scrollbar-width: thin; padding: 0 0.25rem; @include themify($themes) { background: themed('button-color-hover'); scrollbar-color: themed('background-light') themed('button-color-hover'); } } pre code { scrollbar-width: thin; font-size: 0.85rem; line-height: 1.375rem; @include themify($themes) { scrollbar-color: themed('background-light') themed('background-highlight'); } } .hljs-run { position: absolute; top: 0.25rem; right: 0.25rem; width: 24px; height: 24px; .hljs-run-button { display: block; width: 100%; height: 100%; } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/parts/footer.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themed" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; footer { display: flex; padding: 2rem; justify-content: center; @include themify($themes) { border-top: 1px solid themed('border-color-light'); } .footer { display: flex; justify-content: space-between; align-items: start; flex-direction: column; @include wrapper; @include media('min', 'sm') { flex-direction: row; } .footer-logo { width: 144px; } .title { font-size: 1.125rem; font-weight: 600; @include themify($themes) { color: themed('font-color'); } } .copyright { order: 3; margin-top: 1rem; @include media('min', 'sm') { order: unset; margin-top: 0; } } } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/parts/header.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themed" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; header { display: flex; justify-content: center; @include themify($themes) { background-color: themed('background-color'); } @include media("min", "xl") { padding: 0 1rem; } } nav { display: flex; justify-content: space-between; align-items: center; padding: 1rem; max-height: 86px; @include wrapper; .logo { max-width: 60%; @include media('min', 'sm') { width: 360px; max-width: unset; } a { display: flex; img { width: 100%; height: auto; } } } #menu { display: flex; align-items: center; .menu-items { display: none; @include media("min", "lg") { display: flex; align-items: center; } .menu-item { padding-right: 1rem; &:last-child { padding-right: 0; } .theme-switcher { display: flex; align-items: center; } .theme-switcher-title { margin-right: 0.5rem; @include media("min", "lg") { display: none; } } } a { font-size: 1.5rem; display: block; overflow-wrap: break-word; @include themify($themes) { color: themed('link-color'); } &:hover { @include themify($themes) { color: themed('link-color-hover'); } } &.active { @include themify($themes) { color: themed('link-color2'); } } .icon { width: 26px; height: 26px; } } .mobile-docs-menu { display: none; } } &.active { align-items: center; overflow-y: auto; & > .backdrop { display: block; } @include media("max", "lg") { .menu-items { z-index: 5; display: flex; flex-direction: column; position: absolute; top: 0; right: 0; min-height: 40vh; width: 75%; max-height: 100vh; max-width: 350px; overflow-y: auto; scrollbar-width: thin; @include themify($themes) { scrollbar-color: themed('background-light') themed('background-highlight'); } border-top-left-radius: 20px; border-bottom-left-radius: 20px; padding: 50px 20px 30px 30px; @include themify($themes) { background-color: themed('box-color'); box-shadow: -1px 1px 5px themed('background-light'); } .mobile-docs-menu { display: block; ul { list-style: circle; } .menu-header { font-size: 1.25rem; } } } .menu-item { line-height: 2rem; a::after { top: 0.75rem; } } .burger { position: absolute; top: 25px; right: 15px; z-index: 6; a { display: block; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; span { height: 1px; @include themify($themes) { background-color: themed('font-color'); } &:nth-child(1) { margin-top: 11px; transform: rotate(-45deg); } &:nth-child(2) { margin-top: -1px; transform: rotate(45deg); } &:nth-child(3) { display: none; } } } } } } .burger { @include media("min", "lg") { display: none; } a { display: flex; width: 26px; height: 22px; padding: 5px; flex-direction: column; justify-content: space-between; span { display: block; width: 100%; height: 2px; border-radius: 2px; @include themify($themes) { background-color: themed('link-color'); } } } } .backdrop { display: none; content: ''; position: absolute; width: 100%; height: 100vh; top: 0; left: 0; right: 0; bottom: 0; z-index: 4; } .socials { display: flex; align-items: center; margin-right: 1rem; @include media("max", "lg") { width: 100%; justify-content: center; margin: auto 0 0; order: 99; padding-top: 2rem; } @include media("min", "lg") { padding: 0 1rem; @include themify($themes) { border-left: 1px solid themed('link-color'); border-right: 1px solid themed('link-color'); } } } } } .theme-light { .icon.light { display: none; } .icon.dark { display: block; } } .theme-dark { .icon.light { display: block; } .icon.dark { display: none; } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/parts/main.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themed" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; .collapsible { a { position: relative; } & > ul { display: none; } &.active { & > a::after { transform: rotate(-135deg); top: 0.625rem; } & > ul { display: block; } } & > a::after { position: absolute; width: 5px; height: 5px; transform: rotate(45deg); content: ''; margin-left: 0.5rem; top: 0.375rem; @include themify($themes) { border-right: 1px solid themed('link-color'); border-bottom: 1px solid themed('link-color'); } } } main { display: flex; justify-content: center; flex-grow: 1; margin-bottom: 2rem; @include media('min', 'sm') { padding: 0 1rem 1rem; } a { @include themify($themes) { color: themed('link-color2'); } &:focus { @include themify($themes) { color: themed('link-color2'); } } &:hover { @include themify($themes) { color: themed('link-color2-hover'); } } } .main { padding: 1rem 1rem; @include themify($themes) { background-color: themed('background-light'); } @include wrapper; .wrapper { display: flex; position: relative; .docs-menu { position: sticky; top: 1rem; align-self: flex-start; padding: 0 0.5rem 150px 0; font-size: 0.875rem; flex-basis: 20%; min-width: 160px; flex-shrink: 0; line-height: 1.3; min-height: 100vh; min-height: 100dvh; max-height: 100vh; max-height: 100dvh; overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; @include themify($themes) { border-right: 1px solid themed('border-color-lighter'); scrollbar-color: themed('background-light') themed('background-highlight'); } ul { list-style: none; padding: 0; li { padding: 0.25rem 0 0.5rem 0; &:last-child { padding-bottom: 0; } } } @include media('max', 'md') { position: absolute; left: -1rem; top: 1rem; bottom: 1rem; min-width: 1.75rem; z-index: 3; overflow-y: unset; padding: 0; height: 100%; min-height: unset; max-height: unset; overflow-x: unset; @include themify($themes) { background-color: themed('background-light'); box-shadow: 5px 5px 7px -6px themed('background-highlight'); } .container { position: sticky; display: flex; top: 1rem; max-height: 100dvh; height: 100%; padding-bottom: 1rem; } .docs-links { max-height: 100dvh; height: 100%; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; padding-bottom: 1rem; } .mobile-trigger { display: flex; width: 1.75rem; min-width: 1.75rem; cursor: pointer; align-items: center; justify-content: center; max-height: 100vh; max-height: 100dvh; &:after { content: ''; display: block; width: 10px; height: 10px; transform: rotate(-45deg); margin-left: -2px; @include themify($themes) { border-right: 2px solid themed('link-color'); border-bottom: 2px solid themed('link-color'); } } &:hover { &:after { @include themify($themes) { border-right: 2px solid themed('link-color-hover'); border-bottom: 2px solid themed('link-color-hover'); } } } } li { @include media('max', 'md') { display: none; } } &.active { min-width: 180px; max-width: 270px; padding-left: 1rem; li { display: block; } .mobile-trigger { &:after { transform: rotate(135deg); margin-left: 5px; } } } } a { &.active { @include themify($themes) { color: themed('link-color2-hover'); } } } .collapsible { & > ul { padding: 0.75rem 0 0 1rem; } &.active { & > a::after { top: 0.5rem; } } & > a::after { top: 0.125rem; } } .menu-header { padding: 0 0 0.75rem 0; font-weight: 600; } .menu-item { padding: 0 0.5rem 0.5rem 0.5rem; @include themify($themes) { border-right: 1px solid themed('border-color-lighter'); } } } .content { width: 100%; padding: 1rem 1rem 0; min-width: 0; text-align: justify; @include media("min", "md") { padding: 0 1rem; } } .table-of-contents { position: sticky; top: 1rem; align-self: flex-start; font-size: 0.875rem; max-width: 20%; min-width: 20%; height: 100vh; height: 100dvh; overflow-y: auto; scrollbar-width: none; @include themify($themes) { border-left: 1px solid themed('border-color-lighter'); } .mobile-trigger { display: none; } @include media('max', 'xl') { position: absolute; right: -1rem; top: 1rem; bottom: 1rem; min-width: 1.75rem; z-index: 3; overflow-y: unset; height: 100%; @include themify($themes) { background-color: themed('background-light'); box-shadow: -5px 5px 7px -6px themed('background-highlight'); } .container { position: sticky; display: flex; top: 1rem; max-height: 100dvh; height: 100%; padding-bottom: 1rem; } .toc-links { max-height: 100dvh; height: 100%; overflow-y: auto; scrollbar-width: none; -ms-overflow-style: none; } .mobile-trigger { display: flex; width: 1.75rem; min-width: 1.75rem; cursor: pointer; align-items: center; justify-content: center; max-height: 100vh; max-height: 100dvh; &:after { content: ''; display: block; transform: rotate(135deg); width: 10px; height: 10px; margin-left: 5px; @include themify($themes) { border-right: 2px solid themed('link-color'); border-bottom: 2px solid themed('link-color'); } } &:hover { &:after { @include themify($themes) { border-right: 2px solid themed('link-color-hover'); border-bottom: 2px solid themed('link-color-hover'); } } } } &.active { min-width: 180px; .toc-link { display: block; padding-left: 0; padding-right: 1rem; } .mobile-trigger { &:after { transform: rotate(-45deg); margin-left: -2px; } } } } .toc-link { padding: 0 0 0.5rem 1rem; @include media('max', 'xl') { display: none; } a { display: block; } &.active { a { @include themify($themes) { color: themed('link-color2-hover'); } } } .h3 { margin-left: 0.5rem; } .h4, .h5, .h6, .h7 { margin-left: 1rem; } } } } .sponsors { display: flex; flex-wrap: wrap; a { flex-basis: 33%; @include media("min", "md") { flex-basis: 25%; } } } .features { display: flex; flex-wrap: wrap; align-content: stretch; align-items: stretch; justify-content: center; margin: 1rem 0; text-align: start; gap: 2rem; .feature { flex-basis: 100%; padding: 1rem; border-radius: 1rem; max-width: 400px; @include themify($themes) { background-color: themed('box-color'); border: 1px solid themed('box-light'); } @include media("min", "md") { flex-basis: 48%; } @include media("min", "lg") { flex-basis: 31%; } @include media("min", "xxl") { flex-basis: 23%; } .title { font-size: 1.5rem; display: flex; align-items: center; gap: 0.5rem; svg { @include themify($themes) { color: themed('font-success'); } } } .desc { } } } } } .dropdown { a { white-space: nowrap; } .dropdown-wrapper { position: relative; & > a { display: block; overflow: hidden; width: 90%; &::after { content: ''; width: 5px; height: 5px; transform: rotate(45deg); position: absolute; right: 5px; top: 3px; @include themify($themes) { border-right: 2px solid themed('link-color'); border-bottom: 2px solid themed('link-color'); } } } .dropdown-block { display: none; a { display: block; line-height: 2; } } } &.active { .dropdown-block { display: block; position: absolute; z-index: 6; left: -1rem; margin-top: 0.625rem; padding: 0.5rem 1rem; border-radius: 0.5rem; @include themify($themes) { border: 1px solid themed('border-color-lighter'); background-color: themed('background-color'); } a.active { font-weight: 500; @include themify($themes) { color: themed('link-color2-hover'); } } } .backdrop { display: block; position: fixed; top: 0; right: 0; bottom: 0; left: 0; } } @include media("max", "lg") { .backdrop { height: 100%; } } } .versions-menu { padding: 0.5rem 1rem; border-radius: 0.5rem; @include themify($themes) { border: 1px solid themed('border-color-lighter'); background-color: themed('background-light'); } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/parts/playground.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themed" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; .sandbox-wrapper { margin: 1rem 0 0; @include media("min", "lg") { display: flex; } .editor { position: relative; flex-basis: 800px; flex-grow: 1; height: 30rem; padding: 0; border: none; @include media("min", "lg") { margin-right: 1rem; } .input, .output { box-sizing: border-box; position: absolute; height: 100%; width: 100%; font-family: monospace; padding: 0.5em; border: none; font-size: 0.85rem; line-height: 1.375rem; white-space: pre; word-wrap: break-word; overflow: auto; scrollbar-width: thin; @include themify($themes) { scrollbar-color: themed('background-light') themed('background-highlight'); } } .input { z-index: 1; color: transparent; background-color: transparent; resize: none; @include themify($themes) { caret-color: themed('font-color'); } } .output { z-index: 0; padding-bottom: 7px; @include themify($themes) { background-color: themed('box-color'); } } .controls-float { position: absolute; position: sticky; width: fit-content; display: flex; top: 0.25rem; right: 0.5rem; margin-left: auto; padding-right: 0.5rem; padding-top: 0.25rem; z-index: 3; a { display: block; width: 24px; height: 24px; margin-right: 0.5rem; &.link-button { width: 22px; height: 22px; } } } } .result { margin-top: 2rem; padding: 0.5em; font-family: monospace; font-size: 0.85rem; line-height: 1.375rem; white-space: pre; word-wrap: break-word; scrollbar-width: thin; @include themify($themes) { background-color: themed('box-color'); scrollbar-color: themed('background-light') themed('background-highlight'); } @include media("min", "lg") { flex-basis: 400px; flex-shrink: 0; margin-top: 0; overflow: auto; height: 30rem; } .console { &.log { @include themify($themes) { color: themed('font-success'); } } &.warn { @include themify($themes) { color: themed('font-warning'); } } &.error { @include themify($themes) { color: themed('font-error'); } } } } } .playground-menu { display: flex; flex-direction: column; align-items: center; @include media("min", "md") { flex-direction: row; } .title { display: flex; align-items: center; margin-bottom: 1rem; @include media("min", "md") { margin: 0 1.5rem 0 0; } .back-link { flex-basis: 68px; flex-shrink: 0; margin-right: 1.5rem; padding-left: 0.25rem; a { align-items: center; display: none; .icon { margin-right: 0.5rem; } } .dummy { width: 36px; height: 36px; margin-left: auto; svg { @include themify($themes) { fill: themed('font-color'); } } } &.active { a { display: flex; } .dummy { display: none; } } } h1 { border-bottom: 0; margin: 0; } } .playground-versions { min-width: 200px; width: 100%; @include media("min", "md") { max-width: 200px; } .dropdown .dropdown-wrapper > a:after { top: 8px; } .backdrop { z-index: 3; } } .playground-controls { display: flex; margin-bottom: 1rem; @include media("min", "md") { margin-bottom: 0; } button { margin-right: 1rem; &:last-child { margin-right: 0; } } } .playground-notes { display: flex; align-items: center; font-size: 0.75rem; padding: 0 0.5rem; @include themify($themes) { color: themed('font-note'); } @include media("min", "md") { margin-left: auto; } .icon { margin-right: 0.5rem; svg { @include themify($themes) { fill: themed('font-note'); } } } } } .copy-fallback { position: fixed; top: 0; left: 0; opacity: 0; }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/src/scss/parts/tooltip.scss
SCSS
@use "../includes/mixins" as *; @use "../includes/themed" as *; @use "../includes/themes" as *; @use "../includes/themify" as *; #tooltip { position: absolute; font-weight: bold; padding: 4px 8px; border-radius: 4px; opacity: 0; transition: opacity 0.3s ease; @include themify($themes) { background: themed('font-color'); color: themed('background-highlight'); } &[data-show] { opacity: 1; } #tooltip-arrow, #tooltip-arrow::before { position: absolute; width: 8px; height: 8px; background: inherit; } #tooltip-arrow { visibility: hidden; } #tooltip-arrow::before { visibility: visible; content: ''; transform: rotate(45deg); } &[data-popper-placement^='top'] > #tooltip-arrow { bottom: -4px; } &[data-popper-placement^='bottom'] > #tooltip-arrow { top: -4px; } &[data-popper-placement^='left'] > #tooltip-arrow { right: -4px; } &[data-popper-placement^='right'] > #tooltip-arrow { left: -4px; } }
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
website/vite.config.mjs
JavaScript
import { defineConfig } from 'vite'; import legacy from '@vitejs/plugin-legacy'; export default defineConfig({ root: 'src', publicDir: 'public', base: '', build: { rollupOptions: { input: { main: 'src/index.html', playground: 'src/playground.html', }, }, outDir: '../templates', emptyOutDir: true, minify: true, cssTarget: [ 'ie11', ], }, plugins: [ legacy({ targets: 'IE 11, Chrome>=38, Safari>=7.1, FF>=15', polyfills: false, }), ], });
zloirock/core-js
25,418
Standard Library
JavaScript
zloirock
Denis Pushkarev
Gruntfile.js
JavaScript
module.exports = function(grunt){ grunt.loadNpmTasks('grunt-karma'); return grunt.initConfig({ karma: { unit: { configFile: './tests/karma.conf.js' }, continuous: { configFile: './tests/karma.conf.js', singleRun: true, browsers: ['PhantomJS'] } } }); };
zloirock/dtf
42
Date formatting
JavaScript
zloirock
Denis Pushkarev
dtf.min.js
JavaScript
/** * dtf 1.0.0 * https://github.com/zloirock/dtf * License: http://rock.mit-license.org * © 2015 Denis Pushkarev */ !function(){function n(a,c){try{Object.defineProperty(b,a,{configurable:!0,writable:!0,value:c})}catch(d){b[a]=c}}function o(a){return a>9?a:"0"+a}function p(a,b,e,n){function q(c){return a[b+c]()}var p=f[c.call(f,n)?n:g];return String(e).replace(d,function(a){switch(a){case"s":return q(h);case"ss":return o(q(h));case"m":return q(i);case"mm":return o(q(i));case"h":return q(j);case"hh":return o(q(j));case"D":return q(k);case"DD":return o(q(k));case"W":return p[0][q("Day")];case"N":return q(l)+1;case"NN":return o(q(l)+1);case"M":return p[2][q(l)];case"MM":return p[1][q(l)];case"Y":return q(m);case"YY":return o(q(m)%100)}return a})}function q(a,b){function c(a){for(var c=Array(7),d=b.months.split(","),f=0;7>f;)c[f]=d[f++].replace(e,"$"+a);return c}return f[a]=[b.weekdays.split(","),c(1),c(2)],r}var a="undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),b=Date.prototype,c={}.hasOwnProperty,d=/\b\w\w?\b/g,e=/:(.*)\|(.*)$/,f={},g="en",h="Seconds",i="Minutes",j="Hours",k="Date",l="Month",m="FullYear",r={format:function(a,b,c){return p(a,"get",b,c)},formatUTC:function(a,b,c){return p(a,"getUTC",b,c)},addLocale:q,locale:function(a){return c.call(f,a)?g=a:g},extend:function(){return n("format",function(a,b){return p(this,"get",a,b)}),n("formatUTC",function(a,b){return p(this,"getUTC",a,b)}),r}};q(g,{weekdays:"Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday",months:"January,February,March,April,May,June,July,August,September,October,November,December"}),q("ru",{weekdays:"Воскресенье,Понедельник,Вторник,Среда,Четверг,Пятница,Суббота",months:"Январ:я|ь,Феврал:я|ь,Март:а|,Апрел:я|ь,Ма:я|й,Июн:я|ь,Июл:я|ь,Август:а|,Сентябр:я|ь,Октябр:я|ь,Ноябр:я|ь,Декабр:я|ь"}),"undefined"!=typeof module&&module.exports?module.exports=r:"function"==typeof define&&define.amd?define(function(){return r}):a.dtf=r}();
zloirock/dtf
42
Date formatting
JavaScript
zloirock
Denis Pushkarev
index.js
JavaScript
/** * dtf 1.0.0 * https://github.com/zloirock/dtf * License: http://rock.mit-license.org * © 2015 Denis Pushkarev */ !function(){ var global = typeof self != 'undefined' && self.Math == Math ? self : Function('return this')(); var DateProto = Date.prototype; var has = {}.hasOwnProperty; var formatRegExp = /\b\w\w?\b/g; var flexioRegExp = /:(.*)\|(.*)$/; var locales = {}; var current = 'en'; var SECONDS = 'Seconds'; var MINUTES = 'Minutes'; var HOURS = 'Hours'; var DATE = 'Date'; var MONTH = 'Month'; var YEAR = 'FullYear'; function $define(key, value){ try { Object.defineProperty(DateProto, key, {configurable: true, writable: true, value: value}); } catch(e){ DateProto[key] = value; } } function lz(num){ return num > 9 ? num : '0' + num; } function $format(date, prefix, template, locale /* = current */){ var dict = locales[has.call(locales, locale) ? locale : current]; function get(unit){ return date[prefix + unit](); } return String(template).replace(formatRegExp, function(part){ switch(part){ case 's' : return get(SECONDS); // Seconds : 0-59 case 'ss' : return lz(get(SECONDS)); // Seconds : 00-59 case 'm' : return get(MINUTES); // Minutes : 0-59 case 'mm' : return lz(get(MINUTES)); // Minutes : 00-59 case 'h' : return get(HOURS); // Hours : 0-23 case 'hh' : return lz(get(HOURS)); // Hours : 00-23 case 'D' : return get(DATE); // Date : 1-31 case 'DD' : return lz(get(DATE)); // Date : 01-31 case 'W' : return dict[0][get('Day')]; // Day : Понедельник case 'N' : return get(MONTH) + 1; // Month : 1-12 case 'NN' : return lz(get(MONTH) + 1); // Month : 01-12 case 'M' : return dict[2][get(MONTH)]; // Month : Январь case 'MM' : return dict[1][get(MONTH)]; // Month : Января case 'Y' : return get(YEAR); // Year : 2014 case 'YY' : return lz(get(YEAR) % 100); // Year : 14 } return part; }); } function addLocale(lang, locale){ function split(index){ var result = Array(7); var months = locale.months.split(','); var i = 0; while(i < 7)result[i] = months[i++].replace(flexioRegExp, '$' + index); return result; } locales[lang] = [locale.weekdays.split(','), split(1), split(2)]; return dtf; } var dtf = { format: function(date, template, locale){ return $format(date, 'get', template, locale); }, formatUTC: function(date, template, locale){ return $format(date, 'getUTC', template, locale); }, addLocale: addLocale, locale: function(locale){ return has.call(locales, locale) ? current = locale : current; }, extend: function(){ $define('format', function(template, locale){ return $format(this, 'get', template, locale); }); $define('formatUTC', function(template, locale){ return $format(this, 'getUTC', template, locale); }); return dtf; } }; addLocale(current, { weekdays: 'Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday', months: 'January,February,March,April,May,June,July,August,September,October,November,December' }); addLocale('ru', { weekdays: 'Воскресенье,Понедельник,Вторник,Среда,Четверг,Пятница,Суббота', months: 'Январ:я|ь,Феврал:я|ь,Март:а|,Апрел:я|ь,Ма:я|й,Июн:я|ь,' + 'Июл:я|ь,Август:а|,Сентябр:я|ь,Октябр:я|ь,Ноябр:я|ь,Декабр:я|ь' }); /* eslint-disable no-undef */ // CommonJS export if(typeof module != 'undefined' && module.exports)module.exports = dtf; // RequireJS export else if(typeof define == 'function' && define.amd)define(function(){ return dtf; }); // Export to global object else global.dtf = dtf; }();
zloirock/dtf
42
Date formatting
JavaScript
zloirock
Denis Pushkarev