Gathering detailed insights and metrics for core-js
Gathering detailed insights and metrics for core-js
Gathering detailed insights and metrics for core-js
Gathering detailed insights and metrics for core-js
npm install core-js
3.39.0 - 2024.10.31
Published on 31 Oct 2024
3.38.1 - 2024.08.20
Published on 20 Aug 2024
3.38.0 - 2024.08.05
Published on 04 Aug 2024
3.37.1 - 2024.05.14
Published on 14 May 2024
3.37.0 - 2024.04.17
Published on 16 Apr 2024
3.36.1 - 2024.03.19
Published on 19 Mar 2024
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
24,596 Stars
6,412 Commits
1,658 Forks
253 Watching
6 Branches
126 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (99.8%)
TypeScript (0.15%)
HTML (0.04%)
Cumulative downloads
Total Downloads
Last day
-6%
7,347,683
Compared to previous day
Last week
3.7%
40,487,431
Compared to previous week
Last month
19.2%
162,659,437
Compared to previous month
Last year
-13.1%
1,709,560,222
Compared to previous year
No dependencies detected.
Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2024: promises, symbols, collections, iterators, typed arrays, many other features, ECMAScript proposals, some cross-platform WHATWG / W3C features and proposals like
URL
. You can load only required features or use it without global namespace pollution.
If you are looking for documentation for obsolete core-js@2
, please, check this branch.
core-js
isn't backed by a company, so the future of this project depends on you. Become a sponsor or a backer if you are interested in core-js
: Open Collective, Patreon, Boosty, Bitcoin ( bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz ), Alipay.
1import 'core-js/actual'; 2 3Promise.resolve(42).then(it => console.log(it)); // => 42 4 5Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5] 6 7[1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2] 8 9(function * (i) { while (true) yield i++; })(1) 10 .drop(1).take(5) 11 .filter(it => it % 2) 12 .map(it => it ** 2) 13 .toArray(); // => [9, 25] 14 15structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
You can load only required features:
1import 'core-js/actual/promise'; 2import 'core-js/actual/set'; 3import 'core-js/actual/iterator'; 4import 'core-js/actual/array/from'; 5import 'core-js/actual/array/flat-map'; 6import 'core-js/actual/structured-clone'; 7 8Promise.resolve(42).then(it => console.log(it)); // => 42 9 10Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5] 11 12[1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2] 13 14(function * (i) { while (true) yield i++; })(1) 15 .drop(1).take(5) 16 .filter(it => it % 2) 17 .map(it => it ** 2) 18 .toArray(); // => [9, 25] 19 20structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
Or use it without global namespace pollution:
1import Promise from 'core-js-pure/actual/promise'; 2import Set from 'core-js-pure/actual/set'; 3import Iterator from 'core-js-pure/actual/iterator'; 4import from from 'core-js-pure/actual/array/from'; 5import flatMap from 'core-js-pure/actual/array/flat-map'; 6import structuredClone from 'core-js-pure/actual/structured-clone'; 7 8Promise.resolve(42).then(it => console.log(it)); // => 42 9 10from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5] 11 12flatMap([1, 2], it => [it, it]); // => [1, 1, 2, 2] 13 14Iterator.from(function * (i) { while (true) yield i++; }(1)) 15 .drop(1).take(5) 16 .filter(it => it % 2) 17 .map(it => it ** 2) 18 .toArray(); // => [9, 25] 19 20structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
globalThis
Array.prototype.includes
Array.prototype.flat
/ Array.prototype.flatMap
Array
find from lastArray
by copyArray
groupingArrayBuffer.prototype.transfer
and friendsIterator
helpersObject.values
/ Object.entries
Object.fromEntries
Object.getOwnPropertyDescriptors
Object.prototype.hasOwnProperty
String
paddingString.prototype.matchAll
String.prototype.replaceAll
String.prototype.trimStart
/ String.prototype.trimEnd
RegExp
s
(dotAll
) flagRegExp
named capture groupsPromise.allSettled
Promise.any
Promise.prototype.finally
Promise.try
Promise.withResolvers
Symbol.asyncIterator
for asynchronous iterationSymbol.prototype.description
JSON.stringify
Set
methods1// global version 2npm install --save core-js@3.39.0 3// version without global namespace pollution 4npm install --save core-js-pure@3.39.0 5// bundled global version 6npm install --save core-js-bundle@3.39.0
Or you can use core-js
from CDN.
postinstall
message⬆The core-js
project needs your help, so the package shows a message about it after installation. If it causes problems for you, you can disable it:
1ADBLOCK=true npm install 2// or 3DISABLE_OPENCOLLECTIVE=true npm install 4// or 5npm install --loglevel silent
You can import only-required-for-you polyfills, like in the examples at the top of README.md
. Available CommonJS entry points for all polyfilled methods / constructors and namespaces. Just some examples:
1// polyfill all `core-js` features, including early-stage proposals: 2import "core-js"; 3// or: 4import "core-js/full"; 5// polyfill all actual features - stable ES, web standards and stage 3 ES proposals: 6import "core-js/actual"; 7// polyfill only stable features - ES and web standards: 8import "core-js/stable"; 9// polyfill only stable ES features: 10import "core-js/es"; 11 12// if you want to polyfill `Set`: 13// all `Set`-related features, with early-stage ES proposals: 14import "core-js/full/set"; 15// stable required for `Set` ES features, features from web standards and stage 3 ES proposals: 16import "core-js/actual/set"; 17// stable required for `Set` ES features and features from web standards 18// (DOM collections iterator in this case): 19import "core-js/stable/set"; 20// only stable ES features required for `Set`: 21import "core-js/es/set"; 22// the same without global namespace pollution: 23import Set from "core-js-pure/full/set"; 24import Set from "core-js-pure/actual/set"; 25import Set from "core-js-pure/stable/set"; 26import Set from "core-js-pure/es/set"; 27 28// if you want to polyfill just the required methods: 29import "core-js/full/set/intersection"; 30import "core-js/actual/array/find-last"; 31import "core-js/stable/queue-microtask"; 32import "core-js/es/array/from"; 33 34// polyfill iterator helpers proposal: 35import "core-js/proposals/iterator-helpers"; 36// polyfill all stage 2+ proposals: 37import "core-js/stage/2";
[!TIP] The usage of the
/actual/
namespace is recommended since it includes all actual JavaScript features and does not include unstable early-stage proposals that are available mainly for experiments.
[!WARNING]
- The
modules
path is an internal API, does not inject all required dependencies and can be changed in minor or patch releases. Use it only for a custom build and/or if you know what are you doing.- If you use
core-js
with the extension of native objects, recommended to load allcore-js
modules at the top of the entry point of your application, otherwise, you can have conflicts.
- For example, Google Maps use their own
Symbol.iterator
, conflicting withArray.from
,URLSearchParams
and / or something else fromcore-js
, see related issues.- Such conflicts are also resolvable by discovering and manually adding each conflicting entry from
core-js
.core-js
is extremely modular and uses a lot of very tiny modules, because of that for usage in browsers bundle upcore-js
instead of a usage loader for each file, otherwise, you will have hundreds of requests.
In the pure
version, we can't pollute prototypes of native constructors. Because of that, prototype methods transformed into static methods like in examples above. But with transpilers, we can use one more trick - bind operator and virtual methods. Special for that, available /virtual/
entry points. Example:
1import fill from 'core-js-pure/actual/array/virtual/fill'; 2import findIndex from 'core-js-pure/actual/array/virtual/find-index'; 3 4Array(10)::fill(0).map((a, b) => b * b)::findIndex(it => it && !(it % 8)); // => 4
[!WARNING] The bind operator is an early-stage ECMAScript proposal and usage of this syntax can be dangerous.
core-js
is integrated with babel
and is the base for polyfilling-related babel
features:
@babel/polyfill
⬆@babel/polyfill
IS just the import of stable core-js
features and regenerator-runtime
for generators and async functions, so if you load @babel/polyfill
- you load the global version of core-js
without ES proposals.
Now it's deprecated in favor of separate inclusion of required parts of core-js
and regenerator-runtime
and, for preventing breaking changes, left on core-js@2
.
As a full equal of @babel/polyfill
, you can use this:
1import 'core-js/stable'; 2import 'regenerator-runtime/runtime';
@babel/preset-env
⬆@babel/preset-env
has useBuiltIns
option, which optimizes working with the global version of core-js
. With useBuiltIns
option, you should also set corejs
option to the used version of core-js
, like corejs: '3.39'
.
[!IMPORTANT] Recommended to specify used minor
core-js
version, likecorejs: '3.39'
, instead ofcorejs: 3
, since withcorejs: 3
will not be injected modules which were added in minorcore-js
releases.
useBuiltIns: 'entry'
replaces imports of core-js
to import only required for a target environment modules. So, for example,1import 'core-js/stable';
with chrome 71
target will be replaced just to:
1import 'core-js/modules/es.array.unscopables.flat'; 2import 'core-js/modules/es.array.unscopables.flat-map'; 3import 'core-js/modules/es.object.from-entries'; 4import 'core-js/modules/web.immediate';
It works for all entry points of global version of core-js
and their combinations, for example for
1import 'core-js/es'; 2import 'core-js/proposals/set-methods'; 3import 'core-js/full/set/map';
with chrome 71
target you will have as the result:
1import 'core-js/modules/es.array.unscopables.flat'; 2import 'core-js/modules/es.array.unscopables.flat-map'; 3import 'core-js/modules/es.object.from-entries'; 4import 'core-js/modules/esnext.set.difference'; 5import 'core-js/modules/esnext.set.intersection'; 6import 'core-js/modules/esnext.set.is-disjoint-from'; 7import 'core-js/modules/esnext.set.is-subset-of'; 8import 'core-js/modules/esnext.set.is-superset-of'; 9import 'core-js/modules/esnext.set.map'; 10import 'core-js/modules/esnext.set.symmetric-difference'; 11import 'core-js/modules/esnext.set.union';
useBuiltIns: 'usage'
adds to the top of each file import of polyfills for features used in this file and not supported by target environments, so for:1// first file: 2let set = new Set([1, 2, 3]);
1// second file: 2let array = Array.of(1, 2, 3);
if the target contains an old environment like IE 11
we will have something like:
1// first file: 2import 'core-js/modules/es.array.iterator'; 3import 'core-js/modules/es.object.to-string'; 4import 'core-js/modules/es.set'; 5 6var set = new Set([1, 2, 3]);
1// second file: 2import 'core-js/modules/es.array.of'; 3 4var array = Array.of(1, 2, 3);
By default, @babel/preset-env
with useBuiltIns: 'usage'
option only polyfills stable features, but you can enable polyfilling of proposals by the proposals
option, as corejs: { version: '3.39', proposals: true }
.
[!IMPORTANT] In the case of
useBuiltIns: 'usage'
, you should not addcore-js
imports by yourself, they will be added automatically.
@babel/runtime
⬆@babel/runtime
with corejs: 3
option simplifies work with the core-js-pure
. It automatically replaces the usage of modern features from the JS standard library to imports from the version of core-js
without global namespace pollution, so instead of:
1import from from 'core-js-pure/stable/array/from'; 2import flat from 'core-js-pure/stable/array/flat'; 3import Set from 'core-js-pure/stable/set'; 4import Promise from 'core-js-pure/stable/promise'; 5 6from(new Set([1, 2, 3, 2, 1])); 7flat([1, [2, 3], [4, [5]]], 2); 8Promise.resolve(32).then(x => console.log(x));
you can write just:
1Array.from(new Set([1, 2, 3, 2, 1])); 2[1, [2, 3], [4, [5]]].flat(2); 3Promise.resolve(32).then(x => console.log(x));
By default, @babel/runtime
only polyfills stable features, but like in @babel/preset-env
, you can enable polyfilling of proposals by proposals
option, as corejs: { version: 3, proposals: true }
.
[!WARNING] If you use
@babel/preset-env
and@babel/runtime
together, usecorejs
option only in one place since it's duplicate functionality and will cause conflicts.
Fast JavaScript transpiler swc
contains integration with core-js
, that optimizes work with the global version of core-js
. Like @babel/preset-env
, it has 2 modes: usage
and entry
, but usage
mode still works not so well as in babel
. Example of configuration in .swcrc
:
1{ 2 "env": { 3 "targets": "> 0.25%, not dead", 4 "mode": "entry", 5 "coreJs": "3.39" 6 } 7}
By default, core-js
sets polyfills only when they are required. That means that core-js
checks if a feature is available and works correctly or not and if it has no problems, core-js
uses native implementation.
But sometimes core-js
feature detection could be too strict for your case. For example, Promise
constructor requires the support of unhandled rejection tracking and @@species
.
Sometimes we could have an inverse problem - a knowingly broken environment with problems not covered by core-js
feature detection.
For those cases, we could redefine this behavior for certain polyfills:
1const configurator = require('core-js/configurator'); 2 3configurator({ 4 useNative: ['Promise'], // polyfills will be used only if natives are completely unavailable 5 usePolyfill: ['Array.from', 'String.prototype.padEnd'], // polyfills will be used anyway 6 useFeatureDetection: ['Map', 'Set'], // default behavior 7}); 8 9require('core-js/actual');
It does not work with some features. Also, if you change the default behavior, even core-js
internals may not work correctly.
For some cases could be useful to exclude some core-js
features or generate a polyfill for target engines. You could use core-js-builder
package for that.
core-js
tries to support all possible JS engines and environments with ES3 support. Some features have a higher lower bar - for example, some accessors can properly work only from ES5, promises require a way to set a microtask or a task, etc.
However, I have no possibility to test core-js
absolutely everywhere - for example, testing in IE7- and some other ancient was stopped. The list of definitely supported engines you can see in the compatibility table by the link below. Write if you have issues or questions with the support of any engine.
core-js
project provides (as core-js-compat
package) all required data about the necessity of core-js
modules, entry points, and tools for work with it - it's useful for integration with tools like babel
or swc
. If you wanna help, you could take a look at the related section of CONTRIBUTING.md
. The visualization of compatibility data and the browser tests runner is available here, the example:
core-js(-pure)
core-js(-pure)/es
Modules es.object.assign
, es.object.create
, es.object.define-getter
, es.object.define-property
, es.object.define-properties
, es.object.define-setter
, es.object.entries
, es.object.freeze
, es.object.from-entries
, es.object.get-own-property-descriptor
, es.object.get-own-property-descriptors
, es.object.get-own-property-names
, es.object.get-prototype-of
, es.object.group-by
, es.object.has-own
, es.object.is
, es.object.is-extensible
, es.object.is-frozen
, es.object.is-sealed
, es.object.keys
, es.object.lookup-setter
, es.object.lookup-getter
, es.object.prevent-extensions
, es.object.proto
, es.object.to-string
, es.object.seal
, es.object.set-prototype-of
, es.object.values
.
1class Object { 2 toString(): string; // ES2015+ fix: @@toStringTag support 3 __defineGetter__(property: PropertyKey, getter: Function): void; 4 __defineSetter__(property: PropertyKey, setter: Function): void; 5 __lookupGetter__(property: PropertyKey): Function | void; 6 __lookupSetter__(property: PropertyKey): Function | void; 7 __proto__: Object | null; // required a way setting of prototype - will not in IE10-, it's for modern engines like Deno 8 static assign(target: Object, ...sources: Array<Object>): Object; 9 static create(prototype: Object | null, properties?: { [property: PropertyKey]: PropertyDescriptor }): Object; 10 static defineProperties(object: Object, properties: { [property: PropertyKey]: PropertyDescriptor })): Object; 11 static defineProperty(object: Object, property: PropertyKey, attributes: PropertyDescriptor): Object; 12 static entries(object: Object): Array<[string, mixed]>; 13 static freeze(object: any): any; 14 static fromEntries(iterable: Iterable<[key, value]>): Object; 15 static getOwnPropertyDescriptor(object: any, property: PropertyKey): PropertyDescriptor | void; 16 static getOwnPropertyDescriptors(object: any): { [property: PropertyKey]: PropertyDescriptor }; 17 static getOwnPropertyNames(object: any): Array<string>; 18 static getPrototypeOf(object: any): Object | null; 19 static groupBy(items: Iterable, callbackfn: (value: any, index: number) => key): { [key]: Array<mixed> }; 20 static hasOwn(object: object, key: PropertyKey): boolean; 21 static is(value1: any, value2: any): boolean; 22 static isExtensible(object: any): boolean; 23 static isFrozen(object: any): boolean; 24 static isSealed(object: any): boolean; 25 static keys(object: any): Array<string>; 26 static preventExtensions(object: any): any; 27 static seal(object: any): any; 28 static setPrototypeOf(target: any, prototype: Object | null): any; // required __proto__ - IE11+ 29 static values(object: any): Array<mixed>; 30}
core-js(-pure)/es|stable|actual|full/object
core-js(-pure)/es|stable|actual|full/object/assign
core-js(-pure)/es|stable|actual|full/object/is
core-js(-pure)/es|stable|actual|full/object/set-prototype-of
core-js(-pure)/es|stable|actual|full/object/get-prototype-of
core-js(-pure)/es|stable|actual|full/object/create
core-js(-pure)/es|stable|actual|full/object/define-property
core-js(-pure)/es|stable|actual|full/object/define-properties
core-js(-pure)/es|stable|actual|full/object/get-own-property-descriptor
core-js(-pure)/es|stable|actual|full/object/get-own-property-descriptors
core-js(-pure)/es|stable|actual|full/object/group-by
core-js(-pure)/es|stable|actual|full/object/has-own
core-js(-pure)/es|stable|actual|full/object/keys
core-js(-pure)/es|stable|actual|full/object/values
core-js(-pure)/es|stable|actual|full/object/entries
core-js(-pure)/es|stable|actual|full/object/get-own-property-names
core-js(-pure)/es|stable|actual|full/object/freeze
core-js(-pure)/es|stable|actual|full/object/from-entries
core-js(-pure)/es|stable|actual|full/object/seal
core-js(-pure)/es|stable|actual|full/object/prevent-extensions
core-js/es|stable|actual|full/object/proto
core-js(-pure)/es|stable|actual|full/object/is-frozen
core-js(-pure)/es|stable|actual|full/object/is-sealed
core-js(-pure)/es|stable|actual|full/object/is-extensible
core-js/es|stable|actual|full/object/to-string
core-js(-pure)/es|stable|actual|full/object/define-getter
core-js(-pure)/es|stable|actual|full/object/define-setter
core-js(-pure)/es|stable|actual|full/object/lookup-getter
core-js(-pure)/es|stable|actual|full/object/lookup-setter
Examples:
1let foo = { q: 1, w: 2 };
2let bar = { e: 3, r: 4 };
3let baz = { t: 5, y: 6 };
4Object.assign(foo, bar, baz); // => foo = { q: 1, w: 2, e: 3, r: 4, t: 5, y: 6 }
5
6Object.is(NaN, NaN); // => true
7Object.is(0, -0); // => false
8Object.is(42, 42); // => true
9Object.is(42, '42'); // => false
10
11function Parent() { /* empty */ }
12function Child() { /* empty */ }
13Object.setPrototypeOf(Child.prototype, Parent.prototype);
14new Child() instanceof Child; // => true
15new Child() instanceof Parent; // => true
16
17({
18 [Symbol.toStringTag]: 'Foo',
19}).toString(); // => '[object Foo]'
20
21Object.keys('qwe'); // => ['0', '1', '2']
22Object.getPrototypeOf('qwe') === String.prototype; // => true
23
24Object.values({ a: 1, b: 2, c: 3 }); // => [1, 2, 3]
25Object.entries({ a: 1, b: 2, c: 3 }); // => [['a', 1], ['b', 2], ['c', 3]]
26
27for (let [key, value] of Object.entries({ a: 1, b: 2, c: 3 })) {
28 console.log(key); // => 'a', 'b', 'c'
29 console.log(value); // => 1, 2, 3
30}
31
32// Shallow object cloning with prototype and descriptors:
33let copy = Object.create(Object.getPrototypeOf(object), Object.getOwnPropertyDescriptors(object));
34// Mixin:
35Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
36
37const map = new Map([['a', 1], ['b', 2]]);
38Object.fromEntries(map); // => { a: 1, b: 2 }
39
40class Unit {
41 constructor(id) {
42 this.id = id;
43 }
44 toString() {
45 return `unit${ this.id }`;
46 }
47}
48
49const units = new Set([new Unit(101), new Unit(102)]);
50
51Object.fromEntries(units.entries()); // => { unit101: Unit { id: 101 }, unit102: Unit { id: 102 } }
52
53Object.hasOwn({ foo: 42 }, 'foo'); // => true
54Object.hasOwn({ foo: 42 }, 'bar'); // => false
55Object.hasOwn({}, 'toString'); // => false
56
57Object.groupBy([1, 2, 3, 4, 5], it => it % 2); // => { 1: [1, 3, 5], 0: [2, 4] }
Modules es.function.name
, es.function.has-instance
. Just ES5: es.function.bind
.
1class Function { 2 name: string; 3 bind(thisArg: any, ...args: Array<mixed>): Function; 4 @@hasInstance(value: any): boolean; 5}
core-js/es|stable|actual|full/function
core-js/es|stable|actual|full/function/name
core-js/es|stable|actual|full/function/has-instance
core-js(-pure)/es|stable|actual|full/function/bind
core-js(-pure)/es|stable|actual|full/function/virtual/bind
1(function foo() { /* empty */ }).name; // => 'foo' 2 3console.log.bind(console, 42)(43); // => 42 43
Modules es.aggregate-error
, es.aggregate-error.cause
, es.error.cause
, es.error.to-string
.
1class [ 2 Error, 3 EvalError, 4 RangeError, 5 ReferenceError, 6 SyntaxError, 7 TypeError, 8 URIError, 9 WebAssembly.CompileError, 10 WebAssembly.LinkError, 11 WebAssembly.RuntimeError, 12] { 13 constructor(message: string, { cause: any }): %Error%; 14} 15 16class AggregateError extends Error { 17 constructor(errors: Iterable, message?: string, { cause: any }?): AggregateError; 18 errors: Array<any>; 19 message: string; 20 cause: any; 21} 22 23class Error { 24 toString(): string; // different fixes 25}
core-js(-pure)/es|stable|actual|full/aggregate-error
core-js/es|stable|actual|full/error
core-js/es|stable|actual|full/error/constructor
core-js/es|stable|actual|full/error/to-string
1const error1 = new TypeError('Error 1'); 2const error2 = new TypeError('Error 2'); 3const aggregate = new AggregateError([error1, error2], 'Collected errors'); 4aggregate.errors[0] === error1; // => true 5aggregate.errors[1] === error2; // => true 6 7const cause = new TypeError('Something wrong'); 8const error = new TypeError('Here explained what`s wrong', { cause }); 9error.cause === cause; // => true 10 11Error.prototype.toString.call({ message: 1, name: 2 }) === '2: 1'; // => true
Modules es.array.from
, es.array.is-array
, es.array.of
, es.array.copy-within
, es.array.fill
, es.array.find
, es.array.find-index
, es.array.find-last
, es.array.find-last-index
, es.array.iterator
, es.array.includes
, es.array.push
, es.array.slice
, es.array.join
, es.array.unshift
, es.array.index-of
, es.array.last-index-of
, es.array.every
, es.array.some
, es.array.for-each
, es.array.map
, es.array.filter
, es.array.reduce
, es.array.reduce-right
, es.array.reverse
, es.array.sort
, es.array.flat
, es.array.flat-map
, es.array.unscopables.flat
, es.array.unscopables.flat-map
, es.array.at
, es.array.to-reversed
, es.array.to-sorted
, es.array.to-spliced
, es.array.with
.
1class Array { 2 at(index: int): any; 3 concat(...args: Array<mixed>): Array<mixed>; // with adding support of @@isConcatSpreadable and @@species 4 copyWithin(target: number, start: number, end?: number): this; 5 entries(): Iterator<[index, value]>; 6 every(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): boolean; 7 fill(value: any, start?: number, end?: number): this; 8 filter(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): Array<mixed>; // with adding support of @@species 9 find(callbackfn: (value: any, index: number, target: any) => boolean), thisArg?: any): any; 10 findIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; 11 findLast(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): any; 12 findLastIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; 13 flat(depthArg?: number = 1): Array<mixed>; 14 flatMap(mapFn: (value: any, index: number, target: any) => any, thisArg: any): Array<mixed>; 15 forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg?: any): void; 16 includes(searchElement: any, from?: number): boolean; 17 indexOf(searchElement: any, from?: number): number; 18 join(separator: string = ','): string; 19 keys(): Iterator<index>; 20 lastIndexOf(searchElement: any, from?: number): number; 21 map(mapFn: (value: any, index: number, target: any) => any, thisArg?: any): Array<mixed>; // with adding support of @@species 22 push(...args: Array<mixed>): uint; 23 reduce(callbackfn: (memo: any, value: any, index: number, target: any) => any, initialValue?: any): any; 24 reduceRight(callbackfn: (memo: any, value: any, index: number, target: any) => any, initialValue?: any): any; 25 reverse(): this; // Safari 12.0 bug fix 26 slice(start?: number, end?: number): Array<mixed>; // with adding support of @@species 27 splice(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>; // with adding support of @@species 28 some(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): boolean; 29 sort(comparefn?: (a: any, b: any) => number): this; // with modern behavior like stable sort 30 toReversed(): Array<mixed>; 31 toSpliced(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>; 32 toSorted(comparefn?: (a: any, b: any) => number): Array<mixed>; 33 unshift(...args: Array<mixed>): uint; 34 values(): Iterator<value>; 35 with(index: includes, value: any): Array<mixed>; 36 @@iterator(): Iterator<value>; 37 @@unscopables: { [newMethodNames: string]: true }; 38 static from(items: Iterable | ArrayLike, mapFn?: (value: any, index: number) => any, thisArg?: any): Array<mixed>; 39 static isArray(value: any): boolean; 40 static of(...args: Array<mixed>): Array<mixed>; 41} 42 43class Arguments { 44 @@iterator(): Iterator<value>; // available only in core-js methods 45}
core-js(-pure)/es|stable|actual|full/array
core-js(-pure)/es|stable|actual|full/array/from
core-js(-pure)/es|stable|actual|full/array/of
core-js(-pure)/es|stable|actual|full/array/is-array
core-js(-pure)/es|stable|actual|full/array(/virtual)/at
core-js(-pure)/es|stable|actual|full/array(/virtual)/concat
core-js(-pure)/es|stable|actual|full/array(/virtual)/copy-within
core-js(-pure)/es|stable|actual|full/array(/virtual)/entries
core-js(-pure)/es|stable|actual|full/array(/virtual)/every
core-js(-pure)/es|stable|actual|full/array(/virtual)/fill
core-js(-pure)/es|stable|actual|full/array(/virtual)/filter
core-js(-pure)/es|stable|actual|full/array(/virtual)/find
core-js(-pure)/es|stable|actual|full/array(/virtual)/find-index
core-js(-pure)/es|stable|actual|full/array(/virtual)/find-last
core-js(-pure)/es|stable|actual|full/array(/virtual)/find-last-index
core-js(-pure)/es|stable|actual|full/array(/virtual)/flat
core-js(-pure)/es|stable|actual|full/array(/virtual)/flat-map
core-js(-pure)/es|stable|actual|full/array(/virtual)/for-each
core-js(-pure)/es|stable|actual|full/array(/virtual)/includes
core-js(-pure)/es|stable|actual|full/array(/virtual)/index-of
core-js(-pure)/es|stable|actual|full/array(/virtual)/iterator
core-js(-pure)/es|stable|actual|full/array(/virtual)/join
core-js(-pure)/es|stable|actual|full/array(/virtual)/keys
core-js(-pure)/es|stable|actual|full/array(/virtual)/last-index-of
core-js(-pure)/es|stable|actual|full/array(/virtual)/map
core-js(-pure)/es|stable|actual|full/array(/virtual)/push
core-js(-pure)/es|stable|actual|full/array(/virtual)/reduce
core-js(-pure)/es|stable|actual|full/array(/virtual)/reduce-right
core-js(-pure)/es|stable|actual|full/array(/virtual)/reverse
core-js(-pure)/es|stable|actual|full/array(/virtual)/slice
core-js(-pure)/es|stable|actual|full/array(/virtual)/some
core-js(-pure)/es|stable|actual|full/array(/virtual)/sort
core-js(-pure)/es|stable|actual|full/array(/virtual)/splice
core-js(-pure)/es|stable|actual|full/array(/virtual)/to-reversed
core-js(-pure)/es|stable|actual|full/array(/virtual)/to-sorted
core-js(-pure)/es|stable|actual|full/array(/virtual)/to-spliced
core-js(-pure)/es|stable|actual|full/array(/virtual)/unshift
core-js(-pure)/es|stable|actual|full/array(/virtual)/values
core-js(-pure)/es|stable|actual|full/array(/virtual)/with
1Array.from(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] 2Array.from({ 0: 1, 1: 2, 2: 3, length: 3 }); // => [1, 2, 3] 3Array.from('123', Number); // => [1, 2, 3] 4Array.from('123', it => it * it); // => [1, 4, 9] 5 6Array.of(1); // => [1] 7Array.of(1, 2, 3); // => [1, 2, 3] 8 9let array = ['a', 'b', 'c']; 10 11for (let value of array) console.log(value); // => 'a', 'b', 'c' 12for (let value of array.values()) console.log(value); // => 'a', 'b', 'c' 13for (let key of array.keys()) console.log(key); // => 0, 1, 2 14for (let [key, value] of array.entries()) { 15 console.log(key); // => 0, 1, 2 16 console.log(value); // => 'a', 'b', 'c' 17} 18 19function isOdd(value) { 20 return value % 2; 21} 22[4, 8, 15, 16, 23, 42].find(isOdd); // => 15 23[4, 8, 15, 16, 23, 42].findIndex(isOdd); // => 2 24[1, 2, 3, 4].findLast(isOdd); // => 3 25[1, 2, 3, 4].findLastIndex(isOdd); // => 2 26 27Array(5).fill(42); // => [42, 42, 42, 42, 42] 28 29[1, 2, 3, 4, 5].copyWithin(0, 3); // => [4, 5, 3, 4, 5] 30 31[1, 2, 3].includes(2); // => true 32[1, 2, 3].includes(4); // => false 33[1, 2, 3].includes(2, 2); // => false 34 35[NaN].indexOf(NaN); // => -1 36[NaN].includes(NaN); // => true 37Array(1).indexOf(undefined); // => -1 38Array(1).includes(undefined); // => true 39 40[1, [2, 3], [4, 5]].flat(); // => [1, 2, 3, 4, 5] 41[1, [2, [3, [4]]], 5].flat(); // => [1, 2, [3, [4]], 5] 42[1, [2, [3, [4]]], 5].flat(3); // => [1, 2, 3, 4, 5] 43 44[{ a: 1, b: 2 }, { a: 3, b: 4 }, { a: 5, b: 6 }].flatMap(it => [it.a, it.b]); // => [1, 2, 3, 4, 5, 6] 45 46[1, 2, 3].at(1); // => 2 47[1, 2, 3].at(-1); // => 3 48 49const sequence = [1, 2, 3]; 50sequence.toReversed(); // => [3, 2, 1] 51sequence; // => [1, 2, 3] 52 53const initialArray = [1, 2, 3, 4]; 54initialArray.toSpliced(1, 2, 5, 6, 7); // => [1, 5, 6, 7, 4] 55initialArray; // => [1, 2, 3, 4] 56 57const outOfOrder = [3, 1, 2]; 58outOfOrder.toSorted(); // => [1, 2, 3] 59outOfOrder; // => [3, 1, 2] 60 61const correctionNeeded = [1, 1, 3]; 62correctionNeeded.with(1, 2); // => [1, 2, 3] 63correctionNeeded; // => [1, 1, 3]
Modules es.iterator.constructor
, es.iterator.drop
, es.iterator.every
, es.iterator.filter
, es.iterator.find
, es.iterator.flat-map
, es.iterator.for-each
, es.iterator.from
, es.iterator.map
, es.iterator.reduce
, es.iterator.some
, es.iterator.take
, es.iterator.to-array
1class Iterator { 2 static from(iterable: Iterable<any> | Iterator<any>): Iterator<any>; 3 drop(limit: uint): Iterator<any>; 4 every(callbackfn: (value: any, counter: uint) => boolean): boolean; 5 filter(callbackfn: (value: any, counter: uint) => boolean): Iterator<any>; 6 find(callbackfn: (value: any, counter: uint) => boolean)): any; 7 flatMap(callbackfn: (value: any, counter: uint) => Iterable<any> | Iterator<any>): Iterator<any>; 8 forEach(callbackfn: (value: any, counter: uint) => void): void; 9 map(callbackfn: (value: any, counter: uint) => any): Iterator<any>; 10 reduce(callbackfn: (memo: any, value: any, counter: uint) => any, initialValue: any): any; 11 some(callbackfn: (value: any, counter: uint) => boolean): boolean; 12 take(limit: uint): Iterator<any>; 13 toArray(): Array<any>; 14 @@toStringTag: 'Iterator' 15}
core-js(-pure)/es|stable|actual|full/iterator
core-js(-pure)/es|stable|actual|full/iterator/drop
core-js(-pure)/es|stable|actual|full/iterator/every
core-js(-pure)/es|stable|actual|full/iterator/filter
core-js(-pure)/es|stable|actual|full/iterator/find
core-js(-pure)/es|stable|actual|full/iterator/flat-map
core-js(-pure)/es|stable|actual|full/iterator/for-each
core-js(-pure)/es|stable|actual|full/iterator/from
core-js(-pure)/es|stable|actual|full/iterator/map
core-js(-pure)/es|stable|actual|full/iterator/reduce
core-js(-pure)/es|stable|actual|full/iterator/some
core-js(-pure)/es|stable|actual|full/iterator/take
core-js(-pure)/es|stable|actual|full/iterator/to-array
1[1, 2, 3, 4, 5, 6, 7].values() 2 .drop(1) 3 .take(5) 4 .filter(it => it % 2) 5 .map(it => it ** 2) 6 .toArray(); // => [9, 25] 7 8Iterator.from({ 9 next: () => ({ done: Math.random() > 0.9, value: Math.random() * 10 | 0 }), 10}).toArray(); // => [7, 6, 3, 0, 2, 8]
[!WARNING]
- For preventing prototype pollution, in the
pure
version, new%IteratorPrototype%
methods are not added to the real%IteratorPrototype%
, they are available only on wrappers - instead of[].values().map(fn)
useIterator.from([]).map(fn)
.
The main part of String
features: modules es.string.from-code-point
, es.string.raw
, es.string.iterator
, es.string.split
, es.string.code-point-at
, es.string.ends-with
, es.string.includes
, es.string.repeat
, es.string.pad-start
, es.string.pad-end
, es.string.starts-with
, es.string.trim
, es.string.trim-start
, es.string.trim-end
, es.string.match-all
, es.string.replace-all
, es.string.at-alternative
, es.string.is-well-formed
, es.string.to-well-formed
.
Adding support of well-known symbols @@match
, @@replace
, @@search
and @@split
and direct .exec
calls to related String
methods, modules es.string.match
, es.string.replace
, es.string.search
and es.string.split
.
Annex B methods. Modules es.string.anchor
, es.string.big
, es.string.blink
, es.string.bold
, es.string.fixed
, es.string.fontcolor
, es.string.fontsize
, es.string.italics
, es.string.link
, es.string.small
, es.string.strike
, es.string.sub
, es.string.sup
, es.string.substr
, es.escape
and es.unescape
.
RegExp
features: modules es.regexp.constructor
, es.regexp.dot-all
, es.regexp.flags
, es.regexp.sticky
and es.regexp.test
.
1class String { 2 static fromCodePoint(...codePoints: Array<number>): string; 3 static raw({ raw: Array<string> }, ...substitutions: Array<string>): string; 4 at(index: int): string; 5 includes(searchString: string, position?: number): boolean; 6 startsWith(searchString: string, position?: number): boolean; 7 endsWith(searchString: string, position?: number): boolean; 8 repeat(count: number): string; 9 padStart(length: number, fillStr?: string = ' '): string; 10 padEnd(length: number, fillStr?: string = ' '): string; 11 codePointAt(pos: number): number | void; 12 match(template: any): any; // ES2015+ fix for support @@match 13 matchAll(regexp: RegExp): Iterator; 14 replace(template: any, replacer: any): any; // ES2015+ fix for support @@replace 15 replaceAll(searchValue: string | RegExp, replaceString: string | (searchValue, index, this) => string): string; 16 search(template: any): any; // ES2015+ fix for support @@search 17 split(template: any, limit?: int): Array<string>;; // ES2015+ fix for support @@split, some fixes for old engines 18 trim(): string; 19 trimLeft(): string; 20 trimRight(): string; 21 trimStart(): string; 22 trimEnd(): string; 23 isWellFormed(): boolean; 24 toWellFormed(): string; 25 anchor(name: string): string; 26 big(): string; 27 blink(): string; 28 bold(): string; 29 fixed(): string; 30 fontcolor(color: string): string; 31 fontsize(size: any): string; 32 italics(): string; 33 link(url: string): string; 34 small(): string; 35 strike(): string; 36 sub(): string; 37 substr(start: int, length?: int): string; 38 sup(): string; 39 @@iterator(): Iterator<characters>; 40} 41 42class RegExp { 43 // support of sticky (`y`) flag, dotAll (`s`) flag, named capture groups, can alter flags 44 constructor(pattern: RegExp | string, flags?: string): RegExp; 45 exec(): Array<string | undefined> | null; // IE8 fixes 46 test(string: string): boolean; // delegation to `.exec` 47 toString(): string; // ES2015+ fix - generic 48 @@match(string: string): Array | null; 49 @@matchAll(string: string): Iterator; 50 @@replace(string: string, replaceValue: Function | string): string; 51 @@search(string: string): number; 52 @@split(string: string, limit: number): Array<string>; 53 readonly attribute dotAll: boolean; // IE9+ 54 readonly attribute flags: string; // IE9+ 55 readonly attribute sticky: boolean; // IE9+ 56} 57 58function escape(string: string): string; 59function unescape(string: string): string;
core-js(-pure)/es|stable|actual|full/string
core-js(-pure)/es|stable|actual|full/string/from-code-point
core-js(-pure)/es|stable|actual|full/string/raw
core-js/es|stable|actual|full/string/match
core-js/es|stable|actual|full/string/replace
core-js/es|stable|actual|full/string/search
core-js/es|stable|actual|full/string/split
core-js(-pure)/es|stable|actual/string(/virtual)/at
core-js(-pure)/es|stable|actual|full/string(/virtual)/code-point-at
core-js(-pure)/es|stable|actual|full/string(/virtual)/ends-with
core-js(-pure)/es|stable|actual|full/string(/virtual)/includes
core-js(-pure)/es|stable|actual|full/string(/virtual)/starts-with
core-js(-pure)/es|stable|actual|full/string(/virtual)/match-all
core-js(-pure)/es|stable|actual|full/string(/virtual)/pad-start
core-js(-pure)/es|stable|actual|full/string(/virtual)/pad-end
core-js(-pure)/es|stable|actual|full/string(/virtual)/repeat
core-js(-pure)/es|stable|actual|full/string(/virtual)/replace-all
core-js(-pure)/es|stable|actual|full/string(/virtual)/trim
core-js(-pure)/es|stable|actual|full/string(/virtual)/trim-start
core-js(-pure)/es|stable|actual|full/string(/virtual)/trim-end
core-js(-pure)/es|stable|actual|full/string(/virtual)/trim-left
core-js(-pure)/es|stable|actual|full/string(/virtual)/trim-right
core-js(-pure)/es|stable|actual|full/string(/virtual)/is-well-formed
core-js(-pure)/es|stable|actual|full/string(/virtual)/to-well-formed
core-js(-pure)/es|stable|actual|full/string(/virtual)/anchor
core-js(-pure)/es|stable|actual|full/string(/virtual)/big
core-js(-pure)/es|stable|actual|full/string(/virtual)/blink
core-js(-pure)/es|stable|actual|full/string(/virtual)/bold
core-js(-pure)/es|stable|actual|full/string(/virtual)/fixed
core-js(-pure)/es|stable|actual|full/string(/virtual)/fontcolor
core-js(-pure)/es|stable|actual|full/string(/virtual)/fontsize
core-js(-pure)/es|stable|actual|full/string(/virtual)/italics
core-js(-pure)/es|stable|actual|full/string(/virtual)/link
core-js(-pure)/es|stable|actual|full/string(/virtual)/small
core-js(-pure)/es|stable|actual|full/string(/virtual)/strike
core-js(-pure)/es|stable|actual|full/string(/virtual)/sub
core-js(-pure)/es|stable|actual|full/string(/virtual)/substr
core-js(-pure)/es|stable|actual|full/string(/virtual)/sup
core-js(-pure)/es|stable|actual|full/string(/virtual)/iterator
core-js/es|stable|actual|full/regexp
core-js/es|stable|actual|full/regexp/constructor
core-js/es|stable|actual|full/regexp/dot-all
core-js(-pure)/es|stable|actual|full/regexp/flags
core-js/es|stable|actual|full/regexp/sticky
core-js/es|stable|actual|full/regexp/test
core-js/es|stable|actual|full/regexp/to-string
core-js/es|stable|actual|full/escape
core-js/es|stable|actual|full/unescape
1for (let value of 'a𠮷b') { 2 console.log(value); // => 'a', '𠮷', 'b' 3} 4 5'foobarbaz'.includes('bar'); // => true 6'foobarbaz'.includes('bar', 4); // => false 7'foobarbaz'.startsWith('foo'); // => true 8'foobarbaz'.startsWith('bar', 3); // => true 9'foobarbaz'.endsWith('baz'); // => true 10'foobarbaz'.endsWith('bar', 6); // => true 11 12'string'.repeat(3); // => 'stringstringstring' 13 14'hello'.padStart(10); // => ' hello' 15'hello'.padStart(10, '1234'); // => '12341hello' 16'hello'.padEnd(10); // => 'hello ' 17'hello'.padEnd(10, '1234'); // => 'hello12341' 18 19'𠮷'.codePointAt(0); // => 134071 20String.fromCodePoint(97, 134071, 98); // => 'a𠮷b' 21 22let name = 'Bob'; 23String.raw`Hi\n${ name }!`; // => 'Hi\\nBob!' (ES2015 template string syntax) 24String.raw({ raw: 'test' }, 0, 1, 2); // => 't0e1s2t' 25 26'foo'.bold(); // => '<b>foo</b>' 27'bar'.anchor('a"b'); // => '<a name="a"b">bar</a>' 28'baz'.link('https://example.com'); // => '<a href="https://example.com">baz</a>' 29 30RegExp('.', 's').test('\n'); // => true 31RegExp('.', 's').dotAll; // => true 32 33RegExp('foo:(?<foo>\\w+),bar:(?<bar>\\w+)').exec('foo:abc,bar:def').groups; // => { foo: 'abc', bar: 'def' } 34 35'foo:abc,bar:def'.replace(RegExp('foo:(?<foo>\\w+),bar:(?<bar>\\w+)'), '$<bar>,$<foo>'); // => 'def,abc' 36 37// eslint-disable-next-line regexp/no-useless-flag -- example 38RegExp(/./g, 'm'); // => /./m 39 40/foo/.flags; // => '' 41/foo/gi.flags; // => 'gi' 42 43RegExp('foo', 'y').sticky; // => true 44 45const text = 'First line\nSecond line'; 46const regex = RegExp('(?<index>\\S+) line\\n?', 'y'); 47 48regex.exec(text).groups.index; // => 'First' 49regex.exec(text).groups.index; // => 'Second' 50regex.exec(text); // => null 51 52'foo'.match({ [Symbol.match]: () => 1 }); // => 1 53'foo'.replace({ [Symbol.replace]: () => 2 }); // => 2 54'foo'.search({ [Symbol.search]: () => 3 }); // => 3 55'foo'.split({ [Symbol.split]: () => 4 }); // => 4 56 57RegExp.prototype.toString.call({ source: 'foo', flags: 'bar' }); // => '/foo/bar' 58 59' hello '.trimLeft(); // => 'hello ' 60' hello '.trimRight(); // => ' hello' 61' hello '.trimStart(); // => 'hello ' 62' hello '.trimEnd(); // => ' hello' 63 64for (let { groups: { number, letter } } of '1111a2b3cccc'.matchAll(RegExp('(?<number>\\d)(?<letter>\\D)', 'g'))) { 65 console.log(number, letter); // => 1 a, 2 b, 3 c 66} 67 68'Test abc test test abc test.'.replaceAll('abc', 'foo'); // -> 'Test foo test test foo test.' 69 70'abc'.at(1); // => 'b' 71'abc'.at(-1); // => 'c' 72 73'a💩b'.isWellFormed(); // => true 74'a\uD83Db'.isWellFormed(); // => false 75 76'a💩b'.toWellFormed(); // => 'a💩b' 77'a\uD83Db'.toWellFormed(); // => 'a�b'
Module es.number.constructor
. Number
constructor support binary and octal literals, example:
1Number('0b1010101'); // => 85 2Number('0o7654321'); // => 2054353
Modules es.number.epsilon
, es.number.is-finite
, es.number.is-integer
, es.number.is-nan
, es.number.is-safe-integer
, es.number.max-safe-integer
, es.number.min-safe-integer
, es.number.parse-float
, es.number.parse-int
, es.number.to-exponential
, es.number.to-fixed
, es.number.to-precision
, es.parse-int
, es.parse-float
.
1class Number { 2 constructor(value: any): number; 3 toExponential(digits: number): string; 4 toFixed(digits: number): string; 5 toPrecision(precision: number): string; 6 static isFinite(number: any): boolean; 7 static isNaN(number: any): boolean; 8 static isInteger(number: any): boolean; 9 static isSafeInteger(number: any): boolean; 10 static parseFloat(string: string): number; 11 static parseInt(string: string, radix?: number = 10): number; 12 static EPSILON: number; 13 static MAX_SAFE_INTEGER: number; 14 static MIN_SAFE_INTEGER: number; 15} 16 17function parseFloat(string: string): number; 18function parseInt(string: string, radix?: number = 10): number;
core-js(-pure)/es|stable|actual|full/number
core-js(-pure)/es|stable|actual|full/number/constructor
core-js(-pure)/es|stable|actual|full/number/is-finite
core-js(-pure)/es|stable|actual|full/number/is-nan
core-js(-pure)/es|stable|actual|full/number/is-integer
core-js(-pure)/es|stable|actual|full/number/is-safe-integer
core-js(-pure)/es|stable|actual|full/number/parse-float
core-js(-pure)/es|stable|actual|full/number/parse-int
core-js(-pure)/es|stable|actual|full/number/epsilon
core-js(-pure)/es|stable|actual|full/number/max-safe-integer
core-js(-pure)/es|stable|actual|full/number/min-safe-integer
core-js(-pure)/es|stable|actual|full/number(/virtual)/to-exponential
core-js(-pure)/es|stable|actual|full/number(/virtual)/to-fixed
core-js(-pure)/es|stable|actual|full/number(/virtual)/to-precision
core-js(-pure)/es|stable|actual|full/parse-float
core-js(-pure)/es|stable|actual|full/parse-int
Modules es.math.acosh
, es.math.asinh
, es.math.atanh
, es.math.cbrt
, es.math.clz32
, es.math.cosh
, es.math.expm1
, es.math.fround
, es.math.hypot
, es.math.imul
, es.math.log10
, es.math.log1p
, es.math.log2
, es.math.sign
, es.math.sinh
, es.math.tanh
, es.math.trunc
.
1namespace Math { 2 acosh(number: number): number; 3 asinh(number: number): number; 4 atanh(number: number): number; 5 cbrt(number: number): number; 6 clz32(number: number): number; 7 cosh(number: number): number; 8 expm1(number: number): number; 9 fround(number: number): number; 10 hypot(...args: Array<number>): number; 11 imul(number1: number, number2: number): number; 12 log1p(number: number): number; 13 log10(number: number): number; 14 log2(number: number): number; 15 sign(number: number): 1 | -1 | 0 | -0 | NaN; 16 sinh(number: number): number; 17 tanh(number: number): number; 18 trunc(number: number): number; 19}
core-js(-pure)/es|stable|actual|full/math
core-js(-pure)/es|stable|actual|full/math/acosh
core-js(-pure)/es|stable|actual|full/math/asinh
core-js(-pure)/es|stable|actual|full/math/atanh
core-js(-pure)/es|stable|actual|full/math/cbrt
core-js(-pure)/es|stable|actual|full/math/clz32
core-js(-pure)/es|stable|actual|full/math/cosh
core-js(-pure)/es|stable|actual|full/math/expm1
core-js(-pure)/es|stable|actual|full/math/fround
core-js(-pure)/es|stable|actual|full/math/hypot
core-js(-pure)/es|stable|actual|full/math/imul
core-js(-pure)/es|stable|actual|full/math/log1p
core-js(-pure)/es|stable|actual|full/math/log10
core-js(-pure)/es|stable|actual|full/math/log2
core-js(-pure)/es|stable|actual|full/math/sign
core-js(-pure)/es|stable|actual|full/math/sinh
core-js(-pure)/es|stable|actual|full/math/tanh
core-js(-pure)/es|stable|actual|full/math/trunc
Modules es.date.to-string
, ES5 features with fixes: es.date.now
, es.date.to-iso-string
, es.date.to-json
and es.date.to-primitive
.
Annex B methods. Modules es.date.get-year
, es.date.set-year
and es.date.to-gmt-string
.
1class Date {
2 getYear(): int;
3 setYear(year: int): number;
4 toGMTString(): string;
5 toISOString(): string;
6 toJSON(): string;
7 toString(): string;
8 @@toPrimitive(hint: 'default' | 'number' | 'string'): string | number;
9 static now(): number;
10}
core-js/es|stable|actual|full/date
core-js/es|stable|actual|full/date/to-string
core-js(-pure)/es|stable|actual|full/date/now
core-js(-pure)/es|stable|actual|full/date/get-year
core-js(-pure)/es|stable|actual|full/date/set-year
core-js(-pure)/es|stable|actual|full/date/to-gmt-string
core-js(-pure)/es|stable|actual|full/date/to-iso-string
core-js(-pure)/es|stable|actual|full/date/to-json
core-js(-pure)/es|stable|actual|full/date/to-primitive
1new Date(NaN).toString(); // => 'Invalid Date'
Modules es.promise
, es.promise.all-settled
, es.promise.any
, es.promise.finally
, es.promise.try
and es.promise.with-resolvers
.
1class Promise { 2 constructor(executor: (resolve: Function, reject: Function) => void): Promise; 3 then(onFulfilled: Function, onRejected: Function): Promise; 4 catch(onRejected: Function): Promise; 5 finally(onFinally: Function): Promise; 6 static all(iterable: Iterable): Promise; 7 static allSettled(iterable: Iterable): Promise; 8 static any(promises: Iterable): Promise; 9 static race(iterable: Iterable): Promise; 10 static reject(r: any): Promise; 11 static resolve(x: any): Promise; 12 static try(callbackfn: Function, ...args?: Array<mixed>): Promise; 13 static withResolvers(): { promise: Promise, resolve: function, reject: function }; 14}
core-js(-pure)/es|stable|actual|full/promise
core-js(-pure)/es|stable|actual|full/promise/all-settled
core-js(-pure)/es|stable|actual|full/promise/any
core-js(-pure)/es|stable|actual|full/promise/finally
core-js(-pure)/es|stable|actual|full/promise/try
core-js(-pure)/es|stable|actual|full/promise/with-resolvers
Basic example:
1/* eslint-disable promise/prefer-await-to-callbacks -- example */ 2function sleepRandom(time) { 3 return new Promise((resolve, reject) => { 4 setTimeout(resolve, time * 1e3, 0 | Math.random() * 1e3); 5 }); 6} 7 8console.log('Run'); // => Run 9sleepRandom(5).then(result => { 10 console.log(result); // => 869, after 5 sec. 11 return sleepRandom(10); 12}).then(result => { 13 console.log(result); // => 202, after 10 sec. 14}).then(() => { 15 console.log('immediately after'); // => immediately after 16 throw new Error('Irror!'); 17}).then(() => { 18 console.log('will not be displayed'); 19}).catch(error => console.log(error)); // => => Error: Irror!
Promise.resolve
and Promise.reject
example:
1/* eslint-disable promise/prefer-await-to-callbacks -- example */ 2Promise.resolve(42).then(x => console.log(x)); // => 42 3Promise.reject(42).catch(error => console.log(error)); // => 42 4 5Promise.resolve($.getJSON('/data.json')); // => ES promise
Promise#finally
example:
1Promise.resolve(42).finally(() => console.log('You will see it anyway')); 2 3Promise.reject(42).finally(() => console.log('You will see it anyway'));
Promise.all
example:
1Promise.all([ 2 'foo', 3 sleepRandom(5), 4 sleepRandom(15), 5 sleepRandom(10), // after 15 sec: 6]).then(x => console.log(x)); // => ['foo', 956, 85, 382]
Promise.race
example:
1/* eslint-disable promise/prefer-await-to-callbacks -- example */ 2function timeLimit(promise, time) { 3 return Promise.race([promise, new Promise((resolve, reject) => { 4 setTimeout(reject, time * 1e3, new Error(`Await > ${ time } sec`)); 5 })]); 6} 7 8timeLimit(sleepRandom(5), 10).then(x => console.log(x)); // => 853, after 5 sec. 9timeLimit(sleepRandom(15), 10).catch(error => console.log(error)); // Error: Await > 10 sec
Promise.allSettled
example:
1Promise.allSettled([
2 Promise.resolve(1),
3 Promise.reject(2),
4 Promise.resolve(3),
5]).then(console.log); // => [{ value: 1, status: 'fulfilled' }, { reason: 2, status: 'rejected' }, { value: 3, status: 'fulfilled' }]
Promise.any
example:
1Promise.any([ 2 Promise.resolve(1), 3 Promise.reject(2), 4 Promise.resolve(3), 5]).then(console.log); // => 1 6 7Promise.any([ 8 Promise.reject(1), 9 Promise.reject(2), 10 Promise.reject(3), 11]).catch(({ errors }) => console.log(errors)); // => [1, 2, 3]
Promise.try
examples:
1/* eslint-disable promise/prefer-await-to-callbacks -- example */ 2Promise.try(() => 42).then(it => console.log(`Promise, resolved as ${ it }`)); 3 4Promise.try(() => { throw new Error('42'); }).catch(error => console.log(`Promise, rejected as ${ error }`)); 5 6Promise.try(async () => 42).then(it => console.log(`Promise, resolved as ${ it }`)); 7 8Promise.try(async () => { throw new Error('42'); }).catch(error => console.log(`Promise, rejected as ${ error }`)); 9 10Promise.try(it => it, 42).then(it => console.log(`Promise, resolved as ${ it }`));
Promise.withResolvers
examples:
1const d = Promise.withResolvers(); 2d.resolve(42); 3d.promise.then(console.log); // => 42
Example with async functions:
1let delay = time => new Promise(resolve => setTimeout(resolve, time)); 2 3async function sleepRandom(time) { 4 await delay(time * 1e3); 5 return 0 | Math.random() * 1e3; 6} 7 8async function sleepError(time, msg) { 9 await delay(time * 1e3); 10 throw new Error(msg); 11} 12 13(async () => { 14 try { 15 console.log('Run'); // => Run 16 console.log(await sleepRandom(5)); // => 936, after 5 sec. 17 let [a, b, c] = await Promise.all([ 18 sleepRandom(5), 19 sleepRandom(15), 20 sleepRandom(10), 21 ]); 22 console.log(a, b, c); // => 210 445 71, after 15 sec. 23 await sleepError(5, 'Error!'); 24 console.log('Will not be displayed'); 25 } catch (error) { 26 console.log(error); // => Error: 'Error!', after 5 sec. 27 } 28})();
In Node.js, like in native implementation, available events unhandledRejection
and rejectionHandled
:
1process.on('unhandledRejection', (reason, promise) => console.log('unhandled', reason, promise)); 2process.on('rejectionHandled', promise => console.log('handled', promise)); 3 4let promise = Promise.reject(42); 5// unhandled 42 [object Promise] 6 7// eslint-disable-next-line promise/prefer-await-to-then -- example 8setTimeout(() => promise.catch(() => { /* empty */ }), 1e3); 9// handled [object Promise]
In a browser on rejection, by default, you will see notify in the console, or you can add a custom handler and a handler on handling unhandled, example:
1globalThis.addEventListener('unhandledrejection', e => console.log('unhandled', e.reason, e.promise));
2globalThis.addEventListener('rejectionhandled', e => console.log('handled', e.reason, e.promise));
3// or
4globalThis.onunhandledrejection = e => console.log('unhandled', e.reason, e.promise);
5globalThis.onrejectionhandled = e => console.log('handled', e.reason, e.promise);
6
7let promise = Promise.reject(42);
8// => unhandled 42 [object Promise]
9
10// eslint-disable-next-line promise/prefer-await-to-then -- example
11setTimeout(() => promise.catch(() => { /* empty */ }), 1e3);
12// => handled 42 [object Promise]
Modules es.symbol
, es.symbol.async-iterator
, es.symbol.description
, es.symbol.has-instance
, es.symbol.is-concat-spreadable
, es.symbol.iterator
, es.symbol.match
, es.symbol.replace
, es.symbol.search
, es.symbol.species
, es.symbol.split
, es.symbol.to-primitive
, es.symbol.to-string-tag
, es.symbol.unscopables
, es.math.to-string-tag
.
1class Symbol { 2 constructor(description?): symbol; 3 readonly attribute description: string | void; 4 static asyncIterator: @@asyncIterator; 5 static hasInstance: @@hasInstance; 6 static isConcatSpreadable: @@isConcatSpreadable; 7 static iterator: @@iterator; 8 static match: @@match; 9 static replace: @@replace; 10 static search: @@search; 11 static species: @@species; 12 static split: @@split; 13 static toPrimitive: @@toPrimitive; 14 static toStringTag: @@toStringTag; 15 static unscopables: @@unscopables; 16 static for(key: string): symbol; 17 static keyFor(sym: symbol): string; 18 static useSimple(): void; 19 static useSetter(): void; 20} 21 22class Object { 23 static getOwnPropertySymbols(object: any): Array<symbol>; 24}
Also wrapped some methods for correct work with Symbol
polyfill.
1class Object { 2 static create(prototype: Object | null, properties?: { [property: PropertyKey]: PropertyDescriptor }): Object; 3 static defineProperties(object: Object, properties: { [property: PropertyKey]: PropertyDescriptor })): Object; 4 static defineProperty(object: Object, property: PropertyKey, attributes: PropertyDescriptor): Object; 5 static getOwnPropertyDescriptor(object: any, property: PropertyKey): PropertyDescriptor | void; 6 static getOwnPropertyNames(object: any): Array<string>; 7 propertyIsEnumerable(key: PropertyKey): boolean; 8}
core-js(-pure)/es|stable|actual|full/symbol
core-js(-pure)/es|stable|actual|full/symbol/async-iterator
core-js/es|stable|actual|full/symbol/description
core-js(-pure)/es|stable|actual|full/symbol/has-instance
core-js(-pure)/es|stable|actual|full/symbol/is-concat-spreadable
core-js(-pure)/es|stable|actual|full/symbol/iterator
core-js(-pure)/es|stable|actual|full/symbol/match
core-js(-pure)/es|stable|actual|full/symbol/replace
core-js(-pure)/es|stable|actual|full/symbol/search
core-js(-pure)/es|stable|actual|full/symbol/species
core-js(-pure)/es|stable|actual|full/symbol/split
core-js(-pure)/es|stable|actual|full/symbol/to-primitive
core-js(-pure)/es|stable|actual|full/symbol/to-string-tag
core-js(-pure)/es|stable|actual|full/symbol/unscopables
core-js(-pure)/es|stable|actual|full/symbol/for
core-js(-pure)/es|stable|actual|full/symbol/key-for
core-js(-pure)/es|stable|actual|full/object/get-own-property-symbols
core-js(-pure)/es|stable|actual|full/math/to-string-tag
1let Person = (() => { 2 let NAME = Symbol('name'); 3 return class { 4 constructor(name) { 5 this[NAME] = name; 6 } 7 getName() { 8 return this[NAME]; 9 } 10 }; 11})(); 12 13let person = new Person('Vasya'); 14console.log(person.getName()); // => 'Vasya' 15console.log(person.name); // => undefined 16console.log(person[Symbol('name')]); // => undefined, symbols are uniq 17for (let key in person) console.log(key); // => nothing, symbols are not enumerable
Symbol.for
& Symbol.keyFor
example:
1let symbol = Symbol.for('key');
2symbol === Symbol.for('key'); // true
3Symbol.keyFor(symbol); // 'key'
Example with methods for getting own object keys:
1let object = { a: 1 };
2Object.defineProperty(object, 'b', { value: 2 });
3object[Symbol('c')] = 3;
4Object.keys(object); // => ['a']
5Object.getOwnPropertyNames(object); // => ['a', 'b']
6Object.getOwnPropertySymbols(object); // => [Symbol(c)]
7Reflect.ownKeys(object); // => ['a', 'b', Symbol(c)]
1Symbol('foo').description; // => 'foo' 2// eslint-disable-next-line symbol-description -- example 3Symbol().description; // => undefined
Symbol
polyfill:⬆Symbol
returns an object.Symbol.for
and Symbol.keyFor
can't be polyfilled cross-realm.Symbol
polyfill defines a setter in Object.prototype
. For this reason, an uncontrolled creation of symbols can cause a memory leak and the in
operator is not working correctly with Symbol
polyfill: Symbol() in {} // => true
.You can disable defining setters in Object.prototype
. Example:
1Symbol.useSimple(); 2let symbol1 = Symbol('symbol1'); 3let object1 = {}; 4object1[symbol1] = true; 5for (let key in object1) console.log(key); // => 'Symbol(symbol1)_t.qamkg9f3q', w/o native Symbol 6 7Symbol.useSetter(); 8let symbol2 = Symbol('symbol2'); 9let object2 = {}; 10object2[symbol2] = true; 11for (let key in object2) console.log(key); // nothing
core-js
does not add setters to Object.prototype
for well-known symbols for correct work something like Symbol.iterator in foo
. It can cause problems with their enumerability.localStorage
).core-js
uses native collections in most cases, just fixes methods / constructor, if it's required, and in the old environment uses fast polyfill (O(1) lookup).
Modules es.map
and es.map.group-by
.
1class Map { 2 constructor(iterable?: Iterable<[key, value]>): Map; 3 clear(): void; 4 delete(key: any): boolean; 5 forEach(callbackfn: (value: any, key: any, target: any) => void, thisArg: any): void; 6 get(key: any): any; 7 has(key: any): boolean; 8 set(key: any, val: any): this; 9 values(): Iterator<value>; 10 keys(): Iterator<key>; 11 entries(): Iterator<[key, value]>; 12 @@iterator(): Iterator<[key, value]>; 13 readonly attribute size: number; 14 static groupBy(items: Iterable, callbackfn: (value: any, index: number) => key): Map<key, Array<mixed>>; 15}
core-js(-pure)/es|stable|actual|full/map
core-js(-pure)/es|stable|actual|full/map/group-by
1let array = [1]; 2 3let map = new Map([['a', 1], [42, 2]]); 4map.set(array, 3).set(true, 4); 5 6console.log(map.size); // => 4 7console.log(map.has(array)); // => true 8console.log(map.has([1])); // => false 9console.log(map.get(array)); // => 3 10map.forEach((val, key) => { 11 console.log(val); // => 1, 2, 3, 4 12 console.log(key); // => 'a', 42, [1], true 13}); 14map.delete(array); 15console.log(map.size); // => 3 16console.log(map.get(array)); // => undefined 17console.log(Array.from(map)); // => [['a', 1], [42, 2], [true, 4]] 18 19map = new Map([['a', 1], ['b', 2], ['c', 3]]); 20 21for (let [key, value] of map) { 22 console.log(key); // => 'a', 'b', 'c' 23 console.log(value); // => 1, 2, 3 24} 25for (let value of map.values()) console.log(value); // => 1, 2, 3 26for (let key of map.keys()) console.log(key); // => 'a', 'b', 'c' 27for (let [key, value] of map.entries()) { 28 console.log(key); // => 'a', 'b', 'c' 29 console.log(value); // => 1, 2, 3 30} 31 32map = Map.groupBy([1, 2, 3, 4, 5], it => it % 2); 33map.get(1); // => [1, 3, 5] 34map.get(0); // => [2, 4]
Modules es.set
, es.set.difference.v2
, es.set.intersection.v2
, es.set.is-disjoint-from.v2
, es.set.is-subset-of.v2
, es.set.is-superset-of.v2
, es.set.symmetric-difference.v2
, es.set.union.v2
1class Set { 2 constructor(iterable?: Iterable<value>): Set; 3 add(key: any): this; 4 clear(): void; 5 delete(key: any): boolean; 6 forEach((value: any, key: any, target: any) => void, thisArg: any): void; 7 has(key: any): boolean; 8 values(): Iterator<value>; 9 keys(): Iterator<value>; 10 entries(): Iterator<[value, value]>; 11 difference(other: SetLike<mixed>): Set; 12 intersection(other: SetLike<mixed>): Set; 13 isDisjointFrom(other: SetLike<mixed>): boolean; 14 isSubsetOf(other: SetLike<mixed>): boolean; 15 isSupersetOf(other: SetLike<mixed>): boolean; 16 symmetricDifference(other: SetLike<mixed>): Set; 17 union(other: SetLike<mixed>): Set; 18 @@iterator(): Iterator<value>; 19 readonly attribute size: number; 20}
core-js(-pure)/es|stable|actual|full/set
core-js(-pure)/es|stable|actual|full/set/difference
core-js(-pure)/es|stable|actual|full/set/intersection
core-js(-pure)/es|stable|actual|full/set/is-disjoint-from
core-js(-pure)/es|stable|actual|full/set/is-subset-of
core-js(-pure)/es|stable|actual|full/set/is-superset-of
core-js(-pure)/es|stable|actual|full/set/symmetric-difference
core-js(-pure)/es|stable|actual|full/set/union
1let set = new Set(['a', 'b', 'a', 'c']); 2set.add('d').add('b').add('e'); 3console.log(set.size); // => 5 4console.log(set.has('b')); // => true 5set.forEach(it => { 6 console.log(it); // => 'a', 'b', 'c', 'd', 'e' 7}); 8set.delete('b'); 9console.log(set.size); // => 4 10console.log(set.has('b')); // => false 11console.log(Array.from(set)); // => ['a', 'c', 'd', 'e'] 12 13set = new Set([1, 2, 3, 2, 1]); 14 15for (let value of set) console.log(value); // => 1, 2, 3 16for (let value of set.values()) console.log(value); // => 1, 2, 3 17for (let key of set.keys()) console.log(key); // => 1, 2, 3 18for (let [key, value] of set.entries()) { 19 console.log(key); // => 1, 2, 3 20 console.log(value); // => 1, 2, 3 21} 22 23new Set([1, 2, 3]).union(new Set([3, 4, 5])); // => Set {1, 2, 3, 4, 5} 24new Set([1, 2, 3]).intersection(new Set([3, 4, 5])); // => Set {3} 25new Set([1, 2, 3]).difference(new Set([3, 4, 5])); // => Set {1, 2} 26new Set([1, 2, 3]).symmetricDifference(new Set([3, 4, 5])); // => Set {1, 2, 4, 5} 27new Set([1, 2, 3]).isDisjointFrom(new Set([4, 5, 6])); // => true 28new Set([1, 2, 3]).isSubsetOf(new Set([5, 4, 3, 2, 1])); // => true 29new Set([5, 4, 3, 2, 1]).isSupersetOf(new Set([1, 2, 3])); // => true
Module es.weak-map
.
1class WeakMap { 2 constructor(iterable?: Iterable<[key, value]>): WeakMap; 3 delete(key: Object): boolean; 4 get(key: Object): any; 5 has(key: Object): boolean; 6 set(key: Object, val: any): this; 7}
core-js(-pure)/es|stable|actual|full/weak-map
1let a = [1]; 2let b = [2]; 3let c = [3]; 4 5let weakmap = new WeakMap([[a, 1], [b, 2]]); 6weakmap.set(c, 3).set(b, 4); 7console.log(weakmap.has(a)); // => true 8console.log(weakmap.has([1])); // => false 9console.log(weakmap.get(a)); // => 1 10weakmap.delete(a); 11console.log(weakmap.get(a)); // => undefined 12 13// Private properties store: 14let Person = (() => { 15 let names = new WeakMap(); 16 return class { 17 constructor(name) { 18 names.set(this, name); 19 } 20 getName() { 21 return names.get(this); 22 } 23 }; 24})(); 25 26let person = new Person('Vasya'); 27console.log(person.getName()); // => 'Vasya' 28for (let key in person) console.log(key); // => only 'getName'
Module es.weak-set
.
1class WeakSet { 2 constructor(iterable?: Iterable<value>): WeakSet; 3 add(key: Object): this; 4 delete(key: Object): boolean; 5 has(key: Object): boolean; 6}
core-js(-pure)/es|stable|actual|full/weak-set
1let a = [1]; 2let b = [2]; 3let c = [3]; 4 5let weakset = new WeakSet([a, b, a]); 6weakset.add(c).add(b).add(c); 7console.log(weakset.has(b)); // => true 8console.log(weakset.has([2])); // => false 9weakset.delete(b); 10console.log(weakset.has(b)); // => false
[!WARNING]
- Weak-collections polyfill stores values as hidden properties of keys. It works correctly and does not leak in most cases. However, it is desirable to store a collection longer than its keys.
- Native symbols as
WeakMap
keys can't be properly polyfilled without memory leaks.
Implementations and fixes for ArrayBuffer
, DataView
, Typed Arrays constructors, static and prototype methods. Typed arrays work only in environments with support descriptors (IE9+), ArrayBuffer
and DataView
should work anywhere.
Modules es.array-buffer.constructor
, es.array-buffer.is-view
, esnext.array-buffer.detached
, es.array-buffer.slice
, esnext.array-buffer.transfer
, esnext.array-buffer.transfer-to-fixed-length
es.data-view
, es.typed-array.int8-array
, es.typed-array.uint8-array
, es.typed-array.uint8-clamped-array
, es.typed-array.int16-array
, es.typed-array.uint16-array
, es.typed-array.int32-array
, es.typed-array.uint32-array
, es.typed-array.float32-array
, es.typed-array.float64-array
, es.typed-array.copy-within
, es.typed-array.every
, es.typed-array.fill
, es.typed-array.filter
, es.typed-array.find
, es.typed-array.find-index
, es.typed-array.find-last
, es.typed-array.find-last-index
, es.typed-array.for-each
, es.typed-array.from
, es.typed-array.includes
, es.typed-array.index-of
, es.typed-array.iterator
, es.typed-array.last-index-of
, es.typed-array.map
, es.typed-array.of
, es.typed-array.reduce
, es.typed-array.reduce-right
, es.typed-array.reverse
, es.typed-array.set
, es.typed-array.slice
, es.typed-array.some
, es.typed-array.sort
, es.typed-array.subarray
, es.typed-array.to-locale-string
, es.typed-array.to-string
, es.typed-array.at
, es.typed-array.to-reversed
, es.typed-array.to-sorted
, es.typed-array.with
.
1class ArrayBuffer { 2 constructor(length: any): ArrayBuffer; 3 readonly attribute byteLength: number; 4 readonly attribute detached: boolean; 5 slice(start: any, end: any): ArrayBuffer; 6 transfer(newLength?: number): ArrayBuffer; 7 transferToFixedLength(newLength?: number): ArrayBuffer; 8 static isView(arg: any): boolean; 9} 10 11class DataView { 12 constructor(buffer: ArrayBuffer, byteOffset?: number, byteLength?: number): DataView; 13 getInt8(offset: any): int8; 14 getUint8(offset: any): uint8 15 getInt16(offset: any, littleEndian?: boolean = false): int16; 16 getUint16(offset: any, littleEndian?: boolean = false): uint16; 17 getInt32(offset: any, littleEndian?: boolean = false): int32; 18 getUint32(offset: any, littleEndian?: boolean = false): uint32; 19 getFloat32(offset: any, littleEndian?: boolean = false): float32; 20 getFloat64(offset: any, littleEndian?: boolean = false): float64; 21 setInt8(offset: any, value: any): void; 22 setUint8(offset: any, value: any): void; 23 setInt16(offset: any, value: any, littleEndian?: boolean = false): void; 24 setUint16(offset: any, value: any, littleEndian?: boolean = false): void; 25 setInt32(offset: any, value: any, littleEndian?: boolean = false): void; 26 setUint32(offset: any, value: any, littleEndian?: boolean = false): void; 27 setFloat32(offset: any, value: any, littleEndian?: boolean = false): void; 28 setFloat64(offset: any, value: any, littleEndian?: boolean = false): void; 29 readonly attribute buffer: ArrayBuffer; 30 readonly attribute byteLength: number; 31 readonly attribute byteOffset: number; 32} 33 34class [ 35 Int8Array, 36 Uint8Array, 37 Uint8ClampedArray, 38 Int16Array, 39 Uint16Array, 40 Int32Array, 41 Uint32Array, 42 Float32Array, 43 Float64Array, 44] extends %TypedArray% { 45 constructor(length: number): %TypedArray%; 46 constructor(object: %TypedArray% | Iterable | ArrayLike): %TypedArray%; 47 constructor(buffer: ArrayBuffer, byteOffset?: number, length?: number): %TypedArray% 48} 49 50class %TypedArray% { 51 at(index: int): number; 52 copyWithin(target: number, start: number, end?: number): this; 53 entries(): Iterator<[index, value]>; 54 every(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): boolean; 55 fill(value: number, start?: number, end?: number): this; 56 filter(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): %TypedArray%; 57 find(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean), thisArg?: any): any; 58 findIndex(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; 59 findLast(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): any; 60 findLastIndex(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; 61 forEach(callbackfn: (value: number, index: number, target: %TypedArray%) => void, thisArg?: any): void; 62 includes(searchElement: any, from?: number): boolean; 63 indexOf(searchElement: any, from?: number): number; 64 join(separator: string = ','): string; 65 keys(): Iterator<index>; 66 lastIndexOf(searchElement: any, from?: number): number; 67 map(mapFn: (value: number, index: number, target: %TypedArray%) => number, thisArg?: any): %TypedArray%; 68 reduce(callbackfn: (memo: any, value: number, index: number, target: %TypedArray%) => any, initialValue?: any): any; 69 reduceRight(callbackfn: (memo: any, value: number, index: number, target: %TypedArray%) => any, initialValue?: any): any; 70 reverse(): this; 71 set(array: ArrayLike, offset?: number): void; 72 slice(start?: number, end?: number): %TypedArray%; 73 some(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): boolean; 74 sort(comparefn?: (a: number, b: number) => number): this; // with modern behavior like stable sort 75 subarray(begin?: number, end?: number): %TypedArray%; 76 toReversed(): %TypedArray%; 77 toSorted(comparefn?: (a: any, b: any) => number): %TypedArray%; 78 toString(): string; 79 toLocaleString(): string; 80 values(): Iterator<value>; 81 with(index: includes, value: any): %TypedArray%; 82 @@iterator(): Iterator<value>; 83 readonly attribute buffer: ArrayBuffer; 84 readonly attribute byteLength: number; 85 readonly attribute byteOffset: number; 86 readonly attribute length: number; 87 BYTES_PER_ELEMENT: number; 88 static from(items: Iterable | ArrayLike, mapFn?: (value: any, index: number) => any, thisArg?: any): %TypedArray%; 89 static of(...args: Array<mixed>): %TypedArray%; 90 static BYTES_PER_ELEMENT: number; 91}
core-js/es|stable|actual|full/array-buffer
core-js/es|stable|actual|full/array-buffer/constructor
core-js/es|stable|actual|full/array-buffer/is-view
core-js/es|stable|actual|full/array-buffer/detached
core-js/es|stable|actual|full/array-buffer/slice
core-js/es|stable|actual|full/array-buffer/transfer
core-js/es|stable|actual|full/array-buffer/transfer-to-fixed-length
core-js/es|stable|actual|full/data-view
core-js/es|stable|actual|full/typed-array
core-js/es|stable|actual|full/typed-array/int8-array
core-js/es|stable|actual|full/typed-array/uint8-array
core-js/es|stable|actual|full/typed-array/uint8-clamped-array
core-js/es|stable|actual|full/typed-array/int16-array
core-js/es|stable|actual|full/typed-array/uint16-array
core-js/es|stable|actual|full/typed-array/int32-array
core-js/es|stable|actual|full/typed-array/uint32-array
core-js/es|stable|actual|full/typed-array/float32-array
core-js/es|stable|actual|full/typed-array/float64-array
core-js/es|stable|actual|full/typed-array/at
core-js/es|stable|actual|full/typed-array/copy-within
core-js/es|stable|actual|full/typed-array/entries
core-js/es|stable|actual|full/typed-array/every
core-js/es|stable|actual|full/typed-array/fill
core-js/es|stable|actual|full/typed-array/filter
core-js/es|stable|actual|full/typed-array/find
core-js/es|stable|actual|full/typed-array/find-index
core-js/es|stable|actual|full/typed-array/find-last
core-js/es|stable|actual|full/typed-array/find-last-index
core-js/es|stable|actual|full/typed-array/for-each
core-js/es|stable|actual|full/typed-array/from
core-js/es|stable|actual|full/typed-array/includes
core-js/es|stable|actual|full/typed-array/index-of
core-js/es|stable|actual|full/typed-array/iterator
core-js/es|stable|actual|full/typed-array/join
core-js/es|stable|actual|full/typed-array/keys
core-js/es|stable|actual|full/typed-array/last-index-of
core-js/es|stable|actual|full/typed-array/map
core-js/es|stable|actual|full/typed-array/of
core-js/es|stable|actual|full/typed-array/reduce
core-js/es|stable|actual|full/typed-array/reduce-right
core-js/es|stable|actual|full/typed-array/reverse
core-js/es|stable|actual|full/typed-array/set
core-js/es|stable|actual|full/typed-array/slice
core-js/es|stable|actual|full/typed-array/some
core-js/es|stable|actual|full/typed-array/sort
core-js/es|stable|actual|full/typed-array/subarray
core-js/es|stable|actual|full/typed-array/to-locale-string
core-js/es|stable|actual|full/typed-array/to-reversed
core-js/es|stable|actual|full/typed-array/to-sorted
core-js/es|stable|actual|full/typed-array/to-string
core-js/es|stable|actual|full/typed-array/values
core-js/es|stable|actual|full/typed-array/with
1new Int32Array(4); // => [0, 0, 0, 0] 2new Uint8ClampedArray([1, 2, 3, 666]); // => [1, 2, 3, 255] 3new Float32Array(new Set([1, 2, 3, 2, 1])); // => [1, 2, 3] 4 5let buffer = new ArrayBuffer(8); 6let view = new DataView(buffer); 7view.setFloat64(0, 123.456, true); 8new Uint8Array(buffer.slice(4)); // => [47, 221, 94, 64] 9 10Int8Array.of(1, 1.5, 5.7, 745); // => [1, 1, 5, -23] 11Uint8Array.from([1, 1.5, 5.7, 745]); // => [1, 1, 5, 233] 12 13let typed = new Uint8Array([1, 2, 3]); 14 15let a = typed.slice(1); // => [2, 3] 16typed.buffer === a.buffer; // => false 17let b = typed.subarray(1); // => [2, 3] 18typed.buffer === b.buffer; // => true 19 20typed.filter(it => it % 2); // => [1, 3] 21typed.map(it => it * 1.5); // => [1, 3, 4] 22 23for (let value of typed) console.log(value); // => 1, 2, 3 24for (let value of typed.values()) console.log(value); // => 1, 2, 3 25for (let key of typed.keys()) console.log(key); // => 0, 1, 2 26for (let [key, value] of typed.entries()) { 27 console.log(key); // => 0, 1, 2 28 console.log(value); // => 1, 2, 3 29} 30 31new Int32Array([1, 2, 3]).at(1); // => 2 32new Int32Array([1, 2, 3]).at(-1); // => 3 33 34buffer = Int8Array.of(1, 2, 3, 4, 5, 6, 7, 8).buffer; 35console.log(buffer.byteLength); // => 8 36console.log(buffer.detached); // => false 37const newBuffer = buffer.transfer(4); 38console.log(buffer.byteLength); // => 0 39console.log(buffer.detached); // => true 40console.log(newBuffer.byteLength); // => 4 41console.log(newBuffer.detached); // => false 42console.log([...new Int8Array(newBuffer)]); // => [1, 2, 3, 4]
[!WARNING]
- Polyfills of Typed Arrays constructors work completely how they should work by the spec. Still, because of the internal usage of getters / setters on each instance, they are slow and consume significant memory. However, polyfills of Typed Arrays constructors are required mainly for old IE, all modern engines have native Typed Arrays constructors and require only fixes of constructors and polyfills of methods.
ArrayBuffer.prototype.{ transfer, transferToFixedLength }
polyfilled only in runtime with nativestructuredClone
withArrayBuffer
transfer orMessageChannel
support.
Modules es.reflect.apply
, es.reflect.construct
, es.reflect.define-property
, es.reflect.delete-property
, es.reflect.get
, es.reflect.get-own-property-descriptor
, es.reflect.get-prototype-of
, es.reflect.has
, es.reflect.is-extensible
, es.reflect.own-keys
, es.reflect.prevent-extensions
, es.reflect.set
, es.reflect.set-prototype-of
.
1namespace Reflect { 2 apply(target: Function, thisArgument: any, argumentsList: Array<mixed>): any; 3 construct(target: Function, argumentsList: Array<mixed>, newTarget?: Function): Object; 4 defineProperty(target: Object, propertyKey: PropertyKey, attributes: PropertyDescriptor): boolean; 5 deleteProperty(target: Object, propertyKey: PropertyKey): boolean; 6 get(target: Object, propertyKey: PropertyKey, receiver?: any): any; 7 getOwnPropertyDescriptor(target: Object, propertyKey: PropertyKey): PropertyDescriptor | void; 8 getPrototypeOf(target: Object): Object | null; 9 has(target: Object, propertyKey: PropertyKey): boolean; 10 isExtensible(target: Object): boolean; 11 ownKeys(target: Object): Array<string | symbol>; 12 preventExtensions(target: Object): boolean; 13 set(target: Object, propertyKey: PropertyKey, V: any, receiver?: any): boolean; 14 setPrototypeOf(target: Object, proto: Object | null): boolean; // required __proto__ - IE11+ 15}
core-js(-pure)/es|stable|actual|full/reflect
core-js(-pure)/es|stable|actual|full/reflect/apply
core-js(-pure)/es|stable|actual|full/reflect/construct
core-js(-pure)/es|stable|actual|full/reflect/define-property
core-js(-pure)/es|stable|actual|full/reflect/delete-property
core-js(-pure)/es|stable|actual|full/reflect/get
core-js(-pure)/es|stable|actual|full/reflect/get-own-property-descriptor
core-js(-pure)/es|stable|actual|full/reflect/get-prototype-of
core-js(-pure)/es|stable|actual|full/reflect/has
core-js(-pure)/es|stable|actual|full/reflect/is-extensible
core-js(-pure)/es|stable|actual|full/reflect/own-keys
core-js(-pure)/es|stable|actual|full/reflect/prevent-extensions
core-js(-pure)/es|stable|actual|full/reflect/set
core-js(-pure)/es|stable|actual|full/reflect/set-prototype-of
1let object = { a: 1 };
2Object.defineProperty(object, 'b', { value: 2 });
3object[Symbol('c')] = 3;
4Reflect.ownKeys(object); // => ['a', 'b', Symbol(c)]
5
6function C(a, b) {
7 this.c = a + b;
8}
9
10let instance = Reflect.construct(C, [20, 22]);
11instance.c; // => 42
Since JSON
object is missed only in very old engines like IE7-, core-js
does not provide a full JSON
polyfill, however, fix already existing implementations by the current standard, for example, well-formed JSON.stringify
. JSON
is also fixed in other modules - for example, Symbol
polyfill fixes JSON.stringify
for correct work with symbols.
Module es.json.to-string-tag
and es.json.stringify
.
1namespace JSON { 2 stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void; 3 @@toStringTag: 'JSON'; 4}
core-js(-pure)/es|stable|actual|full/json/stringify
core-js(-pure)/es|stable|actual|full/json/to-string-tag
1JSON.stringify({ 'ð ®·': ['\uDF06\uD834'] }); // => '{"ð ®·":["\\udf06\\ud834"]}'
Module es.global-this
.
1let globalThis: GlobalThisValue;
core-js(-pure)/es|stable|actual|full/global-this
1globalThis.Array === Array; // => true
core-js/stage/3
entry point contains only stage 3 proposals, core-js/stage/2.7
- stage 2.7 and stage 3, etc.
Finished (stage 4) proposals already marked in core-js
as stable ECMAScript, they are available in core-js/stable
and core-js/es
namespace, you can find them in related sections of the README. However, even for finished proposals, core-js
provides a way to include only features for a specific proposal like core-js/proposals/proposal-name
.
globalThis
⬆1let globalThis: GlobalThisValue;
core-js/proposals/global-this
1class Array { 2 at(index: int): any; 3} 4 5class String { 6 at(index: int): string; 7} 8 9class %TypedArray% { 10 at(index: int): number; 11}
core-js/proposals/relative-indexing-method
Array.prototype.includes
⬆1class Array { 2 includes(searchElement: any, from?: number): boolean; 3} 4 5class %TypedArray% { 6 includes(searchElement: any, from?: number): boolean; 7}
core-js/proposals/array-includes
Array.prototype.flat
/ Array.prototype.flatMap
⬆1class Array { 2 flat(depthArg?: number = 1): Array<mixed>; 3 flatMap(mapFn: (value: any, index: number, target: any) => any, thisArg: any): Array<mixed>; 4}
core-js/proposals/array-flat-map
1class Array { 2 findLast(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): any; 3 findLastIndex(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): uint; 4} 5 6class %TypedArray% { 7 findLast(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): any; 8 findLastIndex(callbackfn: (value: any, index: number, target: %TypedArray%) => boolean, thisArg?: any): uint; 9}
core-js/proposals/array-find-from-last
Array
by copy⬆1class Array { 2 toReversed(): Array<mixed>; 3 toSpliced(start?: number, deleteCount?: number, ...items: Array<mixed>): Array<mixed>; 4 toSorted(comparefn?: (a: any, b: any) => number): Array<mixed>; 5 with(index: includes, value: any): Array<mixed>; 6} 7 8class %TypedArray% { 9 toReversed(): %TypedArray%; 10 toSorted(comparefn?: (a: any, b: any) => number): %TypedArray%; 11 with(index: includes, value: any): %TypedArray%; 12}
core-js/proposals/change-array-by-copy-stage-4
core-js(-pure)/es|stable|actual|full/array(/virtual)/to-reversed
core-js(-pure)/es|stable|actual|full/array(/virtual)/to-sorted
core-js(-pure)/es|stable|actual|full/array(/virtual)/to-spliced
core-js(-pure)/es|stable|actual|full/array(/virtual)/with
core-js/es|stable|actual|full/typed-array/to-reversed
core-js/es|stable|actual|full/typed-array/to-sorted
core-js/es|stable|actual|full/typed-array/with
Array
grouping⬆1class Object {
2 static groupBy(items: Iterable, callbackfn: (value: any, index: number) => key): { [key]: Array<mixed> };
3}
4
5class Map {
6 static groupBy(items: Iterable, callbackfn: (value: any, index: number) => key): Map<key, Array<mixed>>;
7}
core-js/proposals/array-grouping-v2
ArrayBuffer.prototype.transfer
and friends⬆1class ArrayBuffer { 2 readonly attribute detached: boolean; 3 transfer(newLength?: number): ArrayBuffer; 4 transferToFixedLength(newLength?: number): ArrayBuffer; 5}
core-js/proposals/array-buffer-transfer
Iterator
helpers⬆1class Iterator { 2 static from(iterable: Iterable<any> | Iterator<any>): Iterator<any>; 3 drop(limit: uint): Iterator<any>; 4 every(callbackfn: (value: any, counter: uint) => boolean): boolean; 5 filter(callbackfn: (value: any, counter: uint) => boolean): Iterator<any>; 6 find(callbackfn: (value: any, counter: uint) => boolean)): any; 7 flatMap(callbackfn: (value: any, counter: uint) => Iterable<any> | Iterator<any>): Iterator<any>; 8 forEach(callbackfn: (value: any, counter: uint) => void): void; 9 map(callbackfn: (value: any, counter: uint) => any): Iterator<any>; 10 reduce(callbackfn: (memo: any, value: any, counter: uint) => any, initialValue: any): any; 11 some(callbackfn: (value: any, counter: uint) => boolean): boolean; 12 take(limit: uint): Iterator<any>; 13 toArray(): Array<any>; 14 @@toStringTag: 'Iterator' 15}
core-js/proposals/iterator-helpers-stage-3-2
Object.values
/ Object.entries
⬆1class Object { 2 static entries(object: Object): Array<[string, mixed]>; 3 static values(object: any): Array<mixed>; 4}
core-js/proposals/object-values-entries
Object.fromEntries
⬆1class Object { 2 static fromEntries(iterable: Iterable<[key, value]>): Object; 3}
core-js/proposals/object-from-entries
Object.getOwnPropertyDescriptors
⬆1class Object { 2 static getOwnPropertyDescriptors(object: any): { [property: PropertyKey]: PropertyDescriptor }; 3}
core-js/proposals/object-getownpropertydescriptors
Object.prototype.hasOwnProperty
⬆1class Object { 2 static hasOwn(object: object, key: PropertyKey): boolean; 3}
core-js/proposals/accessible-object-hasownproperty
String
padding⬆1class String {
2 padStart(length: number, fillStr?: string = ' '): string;
3 padEnd(length: number, fillStr?: string = ' '): string;
4}
5
core-js/proposals/string-padding
String#matchAll
⬆.1class String {
2 matchAll(regexp: RegExp): Iterator;
3}
core-js/proposals/string-match-all
String#replaceAll
⬆1class String {
2 replaceAll(searchValue: string | RegExp, replaceString: string | (searchValue, index, this) => string): string;
3}
core-js/proposals/string-replace-all-stage-4
String.prototype.trimStart
/ String.prototype.trimEnd
⬆1class String {
2 trimLeft(): string;
3 trimRight(): string;
4 trimStart(): string;
5 trimEnd(): string;
6}
core-js/proposals/string-left-right-trim
RegExp
s
(dotAll
) flag⬆1// patched for support `RegExp` dotAll (`s`) flag: 2class RegExp { 3 constructor(pattern: RegExp | string, flags?: string): RegExp; 4 exec(): Array<string | undefined> | null; 5 readonly attribute dotAll: boolean; 6 readonly attribute flags: string; 7}
core-js/proposals/regexp-dotall-flag
RegExp
named capture groups⬆1// patched for support `RegExp` named capture groups: 2class RegExp { 3 constructor(pattern: RegExp | string, flags?: string): RegExp; 4 exec(): Array<string | undefined> | null; 5 @@replace(string: string, replaceValue: Function | string): string; 6}
core-js/proposals/regexp-named-groups
Promise.allSettled
⬆1class Promise { 2 static allSettled(iterable: Iterable): Promise; 3}
core-js/proposals/promise-all-settled
Promise.any
⬆1class AggregateError { 2 constructor(errors: Iterable, message: string): AggregateError; 3 errors: Array<any>; 4 message: string; 5} 6 7class Promise { 8 static any(promises: Iterable): Promise<any>; 9}
core-js/proposals/promise-any
Promise.prototype.finally
⬆1class Promise { 2 finally(onFinally: Function): Promise; 3}
core-js/proposals/promise-finally
Promise.try
1class Promise { 2 static try(callbackfn: Function, ...args?: Array<mixed>): Promise; 3}
core-js/proposals/promise-try
Promise.withResolvers
⬆1class Promise { 2 static withResolvers(): { promise: Promise, resolve: function, reject: function }; 3}
core-js/proposals/promise-with-resolvers
Symbol.asyncIterator
for asynchronous iteration⬆1class Symbol { 2 static asyncIterator: @@asyncIterator; 3}
core-js/proposals/async-iteration
Symbol.prototype.description
⬆1class Symbol { 2 readonly attribute description: string | void; 3}
core-js/proposals/symbol-description
JSON.stringify
⬆1namespace JSON { 2 stringify(target: any, replacer?: Function | Array, space?: string | number): string | void; 3}
core-js/proposals/well-formed-stringify
1class String {
2 isWellFormed(): boolean;
3 toWellFormed(): string;
4}
core-js/proposals/well-formed-unicode-strings
Set
methods⬆1class Set { 2 difference(other: SetLike<mixed>): Set; 3 intersection(other: SetLike<mixed>): Set; 4 isDisjointFrom(other: SetLike<mixed>): boolean; 5 isSubsetOf(other: SetLike<mixed>): boolean; 6 isSupersetOf(other: SetLike<mixed>): boolean; 7 symmetricDifference(other: SetLike<mixed>): Set; 8 union(other: SetLike<mixed>): Set; 9}
core-js/proposals/set-methods-v2
core-js(-pure)/stage/3
##### [`Array.fromAsync`](https://github.com/tc39/proposal-array-from-async)[⬆](#index)
Modules [`esnext.array.from-async`](https://github.com/zloirock/core-js/blob/master/packages/core-js/modules/esnext.array.from-async.js).
```ts
class Array {
static fromAsync(asyncItems: AsyncIterable | Iterable | ArrayLike, mapfn?: (value: any, index: number) => any, thisArg?: any): Array;
}
core-js/proposals/array-from-async-stage-2
core-js(-pure)/actual|full/array/from-async
1await Array.fromAsync((async function * () { yield * [1, 2, 3]; })(), i => i * i); // => [1, 4, 9]
JSON.parse
source text access⬆Modules esnext.json.is-raw-json
, esnext.json.parse
, esnext.json.raw-json
.
1namespace JSON { 2 isRawJSON(O: any): boolean; 3 // patched for source support 4 parse(text: string, reviver?: (this: any, key: string, value: any, context: { source?: string }) => any): any; 5 rawJSON(text: any): RawJSON; 6 // patched for `JSON.rawJSON` support 7 stringify(value: any, replacer?: Array<string | number> | (this: any, key: string, value: any) => any, space?: string | number): string | void; 8}
core-js/proposals/json-parse-with-source
core-js(-pure)/actual|full/json/is-raw-json
core-js(-pure)/actual|full/json/parse
core-js(-pure)/actual|full/json/raw-json
core-js(-pure)/actual|full/json/stringify
1function digitsToBigInt(key, val, { source }) {
2 return /^\d+$/.test(source) ? BigInt(source) : val;
3}
4
5function bigIntToRawJSON(key, val) {
6 return typeof val === 'bigint' ? JSON.rawJSON(String(val)) : val;
7}
8
9const tooBigForNumber = BigInt(Number.MAX_SAFE_INTEGER) + 2n;
10JSON.parse(String(tooBigForNumber), digitsToBigInt) === tooBigForNumber; // true
11
12const wayTooBig = BigInt(`1${ '0'.repeat(1000) }`);
13JSON.parse(String(wayTooBig), digitsToBigInt) === wayTooBig; // true
14
15const embedded = JSON.stringify({ tooBigForNumber }, bigIntToRawJSON);
16embedded === '{"tooBigForNumber":9007199254740993}'; // true
Float16
methods⬆Modules esnext.data-view.get-float16
, esnext.data-view.set-float16
and esnext.math.f16round
1class DataView { 2 getFloat16(offset: any): number 3 setFloat16(offset: any, value: any): void; 4} 5 6namespace Math { 7 fround(number: any): number; 8}
core-js/proposals/float16
core-js/actual|full/dataview/get-float16
core-js/actual|full/dataview/set-float16
core-js/actual|full/math/f16round
1console.log(Math.f16round(1.337)); // => 1.3369140625 2 3const view = new DataView(new ArrayBuffer(2)); 4view.setFloat16(0, 1.337); 5console.log(view.getFloat16(0)); // => 1.3369140625
Uint8Array
to / from base64 and hex⬆Modules esnext.uint8-array.from-base64
, esnext.uint8-array.from-hex
, esnext.uint8-array.set-from-hex
, esnext.uint8-array.to-base64
, esnext.uint8-array.to-hex
.
1class Uint8Array {
2 static fromBase64(string: string, options?: { alphabet?: 'base64' | 'base64url', lastChunkHandling?: 'loose' | 'strict' | 'stop-before-partial' }): Uint8Array;
3 static fromHex(string: string): Uint8Array;
4 setFromBase64(string: string, options?: { alphabet?: 'base64' | 'base64url', lastChunkHandling?: 'loose' | 'strict' | 'stop-before-partial' }): { read: uint, written: uint };
5 setFromHex(string: string): { read: uint, written: uint };
6 toBase64(options?: { alphabet?: 'base64' | 'base64url', omitPadding?: boolean }): string;
7 toHex(): string;
8}
core-js/proposals/array-buffer-base64
core-js(-pure)/actual|full/typed-array/from-base64
core-js(-pure)/actual|full/typed-array/from-hex
core-js(-pure)/actual|full/typed-array/set-from-base64
core-js(-pure)/actual|full/typed-array/set-from-hex
core-js(-pure)/actual|full/typed-array/to-base64
core-js(-pure)/actual|full/typed-array/to-hex
Example:
1let arr = new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]); 2console.log(arr.toBase64()); // => 'SGVsbG8gV29ybGQ=' 3console.log(arr.toBase64({ omitPadding: true })); // => 'SGVsbG8gV29ybGQ' 4console.log(arr.toHex()); // => '48656c6c6f20576f726c64' 5console.log(Uint8Array.fromBase64('SGVsbG8gV29ybGQ=')); // => Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]) 6console.log(Uint8Array.fromHex('48656c6c6f20576f726c64')); // => Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])
[!NOTE] This is only built-ins for this proposal,
using
syntax support requires transpiler support.
Modules esnext.symbol.dispose
, esnext.disposable-stack.constructor
, esnext.suppressed-error.constructor
, esnext.iterator.dispose
, esnext.symbol.async-dispose
, esnext.async-disposable-stack.constructor
, esnext.async-iterator.async-dispose
.
1class Symbol { 2 static asyncDispose: @@asyncDispose; 3 static dispose: @@dispose; 4} 5 6class DisposableStack { 7 constructor(): DisposableStack; 8 dispose(): undefined; 9 use(value: Disposable): value; 10 adopt(value: object, onDispose: Function): value; 11 defer(onDispose: Function): undefined; 12 @@dispose(): undefined; 13 @@toStringTag: 'DisposableStack'; 14} 15 16class AsyncDisposableStack { 17 constructor(): AsyncDisposableStack; 18 disposeAsync(): Promise<undefined>; 19 use(value: AsyncDisposable | Disposable): value; 20 adopt(value: object, onDispose: Function): value; 21 defer(onDispose: Function): undefined; 22 @@asyncDispose(): Promise<undefined>; 23 @@toStringTag: 'AsyncDisposableStack'; 24} 25 26class SuppressedError extends Error { 27 constructor(error: any, suppressed: any, message?: string): SuppressedError; 28 error: any; 29 suppressed: any; 30 message: string; 31 cause: any; 32} 33 34class Iterator { 35 @@dispose(): undefined; 36} 37 38class AsyncIterator { 39 @@asyncDispose(): Promise<undefined>; 40}
core-js/proposals/explicit-resource-management
core-js(-pure)/actual|full/symbol/async-dispose
core-js(-pure)/actual|full/symbol/dispose
core-js(-pure)/actual|full/disposable-stack
core-js(-pure)/actual|full/async-disposable-stack
core-js(-pure)/actual|full/suppressed-error
core-js(-pure)/actual|full/iterator/dispose
core-js(-pure)/actual|full/async-iterator/async-dispose
RegExp
escaping⬆Module esnext.regexp.escape
1class RegExp { 2 static escape(value: string): string 3}
core-js/proposals/regexp-escaping
core-js(-pure)/actual|full/regexp/escape
1console.log(RegExp.escape('10$')); // => '\\x310\\$'
2console.log(RegExp.escape('abcdefg_123456')); // => '\\x61bcdefg_123456'
3console.log(RegExp.escape('Привет')); // => 'Привет'
4console.log(RegExp.escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'));
5// => '\\(\\)\\{\\}\\[\\]\\|\\x2c\\.\\?\\*\\+\\x2d\\^\\$\\x3d\\x3c\\x3e\\\\\\/\\x23\\x26\\x21\\x25\\x3a\\x3b\\x40\\x7e\\x27\\x22\\x60'
6console.log(RegExp.escape('\u0009\u000A\u000B\u000C\u000D\u0020\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028\u2029\uFEFF'));
7// => '\\\t\\\n\\\v\\\f\\\r\\x20\\xa0\\u1680\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000\\u2028\\u2029\\ufeff'
8console.log(RegExp.escape('💩')); // => '💩'
9console.log(RegExp.escape('\uD83D')); // => '\\ud83d'
Math.sumPrecise
Module esnext.math.sum-precise
1class Math { 2 static sumPrecise(items: Iterable<number>): Number; 3}
core-js/proposals/math-sum
core-js(-pure)/full|actual/math/sum-precise
11e20 + 0.1 + -1e20; // => 0 2Math.sumPrecise([1e20, 0.1, -1e20]); // => 0.1
Symbol.metadata
for decorators metadata proposal⬆Modules esnext.symbol.metadata
and esnext.function.metadata
.
1class Symbol { 2 static metadata: @@metadata; 3} 4 5class Function { 6 @@metadata: null; 7}
core-js/proposals/decorator-metadata-v2
core-js(-pure)/actual|full/symbol/metadata
core-js(-pure)/actual|full/function/metadata
core-js(-pure)/stage/2.7
Iterator
sequencing⬆Module esnext.iterator.concat
1class Iterator { 2 concat(...items: Array<IterableObject>): Iterator<any>; 3}
core-js/proposals/iterator-sequencing
core-js(-pure)/full/iterator/concat
1Iterator.concat([0, 1].values(), [2, 3], function * () { 2 yield 4; 3 yield 5; 4}()).toArray(); // => [0, 1, 2, 3, 4, 5]
core-js(-pure)/stage/2
AsyncIterator
helpers⬆Modules esnext.async-iterator.constructor
, esnext.async-iterator.drop
, esnext.async-iterator.every
, esnext.async-iterator.filter
, esnext.async-iterator.find
, esnext.async-iterator.flat-map
, esnext.async-iterator.for-each
, esnext.async-iterator.from
, esnext.async-iterator.map
, esnext.async-iterator.reduce
, esnext.async-iterator.some
, esnext.async-iterator.take
, esnext.async-iterator.to-array
, , esnext.iterator.to-async
1class Iterator { 2 toAsync(): AsyncIterator<any>; 3} 4 5class AsyncIterator { 6 static from(iterable: AsyncIterable<any> | Iterable<any> | AsyncIterator<any>): AsyncIterator<any>; 7 drop(limit: uint): AsyncIterator<any>; 8 every(async callbackfn: (value: any, counter: uint) => boolean): Promise<boolean>; 9 filter(async callbackfn: (value: any, counter: uint) => boolean): AsyncIterator<any>; 10 find(async callbackfn: (value: any, counter: uint) => boolean)): Promise<any>; 11 flatMap(async callbackfn: (value: any, counter: uint) => AsyncIterable<any> | Iterable<any> | AsyncIterator<any>): AsyncIterator<any>; 12 forEach(async callbackfn: (value: any, counter: uint) => void): Promise<void>; 13 map(async callbackfn: (value: any, counter: uint) => any): AsyncIterator<any>; 14 reduce(async callbackfn: (memo: any, value: any, counter: uint) => any, initialValue: any): Promise<any>; 15 some(async callbackfn: (value: any, counter: uint) => boolean): Promise<boolean>; 16 take(limit: uint): AsyncIterator<any>; 17 toArray(): Promise<Array>; 18 @@toStringTag: 'AsyncIterator' 19}
core-js/proposals/async-iterator-helpers
core-js(-pure)/actual|full/async-iterator
core-js(-pure)/actual|full/async-iterator/drop
core-js(-pure)/actual|full/async-iterator/every
core-js(-pure)/actual|full/async-iterator/filter
core-js(-pure)/actual|full/async-iterator/find
core-js(-pure)/actual|full/async-iterator/flat-map
core-js(-pure)/actual|full/async-iterator/for-each
core-js(-pure)/actual|full/async-iterator/from
core-js(-pure)/actual|full/async-iterator/map
core-js(-pure)/actual|full/async-iterator/reduce
core-js(-pure)/actual|full/async-iterator/some
core-js(-pure)/actual|full/async-iterator/take
core-js(-pure)/actual|full/async-iterator/to-array
core-js(-pure)/actual|full/iterator/to-async
1await AsyncIterator.from([1, 2, 3, 4, 5, 6, 7]) 2 .drop(1) 3 .take(5) 4 .filter(it => it % 2) 5 .map(it => it ** 2) 6 .toArray(); // => [9, 25] 7 8await [1, 2, 3].values().toAsync().map(async it => it ** 2).toArray(); // => [1, 4, 9]
pure
version, new %AsyncIteratorPrototype%
methods are not added to the real %AsyncIteratorPrototype%
, they available only on wrappers - instead of [].values().toAsync().map(fn)
use AsyncIterator.from([]).map(fn)
.%AsyncIteratorPrototype%
only with usage async generators syntax. So, for compatibility of the library with old browsers, we should use Function
constructor. However, that breaks compatibility with CSP. So, if you wanna use the real %AsyncIteratorPrototype%
, you should set USE_FUNCTION_CONSTRUCTOR
option in the core-js/configurator
to true
:1const configurator = require('core-js/configurator'); 2 3configurator({ USE_FUNCTION_CONSTRUCTOR: true }); 4 5require('core-js/actual/async-iterator'); 6 7(async function * () { /* empty */ })() instanceof AsyncIterator; // => true
core-js/configurator
an object that will be considered as %AsyncIteratorPrototype%
:1const configurator = require('core-js/configurator'); 2 3const { getPrototypeOf } = Object; 4 5configurator({ AsyncIteratorPrototype: getPrototypeOf(getPrototypeOf(getPrototypeOf(async function * () { /* empty */ }()))) }); 6 7require('core-js/actual/async-iterator'); 8 9(async function * () { /* empty */ })() instanceof AsyncIterator; // => true
Iterator.range
⬆Module esnext.iterator.range
1class Iterator { 2 range(start: number, end: number, options: { step: number = 1, inclusive: boolean = false } | step: number = 1): NumericRangeIterator; 3 range(start: bigint, end: bigint | Infinity | -Infinity, options: { step: bigint = 1n, inclusive: boolean = false } | step: bigint = 1n): NumericRangeIterator; 4}
core-js/proposals/number-range
core-js(-pure)/full/iterator/range
1for (const i of Iterator.range(1, 10)) { 2 console.log(i); // => 1, 2, 3, 4, 5, 6, 7, 8, 9 3} 4 5for (const i of Iterator.range(1, 10, { step: 3, inclusive: true })) { 6 console.log(i); // => 1, 4, 7, 10 7}
Map
upsert⬆Modules esnext.map.get-or-insert
, esnext.map.get-or-insert-computed
, esnext.weak-map.get-or-insert
and esnext.weak-map.get-or-insert-computed
1class Map {
2 getOrInsert(key: any, value: any): any;
3 getOrInsertComputed(key: any, (key: any) => value: any): any;
4}
5
6class WeakMap {
7 getOrInsert(key: any, value: any): any;
8 getOrInsertComputed(key: any, (key: any) => value: any): any;
9}
core-js/proposals/map-upsert-v4
core-js(-pure)/full/map/get-or-insert
core-js(-pure)/full/map/get-or-insert-computed
core-js(-pure)/full/weak-map/get-or-insert
core-js(-pure)/full/weak-map/get-or-insert-computed
1const map = new Map([['a', 1]]); 2 3map.getOrInsert('a', 2); // => 1 4 5map.getOrInsert('b', 3); // => 3 6 7map.getOrInsertComputed('a', key => key); // => 1 8 9map.getOrInsertComputed('c', key => key); // => 'c' 10 11console.log(map); // => Map { 'a': 1, 'b': 3, 'c': 'c' }
Array.isTemplateObject
⬆Module esnext.array.is-template-object
1class Array { 2 static isTemplateObject(value: any): boolean 3}
core-js/proposals/array-is-template-object
core-js(-pure)/full/array/is-template-object
Example:
1console.log(Array.isTemplateObject((it => it)`qwe${ 123 }asd`)); // => true
String.dedent
⬆Module esnext.string.dedent
1class String { 2 static dedent(templateOrTag: { raw: Array<string> } | function, ...substitutions: Array<string>): string | function; 3}
core-js/proposals/string-dedent
core-js(-pure)/full/string/dedent
1const message = 42; 2 3console.log(String.dedent` 4 print('${ message }') 5`); // => print('42') 6 7String.dedent(console.log)` 8 print('${ message }') 9`; // => ["print('", "')", raw: Array(2)], 42
Symbol
predicates⬆Modules esnext.symbol.is-registered-symbol
, esnext.symbol.is-well-known-symbol
.
1class Symbol { 2 static isRegisteredSymbol(value: any): boolean; 3 static isWellKnownSymbol(value: any): boolean; 4}
core-js/proposals/symbol-predicates-v2
core-js(-pure)/full/symbol/is-registered-symbol
core-js(-pure)/full/symbol/is-well-known-symbol
1Symbol.isRegisteredSymbol(Symbol.for('key')); // => true
2Symbol.isRegisteredSymbol(Symbol('key')); // => false
3
4Symbol.isWellKnownSymbol(Symbol.iterator); // => true
5Symbol.isWellKnownSymbol(Symbol('key')); // => false
Symbol.customMatcher
for extractors⬆Module esnext.symbol.custom-matcher
.
1class Symbol { 2 static customMatcher: @@customMatcher; 3}
core-js/proposals/pattern-extractors
core-js(-pure)/full/symbol/custom-matcher
core-js(-pure)/stage/1
Observable
⬆Modules esnext.observable
and esnext.symbol.observable
1class Observable { 2 constructor(subscriber: Function): Observable; 3 subscribe(observer: Function | { next?: Function, error?: Function, complete?: Function }): Subscription; 4 @@observable(): this; 5 static of(...items: Array<mixed>): Observable; 6 static from(x: Observable | Iterable): Observable; 7 static readonly attribute @@species: this; 8} 9 10class Symbol { 11 static observable: @@observable; 12}
core-js/proposals/observable
core-js(-pure)/full/observable
core-js(-pure)/full/symbol/observable
1new Observable(observer => { 2 observer.next('hello'); 3 observer.next('world'); 4 observer.complete(); 5}).subscribe({ 6 next(it) { console.log(it); }, 7 complete() { console.log('!'); }, 8});
Modules esnext.set.add-all
, esnext.set.delete-all
, esnext.set.every
, esnext.set.filter
, esnext.set.find
, esnext.set.join
, esnext.set.map
, esnext.set.reduce
, esnext.set.some
, esnext.map.delete-all
, esnext.map.every
, esnext.map.filter
, esnext.map.find
, esnext.map.find-key
, esnext.map.includes
, esnext.map.key-by
, esnext.map.key-of
, esnext.map.map-keys
, esnext.map.map-values
, esnext.map.merge
, esnext.map.reduce
, esnext.map.some
, esnext.map.update
, esnext.weak-set.add-all
, esnext.weak-set.delete-all
, esnext.weak-map.delete-all
.of
and .from
methods on collection constructors⬆Modules esnext.set.of
, esnext.set.from
, esnext.map.of
, esnext.map.from
, esnext.weak-set.of
, esnext.weak-set.from
, esnext.weak-map.of
, esnext.weak-map.from
1class Set { 2 static of(...args: Array<mixed>): Set; 3 static from(iterable: Iterable<mixed>, mapFn?: (value: any, index: number) => any, thisArg?: any): Set; 4 addAll(...args: Array<mixed>): this; 5 deleteAll(...args: Array<mixed>): boolean; 6 every(callbackfn: (value: any, key: any, target: any) => boolean, thisArg?: any): boolean; 7 filter(callbackfn: (value: any, key: any, target: any) => boolean, thisArg?: any): Set; 8 find(callbackfn: (value: any, key: any, target: any) => boolean), thisArg?: any): any; 9 join(separator: string = ','): string; 10 map(callbackfn: (value: any, key: any, target: any) => any, thisArg?: any): Set; 11 reduce(callbackfn: (memo: any, value: any, key: any, target: any) => any, initialValue?: any): any; 12 some(callbackfn: (value: any, key: any, target: any) => boolean, thisArg?: any): boolean; 13} 14 15class Map { 16 static of(...args: Array<[key, value]>): Map; 17 static from(iterable: Iterable<mixed>, mapFn?: (value: any, index: number) => [key: any, value: any], thisArg?: any): Map; 18 static keyBy(iterable: Iterable<mixed>, callbackfn?: (value: any) => any): Map; 19 deleteAll(...args: Array<mixed>): boolean; 20 every(callbackfn: (value: any, key: any, target: any) => boolean, thisArg?: any): boolean; 21 filter(callbackfn: (value: any, key: any, target: any) => boolean, thisArg?: any): Map; 22 find(callbackfn: (value: any, key: any, target: any) => boolean), thisArg?: any): any; 23 findKey(callbackfn: (value: any, key: any, target: any) => boolean), thisArg?: any): any; 24 includes(searchElement: any): boolean; 25 keyOf(searchElement: any): any; 26 mapKeys(mapFn: (value: any, index: number, target: any) => any, thisArg?: any): Map; 27 mapValues(mapFn: (value: any, index: number, target: any) => any, thisArg?: any): Map; 28 merge(...iterables: Array<Iterable>): this; 29 reduce(callbackfn: (memo: any, value: any, key: any, target: any) => any, initialValue?: any): any; 30 some(callbackfn: (value: any, key: any, target: any) => boolean, thisArg?: any): boolean; 31 update(key: any, callbackfn: (value: any, key: any, target: any) => any, thunk?: (key: any, target: any) => any): this; 32} 33 34class WeakSet { 35 static of(...args: Array<mixed>): WeakSet; 36 static from(iterable: Iterable<mixed>, mapFn?: (value: any, index: number) => Object, thisArg?: any): WeakSet; 37 addAll(...args: Array<mixed>): this; 38 deleteAll(...args: Array<mixed>): boolean; 39} 40 41class WeakMap { 42 static of(...args: Array<[key, value]>): WeakMap; 43 static from(iterable: Iterable<mixed>, mapFn?: (value: any, index: number) => [key: Object, value: any], thisArg?: any): WeakMap; 44 deleteAll(...args: Array<mixed>): boolean; 45}
core-js/proposals/collection-methods
core-js/proposals/collection-of-from
core-js(-pure)/full/set/add-all
core-js(-pure)/full/set/delete-all
core-js(-pure)/full/set/every
core-js(-pure)/full/set/filter
core-js(-pure)/full/set/find
core-js(-pure)/full/set/from
core-js(-pure)/full/set/join
core-js(-pure)/full/set/map
core-js(-pure)/full/set/of
core-js(-pure)/full/set/reduce
core-js(-pure)/full/set/some
core-js(-pure)/full/map/delete-all
core-js(-pure)/full/map/every
core-js(-pure)/full/map/filter
core-js(-pure)/full/map/find
core-js(-pure)/full/map/find-key
core-js(-pure)/full/map/from
core-js(-pure)/full/map/includes
core-js(-pure)/full/map/key-by
core-js(-pure)/full/map/key-of
core-js(-pure)/full/map/map-keys
core-js(-pure)/full/map/map-values
core-js(-pure)/full/map/merge
core-js(-pure)/full/map/of
core-js(-pure)/full/map/reduce
core-js(-pure)/full/map/some
core-js(-pure)/full/map/update
core-js(-pure)/full/weak-set/add-all
core-js(-pure)/full/weak-set/delete-all
core-js(-pure)/full/weak-set/of
core-js(-pure)/full/weak-set/from
core-js(-pure)/full/weak-map/delete-all
core-js(-pure)/full/weak-map/of
core-js(-pure)/full/weak-map/from
.of
/ .from
examples:
1Set.of(1, 2, 3, 2, 1); // => Set {1, 2, 3} 2 3Map.from([[1, 2], [3, 4]], ([key, value]) => [key ** 2, value ** 2]); // => Map { 1: 4, 9: 16 }
compositeKey
and compositeSymbol
⬆Modules esnext.composite-key
and esnext.composite-symbol
1function compositeKey(...args: Array<mixed>): object;
2function compositeSymbol(...args: Array<mixed>): symbol;
core-js/proposals/keys-composition
core-js(-pure)/full/composite-key
core-js(-pure)/full/composite-symbol
1// returns a symbol
2const symbol = compositeSymbol({});
3console.log(typeof symbol); // => 'symbol'
4
5// works the same, but returns a plain frozen object without a prototype
6const key = compositeKey({});
7console.log(typeof key); // => 'object'
8console.log({}.toString.call(key)); // => '[object Object]'
9console.log(Object.getPrototypeOf(key)); // => null
10console.log(Object.isFrozen(key)); // => true
11
12const a = ['a'];
13const b = ['b'];
14const c = ['c'];
15
16/* eslint-disable no-self-compare -- example */
17console.log(compositeSymbol(a) === compositeSymbol(a)); // => true
18console.log(compositeSymbol(a) !== compositeSymbol(['a'])); // => true
19console.log(compositeSymbol(a, 1) === compositeSymbol(a, 1)); // => true
20console.log(compositeSymbol(a, b) !== compositeSymbol(b, a)); // => true
21console.log(compositeSymbol(a, b, c) === compositeSymbol(a, b, c)); // => true
22console.log(compositeSymbol(1, a) === compositeSymbol(1, a)); // => true
23console.log(compositeSymbol(1, a, 2, b) === compositeSymbol(1, a, 2, b)); // => true
24console.log(compositeSymbol(a, a) === compositeSymbol(a, a)); // => true
Modules esnext.array.filter-reject
and esnext.typed-array.filter-reject
.
1class Array { 2 filterReject(callbackfn: (value: any, index: number, target: any) => boolean, thisArg?: any): Array<mixed>; 3} 4 5class %TypedArray% { 6 filterReject(callbackfn: (value: number, index: number, target: %TypedArray%) => boolean, thisArg?: any): %TypedArray%; 7}
core-js/proposals/array-filtering-stage-1
core-js(-pure)/full/array(/virtual)/filter-reject
core-js/full/typed-array/filter-reject
1[1, 2, 3, 4, 5].filterReject(it => it % 2); // => [2, 4]
Modules esnext.array.unique-by
and esnext.typed-array.unique-by
1class Array { 2 uniqueBy(resolver?: (item: any) => any): Array<mixed>; 3} 4 5class %TypedArray% { 6 uniqueBy(resolver?: (item: any) => any): %TypedArray%;; 7}
core-js/proposals/array-unique
core-js(-pure)/full/array(/virtual)/unique-by
core-js/full/typed-array/unique-by
1[1, 2, 3, 2, 1].uniqueBy(); // [1, 2, 3] 2 3[ 4 { id: 1, uid: 10000 }, 5 { id: 2, uid: 10000 }, 6 { id: 3, uid: 10001 }, 7].uniqueBy(it => it.uid); // => [{ id: 1, uid: 10000 }, { id: 3, uid: 10001 }]
DataView
get / set Uint8Clamped
methods⬆Modules esnext.data-view.get-uint8-clamped
and esnext.data-view.set-uint8-clamped
1class DataView {
2 getUint8Clamped(offset: any): uint8
3 setUint8Clamped(offset: any, value: any): void;
4}
core-js/proposals/data-view-get-set-uint8-clamped
core-js/full/dataview/get-uint8-clamped
core-js/full/dataview/set-uint8-clamped
1const view = new DataView(new ArrayBuffer(1)); 2view.setUint8Clamped(0, 100500); 3console.log(view.getUint8Clamped(0)); // => 255
Number.fromString
⬆Module esnext.number.from-string
1class Number {
2 fromString(string: string, radix: number): number;
3}
core-js/proposals/number-from-string
core-js(-pure)/full/number/from-string
String.cooked
⬆Module esnext.string.cooked
1class String { 2 static cooked(template: Array<string>, ...substitutions: Array<string>): string; 3}
core-js/proposals/string-cooked
core-js(-pure)/full/string/cooked
1function safePath(strings, ...subs) {
2 return String.cooked(strings, ...subs.map(sub => encodeURIComponent(sub)));
3}
4
5let id = 'spottie?';
6
7safePath`/cats/${ id }`; // => /cats/spottie%3F
String.prototype.codePoints
⬆Module esnext.string.code-points
1class String { 2 codePoints(): Iterator<{ codePoint, position }>; 3}
core-js/proposals/string-code-points
core-js(-pure)/full/string/code-points
1for (let { codePoint, position } of 'qwe'.codePoints()) { 2 console.log(codePoint); // => 113, 119, 101 3 console.log(position); // => 0, 1, 2 4}
Symbol.customMatcher
for pattern matching⬆Module esnext.symbol.custom-matcher
.
1class Symbol { 2 static customMatcher: @@customMatcher; 3}
core-js/proposals/pattern-matching-v2
core-js(-pure)/full/symbol/custom-matcher
core-js(-pure)/stage/0
Function.prototype.demethodize
⬆Module esnext.function.demethodize
1class Function { 2 demethodize(): Function; 3}
core-js/proposals/function-demethodize
core-js(-pure)/full/function/demethodize
core-js(-pure)/full/function/virtual/demethodize
1const slice = Array.prototype.slice.demethodize(); 2 3slice([1, 2, 3], 1); // => [2, 3]
Function.{ isCallable, isConstructor }
⬆Modules esnext.function.is-callable
, esnext.function.is-constructor
1class Function { 2 static isCallable(value: any): boolean; 3 static isConstructor(value: any): boolean; 4}
core-js/proposals/function-is-callable-is-constructor
core-js(-pure)/full/function/is-callable
core-js(-pure)/full/function/is-constructor
1/* eslint-disable prefer-arrow-callback -- example */
2Function.isCallable(null); // => false
3Function.isCallable({}); // => false
4Function.isCallable(function () { /* empty */ }); // => true
5Function.isCallable(() => { /* empty */ }); // => true
6Function.isCallable(class { /* empty */ }); // => false
7
8Function.isConstructor(null); // => false
9Function.isConstructor({}); // => false
10Function.isConstructor(function () { /* empty */ }); // => true
11Function.isConstructor(() => { /* empty */ }); // => false
12Function.isConstructor(class { /* empty */ }); // => true
core-js(-pure)/stage/pre
Reflect
metadata⬆Modules esnext.reflect.define-metadata
, esnext.reflect.delete-metadata
, esnext.reflect.get-metadata
, esnext.reflect.get-metadata-keys
, esnext.reflect.get-own-metadata
, esnext.reflect.get-own-metadata-keys
, esnext.reflect.has-metadata
, esnext.reflect.has-own-metadata
and esnext.reflect.metadata
.
1namespace Reflect {
2 defineMetadata(metadataKey: any, metadataValue: any, target: Object, propertyKey?: PropertyKey): void;
3 getMetadata(metadataKey: any, target: Object, propertyKey?: PropertyKey): any;
4 getOwnMetadata(metadataKey: any, target: Object, propertyKey?: PropertyKey): any;
5 hasMetadata(metadataKey: any, target: Object, propertyKey?: PropertyKey): boolean;
6 hasOwnMetadata(metadataKey: any, target: Object, propertyKey?: PropertyKey): boolean;
7 deleteMetadata(metadataKey: any, target: Object, propertyKey?: PropertyKey): boolean;
8 getMetadataKeys(target: Object, propertyKey?: PropertyKey): Array<mixed>;
9 getOwnMetadataKeys(target: Object, propertyKey?: PropertyKey): Array<mixed>;
10 metadata(metadataKey: any, metadataValue: any): decorator(target: Object, targetKey?: PropertyKey) => void;
11}
core-js/proposals/reflect-metadata
core-js(-pure)/full/reflect/define-metadata
core-js(-pure)/full/reflect/delete-metadata
core-js(-pure)/full/reflect/get-metadata
core-js(-pure)/full/reflect/get-metadata-keys
core-js(-pure)/full/reflect/get-own-metadata
core-js(-pure)/full/reflect/get-own-metadata-keys
core-js(-pure)/full/reflect/has-metadata
core-js(-pure)/full/reflect/has-own-metadata
core-js(-pure)/full/reflect/metadata
1let object = {};
2Reflect.defineMetadata('foo', 'bar', object);
3Reflect.ownKeys(object); // => []
4Reflect.getOwnMetadataKeys(object); // => ['foo']
5Reflect.getOwnMetadata('foo', object); // => 'bar'
self
⬆1getter self: GlobalThisValue;
core-js(-pure)/stable|actual|full/self
1// eslint-disable-next-line no-restricted-globals -- example 2self.Array === Array; // => true
structuredClone
⬆Spec, module web.structured-clone
1function structuredClone(value: Serializable, { transfer?: Sequence<Transferable> }): any;
core-js(-pure)/stable|actual|full/structured-clone
1const structured = [{ a: 42 }]; 2const sclone = structuredClone(structured); 3console.log(sclone); // => [{ a: 42 }] 4console.log(structured !== sclone); // => true 5console.log(structured[0] !== sclone[0]); // => true 6 7const circular = {}; 8circular.circular = circular; 9const cclone = structuredClone(circular); 10console.log(cclone.circular === cclone); // => true 11 12structuredClone(42); // => 42 13structuredClone({ x: 42 }); // => { x: 42 } 14structuredClone([1, 2, 3]); // => [1, 2, 3] 15structuredClone(new Set([1, 2, 3])); // => Set{ 1, 2, 3 } 16structuredClone(new Map([['a', 1], ['b', 2]])); // => Map{ a: 1, b: 2 } 17structuredClone(new Int8Array([1, 2, 3])); // => new Int8Array([1, 2, 3]) 18structuredClone(new AggregateError([1, 2, 3], 'message')); // => new AggregateError([1, 2, 3], 'message')) 19structuredClone(new TypeError('message', { cause: 42 })); // => new TypeError('message', { cause: 42 }) 20structuredClone(new DOMException('message', 'DataCloneError')); // => new DOMException('message', 'DataCloneError') 21structuredClone(document.getElementById('myfileinput')); // => new FileList 22structuredClone(new DOMPoint(1, 2, 3, 4)); // => new DOMPoint(1, 2, 3, 4) 23structuredClone(new Blob(['test'])); // => new Blob(['test']) 24structuredClone(new ImageData(8, 8)); // => new ImageData(8, 8) 25// etc. 26 27structuredClone(new WeakMap()); // => DataCloneError on non-serializable types
[!WARNING]
- Many platform types cannot be transferred in most engines since we have no way to polyfill this behavior, however
.transfer
option works for some platform types. I recommend avoiding this option.- Some specific platform types can't be cloned in old engines. Mainly it's very specific types or very old engines, but here are some exceptions. For example, we have no sync way to clone
ImageBitmap
in Safari 14.0- or Firefox 83-, so it's recommended to look to the polyfill source if you wanna clone something specific.
Specification, MDN. Modules web.atob
, web.btoa
.
1function atob(data: string): string; 2function btoa(data: string): string;
core-js(-pure)/stable|actual|full/atob
core-js(-pure)/stable|actual|full/btoa
1btoa('hi, core-js'); // => 'aGksIGNvcmUtanM=' 2atob('aGksIGNvcmUtanM='); // => 'hi, core-js'
setTimeout
and setInterval
⬆Module web.timers
. Additional arguments fix for IE9-.
1function setTimeout(callback: any, time: any, ...args: Array<mixed>): number;
2function setInterval(callback: any, time: any, ...args: Array<mixed>): number;
core-js(-pure)/stable|actual|full/set-timeout
core-js(-pure)/stable|actual|full/set-interval
1// Before:
2setTimeout(log.bind(null, 42), 1000);
3// After:
4setTimeout(log, 1000, 42);
setImmediate
⬆Module web.immediate
. setImmediate
polyfill.
1function setImmediate(callback: any, ...args: Array<mixed>): number;
2function clearImmediate(id: number): void;
core-js(-pure)/stable|actual|full/set-immediate
core-js(-pure)/stable|actual|full/clear-immediate
1setImmediate((arg1, arg2) => { 2 console.log(arg1, arg2); // => Message will be displayed with minimum delay 3}, 'Message will be displayed', 'with minimum delay'); 4 5clearImmediate(setImmediate(() => { 6 console.log('Message will not be displayed'); 7}));
queueMicrotask
⬆Spec, module web.queue-microtask
1function queueMicrotask(fn: Function): void;
core-js(-pure)/stable|actual|full/queue-microtask
1queueMicrotask(() => console.log('called as microtask'));
URL
and URLSearchParams
⬆URL
standard implementation. Modules web.url
, web.url.can-parse
, web.url.parse
, web.url.to-json
, web.url-search-params
, web.url-search-params.delete
, web.url-search-params.has
, web.url-search-params.size
.
1class URL { 2 constructor(url: string, base?: string); 3 attribute href: string; 4 readonly attribute origin: string; 5 attribute protocol: string; 6 attribute username: string; 7 attribute password: string; 8 attribute host: string; 9 attribute hostname: string; 10 attribute port: string; 11 attribute pathname: string; 12 attribute search: string; 13 readonly attribute searchParams: URLSearchParams; 14 attribute hash: string; 15 toJSON(): string; 16 toString(): string; 17 static canParse(url: string, base?: string): boolean; 18 static parse(url: string, base?: string): URL | null; 19} 20 21class URLSearchParams { 22 constructor(params?: string | Iterable<[key, value]> | Object); 23 append(name: string, value: string): void; 24 delete(name: string, value?: string): void; 25 get(name: string): string | void; 26 getAll(name: string): Array<string>; 27 has(name: string, value?: string): boolean; 28 set(name: string, value: string): void; 29 sort(): void; 30 toString(): string; 31 forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg: any): void; 32 entries(): Iterator<[key, value]>; 33 keys(): Iterator<key>; 34 values(): Iterator<value>; 35 @@iterator(): Iterator<[key, value]>; 36 readonly attribute size: number; 37}
core-js/proposals/url
core-js(-pure)/stable|actual|full/url
core-js(-pure)/stable|actual|full/url/can-parse
core-js/stable|actual|full/url/to-json
core-js(-pure)/stable|actual|full/url-search-params
1URL.canParse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'); // => true 2URL.canParse('https'); // => false 3 4URL.parse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'); // => url 5URL.parse('https'); // => null 6 7const url = new URL('https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment'); 8 9console.log(url.href); // => 'https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment' 10console.log(url.origin); // => 'https://example.com:8080' 11console.log(url.protocol); // => 'https:' 12console.log(url.username); // => 'login' 13console.log(url.password); // => 'password' 14console.log(url.host); // => 'example.com:8080' 15console.log(url.hostname); // => 'example.com' 16console.log(url.port); // => '8080' 17console.log(url.pathname); // => '/foo/bar' 18console.log(url.search); // => '?a=1&b=2&a=3' 19console.log(url.hash); // => '#fragment' 20console.log(url.toJSON()); // => 'https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment' 21console.log(url.toString()); // => 'https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment' 22 23for (let [key, value] of url.searchParams) { 24 console.log(key); // => 'a', 'b', 'a' 25 console.log(value); // => '1', '2', '3' 26} 27 28url.pathname = ''; 29url.searchParams.append('c', 4); 30 31console.log(url.search); // => '?a=1&b=2&a=3&c=4' 32console.log(url.href); // => 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment' 33 34const params = new URLSearchParams('?a=1&b=2&a=3'); 35 36params.append('c', 4); 37params.append('a', 2); 38params.delete('a', 1); 39params.sort(); 40 41console.log(params.size); // => 4 42 43for (let [key, value] of params) { 44 console.log(key); // => 'a', 'a', 'b', 'c' 45 console.log(value); // => '3', '2', '2', '4' 46} 47 48console.log(params.has('a')); // => true 49console.log(params.has('a', 3)); // => true 50console.log(params.has('a', 4)); // => false 51 52console.log(params.toString()); // => 'a=3&a=2&b=2&c=4'
[!WARNING]
- IE8 does not support setters, so they do not work on
URL
instances. However,URL
constructor can be used for basicURL
parsing.- Legacy encodings in a search query are not supported. Also,
core-js
implementation has some other encoding-related issues.URL
implementations from all of the popular browsers have significantly more problems thancore-js
, however, replacing all of them does not look like a good idea. You can customize the aggressiveness of polyfill by your requirements.
DOMException
:⬆The specification. Modules web.dom-exception.constructor
, web.dom-exception.stack
, web.dom-exception.to-string-tag
.
1class DOMException { 2 constructor(message: string, name?: string); 3 readonly attribute name: string; 4 readonly attribute message: string; 5 readonly attribute code: string; 6 attribute stack: string; // in engines that should have it 7 @@toStringTag: 'DOMException'; 8}
core-js(-pure)/stable|actual|full/dom-exception
core-js(-pure)/stable|actual|full/dom-exception/constructor
core-js/stable|actual|full/dom-exception/to-string-tag
1const exception = new DOMException('error', 'DataCloneError'); 2console.log(exception.name); // => 'DataCloneError' 3console.log(exception.message); // => 'error' 4console.log(exception.code); // => 25 5console.log(typeof exception.stack); // => 'string' 6console.log(exception instanceof DOMException); // => true 7console.log(exception instanceof Error); // => true 8console.log(exception.toString()); // => 'DataCloneError: error' 9console.log(Object.prototype.toString.call(exception)); // => '[object DOMException]'
Some DOM collections should have iterable interface or should be inherited from Array
. That means they should have forEach
, keys
, values
, entries
and @@iterator
methods for iteration. So add them. Modules web.dom-collections.iterator
and web.dom-collections.for-each
.
1class [ 2 CSSRuleList, 3 CSSStyleDeclaration, 4 CSSValueList, 5 ClientRectList, 6 DOMRectList, 7 DOMStringList, 8 DataTransferItemList, 9 FileList, 10 HTMLAllCollection, 11 HTMLCollection, 12 HTMLFormElement, 13 HTMLSelectElement, 14 MediaList, 15 MimeTypeArray, 16 NamedNodeMap, 17 PaintRequestList, 18 Plugin, 19 PluginArray, 20 SVGLengthList, 21 SVGNumberList, 22 SVGPathSegList, 23 SVGPointList, 24 SVGStringList, 25 SVGTransformList, 26 SourceBufferList, 27 StyleSheetList, 28 TextTrackCueList, 29 TextTrackList, 30 TouchList, 31] { 32 @@iterator(): Iterator<value>; 33} 34 35class [DOMTokenList, NodeList] { 36 forEach(callbackfn: (value: any, index: number, target: any) => void, thisArg: any): void; 37 entries(): Iterator<[key, value]>; 38 keys(): Iterator<key>; 39 values(): Iterator<value>; 40 @@iterator(): Iterator<value>; 41}
core-js(-pure)/stable|actual|full/dom-collections/iterator
core-js/stable|actual|full/dom-collections/for-each
1for (let { id } of document.querySelectorAll('*')) { 2 if (id) console.log(id); 3} 4 5for (let [index, { id }] of document.querySelectorAll('*').entries()) { 6 if (id) console.log(index, id); 7} 8 9document.querySelectorAll('*').forEach(it => console.log(it.id));
Helpers for checking iterability / get iterator in the pure
version or, for example, for arguments
object:
1function isIterable(value: any): boolean;
2function getIterator(value: any): Object;
3function getIteratorMethod(value: any): Function | void;
core-js-pure/es|stable|actual|full/is-iterable
core-js-pure/es|stable|actual|full/get-iterator
core-js-pure/es|stable|actual|full/get-iterator-method
Examples:
1import isIterable from 'core-js-pure/actual/is-iterable'; 2import getIterator from 'core-js-pure/actual/get-iterator'; 3import getIteratorMethod from 'core-js-pure/actual/get-iterator-method'; 4 5let list = (function () { 6 // eslint-disable-next-line prefer-rest-params -- example 7 return arguments; 8})(1, 2, 3); 9 10console.log(isIterable(list)); // true; 11 12let iterator = getIterator(list); 13console.log(iterator.next().value); // 1 14console.log(iterator.next().value); // 2 15console.log(iterator.next().value); // 3 16console.log(iterator.next().value); // undefined 17 18getIterator({}); // TypeError: [object Object] is not iterable! 19 20let method = getIteratorMethod(list); 21console.log(typeof method); // 'function' 22iterator = method.call(list); 23console.log(iterator.next().value); // 1 24console.log(iterator.next().value); // 2 25console.log(iterator.next().value); // 3 26console.log(iterator.next().value); // undefined 27 28console.log(getIteratorMethod({})); // undefined
BigInt
can't be polyfilled since it requires changes in the behavior of operators, you can find more info here. You could try to use JSBI
.Proxy
can't be polyfilled, you can try to use proxy-polyfill
which provides a very small subset of features.String#normalize
is not a very useful feature, but this polyfill will be very large. If you need it, you can use unorm.Intl
is missed because of the size. You can use those polyfills.window.fetch
is not a cross-platform feature, in some environments, it makes no sense. For this reason, I don't think it should be in core-js
. Looking at a large number of requests it might be added in the future. Now you can use, for example, this polyfill.No vulnerabilities found.
Reason
security policy file detected
Details
Reason
GitHub workflow tokens follow principle of least privilege
Details
Reason
30 commit(s) and 7 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
dependency not pinned by hash detected -- score normalized to 5
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
no SAST tool detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Details
Reason
17 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More