Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Standard Library

License

NotificationsYou must be signed in to change notification settings

zloirock/core-js

Repository files navigation

logo

fundraisingPRs welcomeversioncore-js downloadscore-js-pure downloadsjsDelivr

I highly recommend reading this:So, what's next?

Modular standard library for JavaScript. Includes polyfills forECMAScript up to 2024:promises,symbols,collections, iterators,typed arrays, many other features,ECMAScript proposals,some cross-platform WHATWG / W3C features and proposals likeURL. You can load only required features or use it without global namespace pollution.

If you are looking for documentation for obsoletecore-js@2, please, checkthis branch.

Raising funds

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 incore-js:Open Collective,Patreon,Boosty,Bitcoin ( bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz ),Alipay.




Example of usage:

import'core-js/actual';Promise.resolve(42).then(it=>console.log(it));// => 42Array.from(newSet([1,2,3]).union(newSet([3,4,5])));// => [1, 2, 3, 4, 5][1,2].flatMap(it=>[it,it]);// => [1, 1, 2, 2](function*(i){while(true)yieldi++;})(1).drop(1).take(5).filter(it=>it%2).map(it=>it**2).toArray();// => [9, 25]structuredClone(newSet([1,2,3]));// => new Set([1, 2, 3])

You can load only required features:

import'core-js/actual/promise';import'core-js/actual/set';import'core-js/actual/iterator';import'core-js/actual/array/from';import'core-js/actual/array/flat-map';import'core-js/actual/structured-clone';Promise.resolve(42).then(it=>console.log(it));// => 42Array.from(newSet([1,2,3]).union(newSet([3,4,5])));// => [1, 2, 3, 4, 5][1,2].flatMap(it=>[it,it]);// => [1, 1, 2, 2](function*(i){while(true)yieldi++;})(1).drop(1).take(5).filter(it=>it%2).map(it=>it**2).toArray();// => [9, 25]structuredClone(newSet([1,2,3]));// => new Set([1, 2, 3])

Or use it without global namespace pollution:

importPromisefrom'core-js-pure/actual/promise';importSetfrom'core-js-pure/actual/set';importIteratorfrom'core-js-pure/actual/iterator';importfromfrom'core-js-pure/actual/array/from';importflatMapfrom'core-js-pure/actual/array/flat-map';importstructuredClonefrom'core-js-pure/actual/structured-clone';Promise.resolve(42).then(it=>console.log(it));// => 42from(newSet([1,2,3]).union(newSet([3,4,5])));// => [1, 2, 3, 4, 5]flatMap([1,2],it=>[it,it]);// => [1, 1, 2, 2]Iterator.from(function*(i){while(true)yieldi++;}(1)).drop(1).take(5).filter(it=>it%2).map(it=>it**2).toArray();// => [9, 25]structuredClone(newSet([1,2,3]));// => new Set([1, 2, 3])

Index

Usage

Installation:

// global versionnpm install --save core-js@3.44.0// version without global namespace pollutionnpm install --save core-js-pure@3.44.0// bundled global versionnpm install --save core-js-bundle@3.44.0

Or you can usecore-jsfrom CDN.

postinstall message

Thecore-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:

ADBLOCK=true npm install// orDISABLE_OPENCOLLECTIVE=true npm install// ornpm install --loglevel silent

CommonJS API

You can import only-required-for-you polyfills, like in the examples at the top ofREADME.md. Available CommonJS entry points for all polyfilled methods / constructors and namespaces. Just some examples:

// polyfill all `core-js` features, including early-stage proposals:import"core-js";// or:import"core-js/full";// polyfill all actual features - stable ES, web standards and stage 3 ES proposals:import"core-js/actual";// polyfill only stable features - ES and web standards:import"core-js/stable";// polyfill only stable ES features:import"core-js/es";// if you want to polyfill `Set`:// all `Set`-related features, with early-stage ES proposals:import"core-js/full/set";// stable required for `Set` ES features, features from web standards and stage 3 ES proposals:import"core-js/actual/set";// stable required for `Set` ES features and features from web standards// (DOM collections iterator in this case):import"core-js/stable/set";// only stable ES features required for `Set`:import"core-js/es/set";// the same without global namespace pollution:importSetfrom"core-js-pure/full/set";importSetfrom"core-js-pure/actual/set";importSetfrom"core-js-pure/stable/set";importSetfrom"core-js-pure/es/set";// if you want to polyfill just the required methods:import"core-js/full/set/intersection";import"core-js/actual/array/find-last";import"core-js/stable/queue-microtask";import"core-js/es/array/from";// polyfill iterator helpers proposal:import"core-js/proposals/iterator-helpers";// polyfill all stage 2+ proposals:import"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

  • Themodules 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 usecore-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 ownSymbol.iterator, conflicting withArray.from,URLSearchParams and / or something else fromcore-js, seerelated issues.
    • Such conflicts are also resolvable by discovering and manually adding each conflicting entry fromcore-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.

CommonJS and prototype methods without global namespace pollution

In thepure 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:

importfillfrom'core-js-pure/actual/array/virtual/fill';importfindIndexfrom'core-js-pure/actual/array/virtual/find-index';Array(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.

Babel

core-js is integrated withbabel and is the base for polyfilling-relatedbabel features:

@babel/polyfill

@babel/polyfillIS just the import of stablecore-js features andregenerator-runtime for generators and async functions, so loading@babel/polyfill means loading the global version ofcore-js without ES proposals.

Now it's deprecated in favor of separate inclusion of required parts ofcore-js andregenerator-runtime and, for backward compatibility,@babel/polyfill is still based oncore-js@2.

As a full equal of@babel/polyfill, you can use the following:

import'core-js/stable';import'regenerator-runtime/runtime';

@babel/preset-env

@babel/preset-env hasuseBuiltIns option, which optimizes the use of the global version ofcore-js. WithuseBuiltIns option, you should also setcorejs option to the used version ofcore-js, likecorejs: '3.44'.

Important

It is recommended to specify the used minorcore-js version, likecorejs: '3.44', instead ofcorejs: 3, since withcorejs: 3 will not be injected modules which were added in minorcore-js releases.


  • useBuiltIns: 'entry' replaces imports ofcore-js to import only required for a target environment modules. So, for example,
import'core-js/stable';

withchrome 71 target will be replaced just to:

import'core-js/modules/es.array.unscopables.flat';import'core-js/modules/es.array.unscopables.flat-map';import'core-js/modules/es.object.from-entries';import'core-js/modules/web.immediate';

It works for all entry points of global version ofcore-js and their combinations, for example for

import'core-js/es';import'core-js/proposals/set-methods';import'core-js/full/set/map';

withchrome 71 target you will have as the result:

import'core-js/modules/es.array.unscopables.flat';import'core-js/modules/es.array.unscopables.flat-map';import'core-js/modules/es.object.from-entries';import'core-js/modules/esnext.set.difference';import'core-js/modules/esnext.set.intersection';import'core-js/modules/esnext.set.is-disjoint-from';import'core-js/modules/esnext.set.is-subset-of';import'core-js/modules/esnext.set.is-superset-of';import'core-js/modules/esnext.set.map';import'core-js/modules/esnext.set.symmetric-difference';import'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:
// first file:letset=newSet([1,2,3]);
// second file:letarray=Array.of(1,2,3);

if the target contains an old environment likeIE 11 we will have something like:

// first file:import'core-js/modules/es.array.iterator';import'core-js/modules/es.object.to-string';import'core-js/modules/es.set';varset=newSet([1,2,3]);
// second file:import'core-js/modules/es.array.of';vararray=Array.of(1,2,3);

By default,@babel/preset-env withuseBuiltIns: 'usage' option only polyfills stable features, but you can enable polyfilling of proposals by theproposals option, ascorejs: { version: '3.44', proposals: true }.

Important

In the case ofuseBuiltIns: 'usage', you should not addcore-js imports by yourself, they will be added automatically.

@babel/runtime

@babel/runtime withcorejs: 3 option simplifies work with thecore-js-pure. It automatically replaces the usage of modern features from the JS standard library to imports from the version ofcore-js without global namespace pollution, so instead of:

importfromfrom'core-js-pure/stable/array/from';importflatfrom'core-js-pure/stable/array/flat';importSetfrom'core-js-pure/stable/set';importPromisefrom'core-js-pure/stable/promise';from(newSet([1,2,3,2,1]));flat([1,[2,3],[4,[5]]],2);Promise.resolve(32).then(x=>console.log(x));

you can write just:

Array.from(newSet([1,2,3,2,1]));[1,[2,3],[4,[5]]].flat(2);Promise.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 byproposals option, ascorejs: { 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.

swc

Fast JavaScript transpilerswccontains integration withcore-js, that optimizes work with the global version ofcore-js.Like@babel/preset-env, it has 2 modes:usage andentry, butusage mode still works not so well as inbabel. Example of configuration in.swcrc:

{"env": {"targets":"> 0.25%, not dead","mode":"entry","coreJs":"3.44"  }}

Configurable level of aggressiveness

By default,core-js sets polyfills only when they are required. That means thatcore-js checks if a feature is available and works correctly or not and if it has no problems,core-js uses native implementation.

But sometimescore-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 bycore-js feature detection.

For those cases, we could redefine this behavior for certain polyfills:

constconfigurator=require('core-js/configurator');configurator({useNative:['Promise'],// polyfills will be used only if natives are completely unavailableusePolyfill:['Array.from','String.prototype.padEnd'],// polyfills will be used anywayuseFeatureDetection:['Map','Set'],// default behavior});require('core-js/actual');

It does not work with some features. Also, if you change the default behavior, evencore-js internals may not work correctly.

Custom build

For some cases could be useful to exclude somecore-js features or generate a polyfill for target engines. You could usecore-js-builder package for that.

Supported engines and compatibility data

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 testcore-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 (ascore-js-compat package) all required data about the necessity ofcore-js modules, entry points, and tools for work with it - it's useful for integration with tools likebabel orswc. If you wanna help, you could take a look at the related section ofCONTRIBUTING.md. The visualization of compatibility data and the browser tests runner is availablehere, the example:

compat-table

Features:

CommonJS entry points:

core-js(-pure)

ECMAScript

CommonJS entry points:

core-js(-pure)/es

ECMAScript: Object

Moduleses.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.

classObject{toString():string;// ES2015+ fix: @@toStringTag support__defineGetter__(property:PropertyKey,getter:Function):void;__defineSetter__(property:PropertyKey,setter:Function):void;__lookupGetter__(property:PropertyKey):Function|void;__lookupSetter__(property:PropertyKey):Function|void;__proto__:Object|null;// required a way setting of prototype - will not in IE10-, it's for modern engines like Denostaticassign(target:Object, ...sources:Array<Object>):Object;staticcreate(prototype:Object|null,properties?:{[property:PropertyKey]:PropertyDescriptor}):Object;staticdefineProperties(object:Object,properties:{[property:PropertyKey]:PropertyDescriptor})):Object;staticdefineProperty(object:Object,property:PropertyKey,attributes:PropertyDescriptor):Object;staticentries(object:Object):Array<[string,mixed]>;staticfreeze(object:any):any;staticfromEntries(iterable:Iterable<[key,value]>):Object;staticgetOwnPropertyDescriptor(object:any,property:PropertyKey):PropertyDescriptor|void;staticgetOwnPropertyDescriptors(object:any):{[property:PropertyKey]:PropertyDescriptor};staticgetOwnPropertyNames(object:any):Array<string>;staticgetPrototypeOf(object:any):Object|null;staticgroupBy(items:Iterable,callbackfn:(value:any,index:number)=>key):{[key]:Array<mixed>};statichasOwn(object:object,key:PropertyKey):boolean;staticis(value1:any,value2:any):boolean;staticisExtensible(object:any):boolean;staticisFrozen(object:any):boolean;staticisSealed(object:any):boolean;statickeys(object:any):Array<string>;staticpreventExtensions(object:any):any;staticseal(object:any):any;staticsetPrototypeOf(target:any,prototype:Object|null):any;// required __proto__ - IE11+staticvalues(object:any):Array<mixed>;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/objectcore-js(-pure)/es|stable|actual|full/object/assigncore-js(-pure)/es|stable|actual|full/object/iscore-js(-pure)/es|stable|actual|full/object/set-prototype-ofcore-js(-pure)/es|stable|actual|full/object/get-prototype-ofcore-js(-pure)/es|stable|actual|full/object/createcore-js(-pure)/es|stable|actual|full/object/define-propertycore-js(-pure)/es|stable|actual|full/object/define-propertiescore-js(-pure)/es|stable|actual|full/object/get-own-property-descriptorcore-js(-pure)/es|stable|actual|full/object/get-own-property-descriptorscore-js(-pure)/es|stable|actual|full/object/group-bycore-js(-pure)/es|stable|actual|full/object/has-owncore-js(-pure)/es|stable|actual|full/object/keyscore-js(-pure)/es|stable|actual|full/object/valuescore-js(-pure)/es|stable|actual|full/object/entriescore-js(-pure)/es|stable|actual|full/object/get-own-property-namescore-js(-pure)/es|stable|actual|full/object/freezecore-js(-pure)/es|stable|actual|full/object/from-entriescore-js(-pure)/es|stable|actual|full/object/sealcore-js(-pure)/es|stable|actual|full/object/prevent-extensionscore-js/es|stable|actual|full/object/protocore-js(-pure)/es|stable|actual|full/object/is-frozencore-js(-pure)/es|stable|actual|full/object/is-sealedcore-js(-pure)/es|stable|actual|full/object/is-extensiblecore-js/es|stable|actual|full/object/to-stringcore-js(-pure)/es|stable|actual|full/object/define-gettercore-js(-pure)/es|stable|actual|full/object/define-settercore-js(-pure)/es|stable|actual|full/object/lookup-gettercore-js(-pure)/es|stable|actual|full/object/lookup-setter

Examples:

letfoo={q:1,w:2};letbar={e:3,r:4};letbaz={t:5,y:6};Object.assign(foo,bar,baz);// => foo = { q: 1, w: 2, e: 3, r: 4, t: 5, y: 6 }Object.is(NaN,NaN);// => trueObject.is(0,-0);// => falseObject.is(42,42);// => trueObject.is(42,'42');// => falsefunctionParent(){/* empty */}functionChild(){/* empty */}Object.setPrototypeOf(Child.prototype,Parent.prototype);newChild()instanceofChild;// => truenewChild()instanceofParent;// => true({[Symbol.toStringTag]:'Foo',}).toString();// => '[object Foo]'Object.keys('qwe');// => ['0', '1', '2']Object.getPrototypeOf('qwe')===String.prototype;// => trueObject.values({a:1,b:2,c:3});// => [1, 2, 3]Object.entries({a:1,b:2,c:3});// => [['a', 1], ['b', 2], ['c', 3]]for(let[key,value]ofObject.entries({a:1,b:2,c:3})){console.log(key);// => 'a', 'b', 'c'console.log(value);// => 1, 2, 3}// Shallow object cloning with prototype and descriptors:letcopy=Object.create(Object.getPrototypeOf(object),Object.getOwnPropertyDescriptors(object));// Mixin:Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));constmap=newMap([['a',1],['b',2]]);Object.fromEntries(map);// => { a: 1, b: 2 }classUnit{constructor(id){this.id=id;}toString(){return`unit${this.id}`;}}constunits=newSet([newUnit(101),newUnit(102)]);Object.fromEntries(units.entries());// => { unit101: Unit { id: 101 }, unit102: Unit { id: 102 }}Object.hasOwn({foo:42},'foo');// => trueObject.hasOwn({foo:42},'bar');// => falseObject.hasOwn({},'toString');// => falseObject.groupBy([1,2,3,4,5],it=>it%2);// => { 1: [1, 3, 5], 0: [2, 4] }

ECMAScript: Function

Moduleses.function.name,es.function.has-instance. Just ES5:es.function.bind.

classFunction{name:string;bind(thisArg:any, ...args:Array<mixed>):Function;  @@hasInstance(value: any):boolean;}

CommonJS entry points:

core-js/es|stable|actual|full/functioncore-js/es|stable|actual|full/function/namecore-js/es|stable|actual|full/function/has-instancecore-js(-pure)/es|stable|actual|full/function/bindcore-js(-pure)/es|stable|actual|full/function/virtual/bind

Example:

(functionfoo(){/* empty */}).name;// => 'foo'console.log.bind(console,42)(43);// => 42 43

ECMAScript: Error

Moduleses.aggregate-error,es.aggregate-error.cause,es.error.cause,es.error.is-error,es.suppressed-error.constructor,es.error.to-string.

classError{staticisError(value:any):boolean;constructor(message:string,{cause:any}):%Error%;toString():string;// different fixes}class[EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,WebAssembly.CompileError,WebAssembly.LinkError,WebAssembly.RuntimeError,]extendsError{constructor(message: string,{cause:any}):%Error%;}classAggregateErrorextendsError{constructor(errors:Iterable,message?:string,{cause:any}?):AggregateError;errors:Array<any>;message:string;cause:any;}classSuppressedErrorextendsError{constructor(error:any,suppressed:any,message?:string):SuppressedError;error:any;suppressed:any;message:string;}

CommonJS entry points:

core-js/es|stable|actual|full/errorcore-js/es|stable|actual|full/error/constructorcore-js(-pure)/es|stable|actual|full/error/is-errorcore-js/es|stable|actual|full/error/to-stringcore-js(-pure)/es|stable|actual|full/aggregate-errorcore-js(-pure)/es|stable|actual|full/suppressed-error

Example:

consterror1=newTypeError('Error 1');consterror2=newTypeError('Error 2');constaggregate=newAggregateError([error1,error2],'Collected errors');aggregate.errors[0]===error1;// => trueaggregate.errors[1]===error2;// => trueconstcause=newTypeError('Something wrong');consterror=newTypeError('Here explained what`s wrong',{ cause});error.cause===cause;// => trueError.prototype.toString.call({message:1,name:2})==='2: 1';// => true

Example:

Error.isError(newError('error'));// => trueError.isError(newTypeError('error'));// => trueError.isError(newDOMException('error'));// => trueError.isError(null);// => falseError.isError({});// => falseError.isError(Object.create(Error.prototype));// => false

Warning

We have no bulletproof way to polyfill thisError.isError / check if the object is an error, so it's an enough naive implementation.

ECMAScript: Array

Moduleses.array.from,es.array.from-async,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.

classArray{at(index:int):any;concat(...args:Array<mixed>):Array<mixed>;// with adding support of @@isConcatSpreadable and @@speciescopyWithin(target:number,start:number,end?:number): this;entries():Iterator<[index,value]>;every(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):boolean;fill(value:any,start?:number,end?:number): this;filter(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):Array<mixed>;// with adding support of @@speciesfind(callbackfn:(value:any,index:number,target:any)=>boolean),thisArg?:any):any;findIndex(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):uint;findLast(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):any;findLastIndex(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):uint;flat(depthArg?:number=1):Array<mixed>;flatMap(mapFn:(value:any,index:number,target:any)=>any,thisArg:any):Array<mixed>;forEach(callbackfn:(value:any,index:number,target:any)=>void,thisArg?:any):void;includes(searchElement:any,from?:number):boolean;indexOf(searchElement:any,from?:number):number;join(separator:string=','):string;keys():Iterator<index>;lastIndexOf(searchElement:any,from?:number):number;map(mapFn:(value:any,index:number,target:any)=>any,thisArg?:any):Array<mixed>;// with adding support of @@speciespush(...args:Array<mixed>):uint;reduce(callbackfn:(memo:any,value:any,index:number,target:any)=>any,initialValue?:any):any;reduceRight(callbackfn:(memo:any,value:any,index:number,target:any)=>any,initialValue?:any):any;reverse(): this;// Safari 12.0 bug fixslice(start?:number,end?:number):Array<mixed>;// with adding support of @@speciessplice(start?:number,deleteCount?:number, ...items:Array<mixed>):Array<mixed>;// with adding support of @@speciessome(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):boolean;sort(comparefn?:(a:any,b:any)=>number): this;// with modern behavior like stable sorttoReversed():Array<mixed>;toSpliced(start?:number,deleteCount?:number, ...items:Array<mixed>):Array<mixed>;toSorted(comparefn?:(a:any,b:any)=>number):Array<mixed>;unshift(...args:Array<mixed>):uint;values():Iterator<value>;with(index:includes,value:any):Array<mixed>;  @@iterator():Iterator<value>;  @@unscopables:{[newMethodNames:string]:true};staticfrom(items:Iterable|ArrayLike,mapFn?:(value:any,index:number)=>any,thisArg?:any):Array<mixed>;staticfromAsync(asyncItems:AsyncIterable|Iterable|ArrayLike,mapfn?:(value:any,index:number)=>any,thisArg?:any):Array;staticisArray(value:any):boolean;staticof(...args:Array<mixed>):Array<mixed>;}classArguments{  @@iterator():Iterator<value>;// available only in core-js methods}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/arraycore-js(-pure)/es|stable|actual|full/array/fromcore-js(-pure)/es|stable|actual|full/array/from-asynccore-js(-pure)/es|stable|actual|full/array/ofcore-js(-pure)/es|stable|actual|full/array/is-arraycore-js(-pure)/es|stable|actual|full/array(/virtual)/atcore-js(-pure)/es|stable|actual|full/array(/virtual)/concatcore-js(-pure)/es|stable|actual|full/array(/virtual)/copy-withincore-js(-pure)/es|stable|actual|full/array(/virtual)/entriescore-js(-pure)/es|stable|actual|full/array(/virtual)/everycore-js(-pure)/es|stable|actual|full/array(/virtual)/fillcore-js(-pure)/es|stable|actual|full/array(/virtual)/filtercore-js(-pure)/es|stable|actual|full/array(/virtual)/findcore-js(-pure)/es|stable|actual|full/array(/virtual)/find-indexcore-js(-pure)/es|stable|actual|full/array(/virtual)/find-lastcore-js(-pure)/es|stable|actual|full/array(/virtual)/find-last-indexcore-js(-pure)/es|stable|actual|full/array(/virtual)/flatcore-js(-pure)/es|stable|actual|full/array(/virtual)/flat-mapcore-js(-pure)/es|stable|actual|full/array(/virtual)/for-eachcore-js(-pure)/es|stable|actual|full/array(/virtual)/includescore-js(-pure)/es|stable|actual|full/array(/virtual)/index-ofcore-js(-pure)/es|stable|actual|full/array(/virtual)/iteratorcore-js(-pure)/es|stable|actual|full/array(/virtual)/joincore-js(-pure)/es|stable|actual|full/array(/virtual)/keyscore-js(-pure)/es|stable|actual|full/array(/virtual)/last-index-ofcore-js(-pure)/es|stable|actual|full/array(/virtual)/mapcore-js(-pure)/es|stable|actual|full/array(/virtual)/pushcore-js(-pure)/es|stable|actual|full/array(/virtual)/reducecore-js(-pure)/es|stable|actual|full/array(/virtual)/reduce-rightcore-js(-pure)/es|stable|actual|full/array(/virtual)/reversecore-js(-pure)/es|stable|actual|full/array(/virtual)/slicecore-js(-pure)/es|stable|actual|full/array(/virtual)/somecore-js(-pure)/es|stable|actual|full/array(/virtual)/sortcore-js(-pure)/es|stable|actual|full/array(/virtual)/splicecore-js(-pure)/es|stable|actual|full/array(/virtual)/to-reversedcore-js(-pure)/es|stable|actual|full/array(/virtual)/to-sortedcore-js(-pure)/es|stable|actual|full/array(/virtual)/to-splicedcore-js(-pure)/es|stable|actual|full/array(/virtual)/unshiftcore-js(-pure)/es|stable|actual|full/array(/virtual)/valuescore-js(-pure)/es|stable|actual|full/array(/virtual)/with

Examples:

Array.from(newSet([1,2,3,2,1]));// => [1, 2, 3]Array.from({0:1,1:2,2:3,length:3});// => [1, 2, 3]Array.from('123',Number);// => [1, 2, 3]Array.from('123',it=>it**2);// => [1, 4, 9]Array.of(1);// => [1]Array.of(1,2,3);// => [1, 2, 3]letarray=['a','b','c'];for(letvalueofarray)console.log(value);// => 'a', 'b', 'c'for(letvalueofarray.values())console.log(value);// => 'a', 'b', 'c'for(letkeyofarray.keys())console.log(key);// => 0, 1, 2for(let[key,value]ofarray.entries()){console.log(key);// => 0, 1, 2console.log(value);// => 'a', 'b', 'c'}functionisOdd(value){returnvalue%2;}[4,8,15,16,23,42].find(isOdd);// => 15[4,8,15,16,23,42].findIndex(isOdd);// => 2[1,2,3,4].findLast(isOdd);// => 3[1,2,3,4].findLastIndex(isOdd);// => 2Array(5).fill(42);// => [42, 42, 42, 42, 42][1,2,3,4,5].copyWithin(0,3);// => [4, 5, 3, 4, 5][1,2,3].includes(2);// => true[1,2,3].includes(4);// => false[1,2,3].includes(2,2);// => false[NaN].indexOf(NaN);// => -1[NaN].includes(NaN);// => trueArray(1).indexOf(undefined);// => -1Array(1).includes(undefined);// => true[1,[2,3],[4,5]].flat();// => [1, 2, 3, 4, 5][1,[2,[3,[4]]],5].flat();// => [1, 2, [3, [4]], 5][1,[2,[3,[4]]],5].flat(3);// => [1, 2, 3, 4, 5][{a:1,b:2},{a:3,b:4},{a:5,b:6}].flatMap(it=>[it.a,it.b]);// => [1, 2, 3, 4, 5, 6][1,2,3].at(1);// => 2[1,2,3].at(-1);// => 3constsequence=[1,2,3];sequence.toReversed();// => [3, 2, 1]sequence;// => [1, 2, 3]constinitialArray=[1,2,3,4];initialArray.toSpliced(1,2,5,6,7);// => [1, 5, 6, 7, 4]initialArray;// => [1, 2, 3, 4]constoutOfOrder=[3,1,2];outOfOrder.toSorted();// => [1, 2, 3]outOfOrder;// => [3, 1, 2]constcorrectionNeeded=[1,1,3];correctionNeeded.with(1,2);// => [1, 2, 3]correctionNeeded;// => [1, 1, 3]

Array.fromAsync example:

awaitArray.fromAsync((asyncfunction*(){yield*[1,2,3];})(),i=>i**2);// => [1, 4, 9]

ECMAScript: Iterator

Moduleses.iterator.constructor,es.iterator.dispose,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

classIterator{staticfrom(iterable:Iterable<any>|Iterator<any>):Iterator<any>;drop(limit:uint):Iterator<any>;every(callbackfn:(value:any,counter:uint)=>boolean):boolean;filter(callbackfn:(value:any,counter:uint)=>boolean):Iterator<any>;find(callbackfn:(value:any,counter:uint)=>boolean)):any;flatMap(callbackfn:(value:any,counter:uint)=>Iterable<any>|Iterator<any>):Iterator<any>;forEach(callbackfn:(value:any,counter:uint)=>void):void;map(callbackfn:(value:any,counter:uint)=>any):Iterator<any>;reduce(callbackfn:(memo:any,value:any,counter:uint)=>any,initialValue:any):any;some(callbackfn:(value:any,counter:uint)=>boolean):boolean;take(limit:uint):Iterator<any>;toArray():Array<any>;  @@dispose():undefined;  @@toStringTag:'Iterator'}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/iteratorcore-js(-pure)/es|stable|actual|full/iterator/disposecore-js(-pure)/es|stable|actual|full/iterator/dropcore-js(-pure)/es|stable|actual|full/iterator/everycore-js(-pure)/es|stable|actual|full/iterator/filtercore-js(-pure)/es|stable|actual|full/iterator/findcore-js(-pure)/es|stable|actual|full/iterator/flat-mapcore-js(-pure)/es|stable|actual|full/iterator/for-eachcore-js(-pure)/es|stable|actual|full/iterator/fromcore-js(-pure)/es|stable|actual|full/iterator/mapcore-js(-pure)/es|stable|actual|full/iterator/reducecore-js(-pure)/es|stable|actual|full/iterator/somecore-js(-pure)/es|stable|actual|full/iterator/takecore-js(-pure)/es|stable|actual|full/iterator/to-array

Examples:

[1,2,3,4,5,6,7].values().drop(1).take(5).filter(it=>it%2).map(it=>it**2).toArray();// => [9, 25]Iterator.from({next:()=>({done:Math.random()>0.9,value:Math.random()*10|0}),}).toArray();// => [7, 6, 3, 0, 2, 8]

Warning

  • For preventing prototype pollution, in thepure 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).

ECMAScript: String and RegExp

The main part ofString features: moduleses.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-knownsymbols@@match,@@replace,@@search and@@split and direct.exec calls to relatedString methods, moduleses.string.match,es.string.replace,es.string.search andes.string.split.

Annex B methods. Moduleses.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 andes.unescape.

RegExp features: moduleses.regexp.constructor,es.regexp.escape,es.regexp.dot-all,es.regexp.flags,es.regexp.sticky andes.regexp.test.

classString{staticfromCodePoint(...codePoints:Array<number>):string;staticraw({raw:Array<string>}, ...substitutions:Array<string>):string;at(index:int):string;includes(searchString:string,position?:number):boolean;startsWith(searchString:string,position?:number):boolean;endsWith(searchString:string,position?:number):boolean;repeat(count:number):string;padStart(length:number,fillStr?:string=' '):string;padEnd(length:number,fillStr?:string=' '):string;codePointAt(pos:number):number|void;match(template:any):any;// ES2015+ fix for support @@matchmatchAll(regexp:RegExp):Iterator;replace(template:any,replacer:any):any;// ES2015+ fix for support @@replacereplaceAll(searchValue:string|RegExp,replaceString:string|(searchValue,index,this)=>string):string;search(template:any):any;// ES2015+ fix for support @@searchsplit(template:any,limit?:int):Array<string>;;// ES2015+ fix for support @@split, some fixes for old enginestrim():string;trimLeft():string;trimRight():string;trimStart():string;trimEnd():string;isWellFormed():boolean;toWellFormed():string;anchor(name:string):string;big():string;blink():string;bold():string;fixed():string;fontcolor(color:string):string;fontsize(size:any):string;italics():string;link(url:string):string;small():string;strike():string;sub():string;substr(start:int,length?:int):string;sup():string;  @@iterator():Iterator<characters>;}classRegExp{// support of sticky (`y`) flag, dotAll (`s`) flag, named capture groups, can alter flagsconstructor(pattern:RegExp|string,flags?:string):RegExp;staticescape(value:string):stringexec():Array<string|undefined>|null;// IE8 fixestest(string:string):boolean;// delegation to `.exec`toString():string;// ES2015+ fix - generic  @@match(string:string):Array|null;  @@matchAll(string:string):Iterator;  @@replace(string:string,replaceValue:Function|string):string;  @@search(string:string):number;  @@split(string:string,limit:number):Array<string>;readonlyattributedotAll:boolean;// IE9+readonlyattributeflags:string;// IE9+readonlyattributesticky:boolean;// IE9+}functionescape(string:string):string;functionunescape(string:string):string;

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/stringcore-js(-pure)/es|stable|actual|full/string/from-code-pointcore-js(-pure)/es|stable|actual|full/string/rawcore-js/es|stable|actual|full/string/matchcore-js/es|stable|actual|full/string/replacecore-js/es|stable|actual|full/string/searchcore-js/es|stable|actual|full/string/splitcore-js(-pure)/es|stable|actual/string(/virtual)/atcore-js(-pure)/es|stable|actual|full/string(/virtual)/code-point-atcore-js(-pure)/es|stable|actual|full/string(/virtual)/ends-withcore-js(-pure)/es|stable|actual|full/string(/virtual)/includescore-js(-pure)/es|stable|actual|full/string(/virtual)/starts-withcore-js(-pure)/es|stable|actual|full/string(/virtual)/match-allcore-js(-pure)/es|stable|actual|full/string(/virtual)/pad-startcore-js(-pure)/es|stable|actual|full/string(/virtual)/pad-endcore-js(-pure)/es|stable|actual|full/string(/virtual)/repeatcore-js(-pure)/es|stable|actual|full/string(/virtual)/replace-allcore-js(-pure)/es|stable|actual|full/string(/virtual)/trimcore-js(-pure)/es|stable|actual|full/string(/virtual)/trim-startcore-js(-pure)/es|stable|actual|full/string(/virtual)/trim-endcore-js(-pure)/es|stable|actual|full/string(/virtual)/trim-leftcore-js(-pure)/es|stable|actual|full/string(/virtual)/trim-rightcore-js(-pure)/es|stable|actual|full/string(/virtual)/is-well-formedcore-js(-pure)/es|stable|actual|full/string(/virtual)/to-well-formedcore-js(-pure)/es|stable|actual|full/string(/virtual)/anchorcore-js(-pure)/es|stable|actual|full/string(/virtual)/bigcore-js(-pure)/es|stable|actual|full/string(/virtual)/blinkcore-js(-pure)/es|stable|actual|full/string(/virtual)/boldcore-js(-pure)/es|stable|actual|full/string(/virtual)/fixedcore-js(-pure)/es|stable|actual|full/string(/virtual)/fontcolorcore-js(-pure)/es|stable|actual|full/string(/virtual)/fontsizecore-js(-pure)/es|stable|actual|full/string(/virtual)/italicscore-js(-pure)/es|stable|actual|full/string(/virtual)/linkcore-js(-pure)/es|stable|actual|full/string(/virtual)/smallcore-js(-pure)/es|stable|actual|full/string(/virtual)/strikecore-js(-pure)/es|stable|actual|full/string(/virtual)/subcore-js(-pure)/es|stable|actual|full/string(/virtual)/substrcore-js(-pure)/es|stable|actual|full/string(/virtual)/supcore-js(-pure)/es|stable|actual|full/string(/virtual)/iteratorcore-js/es|stable|actual|full/regexpcore-js/es|stable|actual|full/regexp/constructorcore-js(-pure)/es|stable|actual|full/regexp/escapecore-js/es|stable|actual|full/regexp/dot-allcore-js(-pure)/es|stable|actual|full/regexp/flagscore-js/es|stable|actual|full/regexp/stickycore-js/es|stable|actual|full/regexp/testcore-js/es|stable|actual|full/regexp/to-stringcore-js/es|stable|actual|full/escapecore-js/es|stable|actual|full/unescape

Examples:

for(letvalueof'a𠮷b'){console.log(value);// => 'a', '𠮷', 'b'}'foobarbaz'.includes('bar');// => true'foobarbaz'.includes('bar',4);// => false'foobarbaz'.startsWith('foo');// => true'foobarbaz'.startsWith('bar',3);// => true'foobarbaz'.endsWith('baz');// => true'foobarbaz'.endsWith('bar',6);// => true'string'.repeat(3);// => 'stringstringstring''hello'.padStart(10);// => '     hello''hello'.padStart(10,'1234');// => '12341hello''hello'.padEnd(10);// => 'hello     ''hello'.padEnd(10,'1234');// => 'hello12341''𠮷'.codePointAt(0);// => 134071String.fromCodePoint(97,134071,98);// => 'a𠮷b'letname='Bob';String.raw`Hi\n${name}!`;// => 'Hi\\nBob!' (ES2015 template string syntax)String.raw({raw:'test'},0,1,2);// => 't0e1s2t''foo'.bold();// => '<b>foo</b>''bar'.anchor('a"b');// => '<a name="a&quot;b">bar</a>''baz'.link('https://example.com');// => '<a href="https://example.com">baz</a>'RegExp('.','s').test('\n');// => trueRegExp('.','s').dotAll;// => trueRegExp('foo:(?<foo>\\w+),bar:(?<bar>\\w+)').exec('foo:abc,bar:def').groups;// => { foo: 'abc', bar: 'def' }'foo:abc,bar:def'.replace(RegExp('foo:(?<foo>\\w+),bar:(?<bar>\\w+)'),'$<bar>,$<foo>');// => 'def,abc'// eslint-disable-next-line regexp/no-useless-flag -- exampleRegExp(/./g,'m');// => /./m/foo/.flags;// => ''/foo/gi.flags;// => 'gi'RegExp('foo','y').sticky;// => trueconsttext='First line\nSecond line';constregex=RegExp('(?<index>\\S+) line\\n?','y');regex.exec(text).groups.index;// => 'First'regex.exec(text).groups.index;// => 'Second'regex.exec(text);// => null'foo'.match({[Symbol.match]:()=>1});// => 1'foo'.replace({[Symbol.replace]:()=>2});// => 2'foo'.search({[Symbol.search]:()=>3});// => 3'foo'.split({[Symbol.split]:()=>4});// => 4RegExp.prototype.toString.call({source:'foo',flags:'bar'});// => '/foo/bar''   hello   '.trimLeft();// => 'hello   ''   hello   '.trimRight();// => '   hello''   hello   '.trimStart();// => 'hello   ''   hello   '.trimEnd();// => '   hello'for(let{groups:{ number, letter}}of'1111a2b3cccc'.matchAll(RegExp('(?<number>\\d)(?<letter>\\D)','g'))){console.log(number,letter);// => 1 a, 2 b, 3 c}'Test abc test test abc test.'.replaceAll('abc','foo');// -> 'Test foo test test foo test.''abc'.at(1);// => 'b''abc'.at(-1);// => 'c''a💩b'.isWellFormed();// => true'a\uD83Db'.isWellFormed();// => false'a💩b'.toWellFormed();// => 'a💩b''a\uD83Db'.toWellFormed();// => 'a�b'

Example:

console.log(RegExp.escape('10$'));// => '\\x310\\$'console.log(RegExp.escape('abcdefg_123456'));// => '\\x61bcdefg_123456'console.log(RegExp.escape('Привет'));// => 'Привет'console.log(RegExp.escape('(){}[]|,.?*+-^$=<>\\/#&!%:;@~\'"`'));// => '\\(\\)\\{\\}\\[\\]\\|\\x2c\\.\\?\\*\\+\\x2d\\^\\$\\x3d\\x3c\\x3e\\\\\\/\\x23\\x26\\x21\\x25\\x3a\\x3b\\x40\\x7e\\x27\\x22\\x60'console.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'));// => '\\\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'console.log(RegExp.escape('💩'));// => '💩'console.log(RegExp.escape('\uD83D'));// => '\\ud83d'

ECMAScript: Number

Modulees.number.constructor.Number constructor support binary and octal literals,example:

Number('0b1010101');// => 85Number('0o7654321');// => 2054353

Moduleses.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.

classNumber{constructor(value:any):number;toExponential(digits:number):string;toFixed(digits:number):string;toPrecision(precision:number):string;staticisFinite(number:any):boolean;staticisNaN(number:any):boolean;staticisInteger(number:any):boolean;staticisSafeInteger(number:any):boolean;staticparseFloat(string:string):number;staticparseInt(string:string,radix?:number=10):number;staticEPSILON:number;staticMAX_SAFE_INTEGER:number;staticMIN_SAFE_INTEGER:number;}functionparseFloat(string:string):number;functionparseInt(string:string,radix?:number=10):number;

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/numbercore-js(-pure)/es|stable|actual|full/number/constructorcore-js(-pure)/es|stable|actual|full/number/is-finitecore-js(-pure)/es|stable|actual|full/number/is-nancore-js(-pure)/es|stable|actual|full/number/is-integercore-js(-pure)/es|stable|actual|full/number/is-safe-integercore-js(-pure)/es|stable|actual|full/number/parse-floatcore-js(-pure)/es|stable|actual|full/number/parse-intcore-js(-pure)/es|stable|actual|full/number/epsiloncore-js(-pure)/es|stable|actual|full/number/max-safe-integercore-js(-pure)/es|stable|actual|full/number/min-safe-integercore-js(-pure)/es|stable|actual|full/number(/virtual)/to-exponentialcore-js(-pure)/es|stable|actual|full/number(/virtual)/to-fixedcore-js(-pure)/es|stable|actual|full/number(/virtual)/to-precisioncore-js(-pure)/es|stable|actual|full/parse-floatcore-js(-pure)/es|stable|actual|full/parse-int

ECMAScript: Math

Moduleses.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.f16round,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.

namespaceMath{acosh(number:number): number;asinh(number:number): number;atanh(number:number): number;cbrt(number:number): number;clz32(number:number): number;cosh(number:number): number;expm1(number:number): number;fround(number:number): number;f16round(number: any): number;hypot(...args:Array<number>): number;imul(number1: number,number2: number): number;log1p(number:number): number;log10(number:number): number;log2(number:number): number;sign(number:number):1|-1|0|-0|NaN;sinh(number:number): number;tanh(number:number): number;trunc(number:number): number;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/mathcore-js(-pure)/es|stable|actual|full/math/acoshcore-js(-pure)/es|stable|actual|full/math/asinhcore-js(-pure)/es|stable|actual|full/math/atanhcore-js(-pure)/es|stable|actual|full/math/cbrtcore-js(-pure)/es|stable|actual|full/math/clz32core-js(-pure)/es|stable|actual|full/math/coshcore-js(-pure)/es|stable|actual|full/math/expm1core-js(-pure)/es|stable|actual|full/math/froundcore-js(-pure)/es|stable|actual|full/math/f16roundcore-js(-pure)/es|stable|actual|full/math/hypotcore-js(-pure)/es|stable|actual|full/math/imulcore-js(-pure)/es|stable|actual|full/math/log1pcore-js(-pure)/es|stable|actual|full/math/log10core-js(-pure)/es|stable|actual|full/math/log2core-js(-pure)/es|stable|actual|full/math/signcore-js(-pure)/es|stable|actual|full/math/sinhcore-js(-pure)/es|stable|actual|full/math/tanhcore-js(-pure)/es|stable|actual|full/math/trunc

ECMAScript: Date

Moduleses.date.to-string, ES5 features with fixes:es.date.now,es.date.to-iso-string,es.date.to-json andes.date.to-primitive.

Annex B methods. Moduleses.date.get-year,es.date.set-year andes.date.to-gmt-string.

classDate{getYear():int;setYear(year:int):number;toGMTString():string;toISOString():string;toJSON():string;toString():string;  @@toPrimitive(hint:'default'|'number'|'string'):string|number;staticnow():number;}

CommonJS entry points:

core-js/es|stable|actual|full/datecore-js/es|stable|actual|full/date/to-stringcore-js(-pure)/es|stable|actual|full/date/nowcore-js(-pure)/es|stable|actual|full/date/get-yearcore-js(-pure)/es|stable|actual|full/date/set-yearcore-js(-pure)/es|stable|actual|full/date/to-gmt-stringcore-js(-pure)/es|stable|actual|full/date/to-iso-stringcore-js(-pure)/es|stable|actual|full/date/to-jsoncore-js(-pure)/es|stable|actual|full/date/to-primitive

Example:

newDate(NaN).toString();// => 'Invalid Date'

ECMAScript: Promise

Moduleses.promise,es.promise.all-settled,es.promise.any,es.promise.finally,es.promise.try andes.promise.with-resolvers.

classPromise{constructor(executor:(resolve:Function,reject:Function)=>void):Promise;then(onFulfilled:Function,onRejected:Function):Promise;catch(onRejected:Function):Promise;finally(onFinally:Function):Promise;staticall(iterable:Iterable):Promise;staticallSettled(iterable:Iterable):Promise;staticany(promises:Iterable):Promise;staticrace(iterable:Iterable):Promise;staticreject(r:any):Promise;staticresolve(x:any):Promise;statictry(callbackfn:Function, ...args?:Array<mixed>):Promise;staticwithResolvers():{promise:Promise,resolve:function,reject:function};}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/promisecore-js(-pure)/es|stable|actual|full/promise/all-settledcore-js(-pure)/es|stable|actual|full/promise/anycore-js(-pure)/es|stable|actual|full/promise/finallycore-js(-pure)/es|stable|actual|full/promise/trycore-js(-pure)/es|stable|actual|full/promise/with-resolvers

Basicexample:

/* eslint-disable promise/prefer-await-to-callbacks -- example */functionsleepRandom(time){returnnewPromise((resolve,reject)=>{setTimeout(resolve,time*1e3,0|Math.random()*1e3);});}console.log('Run');// => RunsleepRandom(5).then(result=>{console.log(result);// => 869, after 5 sec.returnsleepRandom(10);}).then(result=>{console.log(result);// => 202, after 10 sec.}).then(()=>{console.log('immediately after');// => immediately afterthrownewError('Irror!');}).then(()=>{console.log('will not be displayed');}).catch(error=>console.log(error));// => => Error: Irror!

Promise.resolve andPromise.rejectexample:

/* eslint-disable promise/prefer-await-to-callbacks -- example */Promise.resolve(42).then(x=>console.log(x));// => 42Promise.reject(42).catch(error=>console.log(error));// => 42Promise.resolve($.getJSON('/data.json'));// => ES promise

Promise#finallyexample:

Promise.resolve(42).finally(()=>console.log('You will see it anyway'));Promise.reject(42).finally(()=>console.log('You will see it anyway'));

Promise.allexample:

Promise.all(['foo',sleepRandom(5),sleepRandom(15),sleepRandom(10),// after 15 sec:]).then(x=>console.log(x));// => ['foo', 956, 85, 382]

Promise.raceexample:

/* eslint-disable promise/prefer-await-to-callbacks -- example */functiontimeLimit(promise,time){returnPromise.race([promise,newPromise((resolve,reject)=>{setTimeout(reject,time*1e3,newError(`Await >${time} sec`));})]);}timeLimit(sleepRandom(5),10).then(x=>console.log(x));// => 853, after 5 sec.timeLimit(sleepRandom(15),10).catch(error=>console.log(error));// Error: Await > 10 sec

Promise.allSettledexample:

Promise.allSettled([Promise.resolve(1),Promise.reject(2),Promise.resolve(3),]).then(console.log);// => [{ value: 1, status: 'fulfilled' }, { reason: 2, status: 'rejected' }, { value: 3, status: 'fulfilled' }]

Promise.anyexample:

Promise.any([Promise.resolve(1),Promise.reject(2),Promise.resolve(3),]).then(console.log);// => 1Promise.any([Promise.reject(1),Promise.reject(2),Promise.reject(3),]).catch(({ errors})=>console.log(errors));// => [1, 2, 3]

Promise.tryexamples:

/* eslint-disable promise/prefer-await-to-callbacks -- example */Promise.try(()=>42).then(it=>console.log(`Promise, resolved as${it}`));Promise.try(()=>{thrownewError('42');}).catch(error=>console.log(`Promise, rejected as${error}`));Promise.try(async()=>42).then(it=>console.log(`Promise, resolved as${it}`));Promise.try(async()=>{thrownewError('42');}).catch(error=>console.log(`Promise, rejected as${error}`));Promise.try(it=>it,42).then(it=>console.log(`Promise, resolved as${it}`));

Promise.withResolversexamples:

constd=Promise.withResolvers();d.resolve(42);d.promise.then(console.log);// => 42

Example with async functions:

letdelay=time=>newPromise(resolve=>setTimeout(resolve,time));asyncfunctionsleepRandom(time){awaitdelay(time*1e3);return0|Math.random()*1e3;}asyncfunctionsleepError(time,msg){awaitdelay(time*1e3);thrownewError(msg);}(async()=>{try{console.log('Run');// => Runconsole.log(awaitsleepRandom(5));// => 936, after 5 sec.let[a,b,c]=awaitPromise.all([sleepRandom(5),sleepRandom(15),sleepRandom(10),]);console.log(a,b,c);// => 210 445 71, after 15 sec.awaitsleepError(5,'Error!');console.log('Will not be displayed');}catch(error){console.log(error);// => Error: 'Error!', after 5 sec.}})();
Unhandled rejection tracking

In Node.js, like in native implementation, available eventsunhandledRejection andrejectionHandled:

process.on('unhandledRejection',(reason,promise)=>console.log('unhandled',reason,promise));process.on('rejectionHandled',promise=>console.log('handled',promise));letpromise=Promise.reject(42);// unhandled 42 [object Promise]// eslint-disable-next-line promise/prefer-await-to-then -- examplesetTimeout(()=>promise.catch(()=>{/* empty */}),1e3);// 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:

globalThis.addEventListener('unhandledrejection',e=>console.log('unhandled',e.reason,e.promise));globalThis.addEventListener('rejectionhandled',e=>console.log('handled',e.reason,e.promise));// orglobalThis.onunhandledrejection=e=>console.log('unhandled',e.reason,e.promise);globalThis.onrejectionhandled=e=>console.log('handled',e.reason,e.promise);letpromise=Promise.reject(42);// => unhandled 42 [object Promise]// eslint-disable-next-line promise/prefer-await-to-then -- examplesetTimeout(()=>promise.catch(()=>{/* empty */}),1e3);// => handled 42 [object Promise]

ECMAScript: Symbol

Moduleses.symbol,es.symbol.async-dispose,es.symbol.async-iterator,es.symbol.description,es.symbol.dispose,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.

classSymbol{constructor(description?):symbol;readonlyattributedescription:string|void;staticasyncDispose: @@asyncDispose;staticasyncIterator: @@asyncIterator;staticdispose: @@dispose;statichasInstance: @@hasInstance;staticisConcatSpreadable: @@isConcatSpreadable;staticiterator: @@iterator;staticmatch: @@match;staticreplace: @@replace;staticsearch: @@search;staticspecies: @@species;staticsplit: @@split;statictoPrimitive: @@toPrimitive;statictoStringTag: @@toStringTag;staticunscopables: @@unscopables;staticfor(key:string):symbol;statickeyFor(sym:symbol):string;staticuseSimple():void;staticuseSetter():void;}classObject{staticgetOwnPropertySymbols(object:any):Array<symbol>;}

Also wrapped some methods for correct work withSymbol polyfill.

classObject{staticcreate(prototype:Object|null,properties?:{[property:PropertyKey]:PropertyDescriptor}):Object;staticdefineProperties(object:Object,properties:{[property:PropertyKey]:PropertyDescriptor})):Object;staticdefineProperty(object:Object,property:PropertyKey,attributes:PropertyDescriptor):Object;staticgetOwnPropertyDescriptor(object:any,property:PropertyKey):PropertyDescriptor|void;staticgetOwnPropertyNames(object:any):Array<string>;propertyIsEnumerable(key:PropertyKey):boolean;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/symbolcore-js(-pure)/es|stable|actual|full/symbol/async-disposecore-js(-pure)/es|stable|actual|full/symbol/async-iteratorcore-js/es|stable|actual|full/symbol/descriptioncore-js(-pure)/es|stable|actual|full/symbol/disposecore-js(-pure)/es|stable|actual|full/symbol/has-instancecore-js(-pure)/es|stable|actual|full/symbol/is-concat-spreadablecore-js(-pure)/es|stable|actual|full/symbol/iteratorcore-js(-pure)/es|stable|actual|full/symbol/matchcore-js(-pure)/es|stable|actual|full/symbol/replacecore-js(-pure)/es|stable|actual|full/symbol/searchcore-js(-pure)/es|stable|actual|full/symbol/speciescore-js(-pure)/es|stable|actual|full/symbol/splitcore-js(-pure)/es|stable|actual|full/symbol/to-primitivecore-js(-pure)/es|stable|actual|full/symbol/to-string-tagcore-js(-pure)/es|stable|actual|full/symbol/unscopablescore-js(-pure)/es|stable|actual|full/symbol/forcore-js(-pure)/es|stable|actual|full/symbol/key-forcore-js(-pure)/es|stable|actual|full/object/get-own-property-symbolscore-js(-pure)/es|stable|actual|full/math/to-string-tag

Basic example:

letPerson=(()=>{letNAME=Symbol('name');returnclass{constructor(name){this[NAME]=name;}getName(){returnthis[NAME];}};})();letperson=newPerson('Vasya');console.log(person.getName());// => 'Vasya'console.log(person.name);// => undefinedconsole.log(person[Symbol('name')]);// => undefined, symbols are uniqfor(letkeyinperson)console.log(key);// => nothing, symbols are not enumerable

Symbol.for &Symbol.keyForexample:

letsymbol=Symbol.for('key');symbol===Symbol.for('key');// trueSymbol.keyFor(symbol);// 'key'

Example with methods for getting own object keys:

letobject={a:1};Object.defineProperty(object,'b',{value:2});object[Symbol('c')]=3;Object.keys(object);// => ['a']Object.getOwnPropertyNames(object);// => ['a', 'b']Object.getOwnPropertySymbols(object);// => [Symbol(c)]Reflect.ownKeys(object);// => ['a', 'b', Symbol(c)]

Symbol#description getter:

Symbol('foo').description;// => 'foo'// eslint-disable-next-line symbol-description -- exampleSymbol().description;// => undefined
Caveats when usingSymbol polyfill:
  • We can't add a new primitive type,Symbol returns an object.
  • Symbol.for andSymbol.keyFor can't be polyfilled cross-realm.
  • By default, to hide the keys,Symbol polyfill defines a setter inObject.prototype. For this reason, an uncontrolled creation of symbols can cause a memory leak and thein operator is not working correctly withSymbol polyfill:Symbol() in {} // => true.

You can disable defining setters inObject.prototype.Example:

Symbol.useSimple();letsymbol1=Symbol('symbol1');letobject1={};object1[symbol1]=true;for(letkeyinobject1)console.log(key);// => 'Symbol(symbol1)_t.qamkg9f3q', w/o native SymbolSymbol.useSetter();letsymbol2=Symbol('symbol2');letobject2={};object2[symbol2]=true;for(letkeyinobject2)console.log(key);// nothing
  • Currently,core-js does not add setters toObject.prototype for well-known symbols for correct work something likeSymbol.iterator in foo. It can cause problems with their enumerability.
  • Some problems are possible with environment exotic objects (for example, IElocalStorage).

ECMAScript: Collections

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).

Map

Moduleses.map andes.map.group-by.

classMap{constructor(iterable?:Iterable<[key,value]>):Map;clear():void;delete(key:any):boolean;forEach(callbackfn:(value:any,key:any,target:any)=>void,thisArg:any):void;get(key:any):any;has(key:any):boolean;set(key:any,val:any): this;values():Iterator<value>;keys():Iterator<key>;entries():Iterator<[key,value]>;  @@iterator():Iterator<[key,value]>;readonlyattributesize:number;staticgroupBy(items:Iterable,callbackfn:(value:any,index:number)=>key):Map<key,Array<mixed>>;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/mapcore-js(-pure)/es|stable|actual|full/map/group-by

Examples:

letarray=[1];letmap=newMap([['a',1],[42,2]]);map.set(array,3).set(true,4);console.log(map.size);// => 4console.log(map.has(array));// => trueconsole.log(map.has([1]));// => falseconsole.log(map.get(array));// => 3map.forEach((val,key)=>{console.log(val);// => 1, 2, 3, 4console.log(key);// => 'a', 42, [1], true});map.delete(array);console.log(map.size);// => 3console.log(map.get(array));// => undefinedconsole.log(Array.from(map));// => [['a', 1], [42, 2], [true, 4]]map=newMap([['a',1],['b',2],['c',3]]);for(let[key,value]ofmap){console.log(key);// => 'a', 'b', 'c'console.log(value);// => 1, 2, 3}for(letvalueofmap.values())console.log(value);// => 1, 2, 3for(letkeyofmap.keys())console.log(key);// => 'a', 'b', 'c'for(let[key,value]ofmap.entries()){console.log(key);// => 'a', 'b', 'c'console.log(value);// => 1, 2, 3}map=Map.groupBy([1,2,3,4,5],it=>it%2);map.get(1);// => [1, 3, 5]map.get(0);// => [2, 4]

Set

Moduleses.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

classSet{constructor(iterable?:Iterable<value>):Set;add(key:any): this;clear():void;delete(key:any):boolean;forEach((value:any,key:any,target:any)=>void,thisArg:any):void;has(key:any):boolean;values():Iterator<value>;keys():Iterator<value>;entries():Iterator<[value,value]>;difference(other:SetLike<mixed>):Set;intersection(other:SetLike<mixed>):Set;isDisjointFrom(other:SetLike<mixed>):boolean;isSubsetOf(other:SetLike<mixed>):boolean;isSupersetOf(other:SetLike<mixed>):boolean;symmetricDifference(other:SetLike<mixed>):Set;union(other:SetLike<mixed>):Set;  @@iterator():Iterator<value>;readonlyattributesize:number;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/setcore-js(-pure)/es|stable|actual|full/set/differencecore-js(-pure)/es|stable|actual|full/set/intersectioncore-js(-pure)/es|stable|actual|full/set/is-disjoint-fromcore-js(-pure)/es|stable|actual|full/set/is-subset-ofcore-js(-pure)/es|stable|actual|full/set/is-superset-ofcore-js(-pure)/es|stable|actual|full/set/symmetric-differencecore-js(-pure)/es|stable|actual|full/set/union

Examples:

letset=newSet(['a','b','a','c']);set.add('d').add('b').add('e');console.log(set.size);// => 5console.log(set.has('b'));// => trueset.forEach(it=>{console.log(it);// => 'a', 'b', 'c', 'd', 'e'});set.delete('b');console.log(set.size);// => 4console.log(set.has('b'));// => falseconsole.log(Array.from(set));// => ['a', 'c', 'd', 'e']set=newSet([1,2,3,2,1]);for(letvalueofset)console.log(value);// => 1, 2, 3for(letvalueofset.values())console.log(value);// => 1, 2, 3for(letkeyofset.keys())console.log(key);// => 1, 2, 3for(let[key,value]ofset.entries()){console.log(key);// => 1, 2, 3console.log(value);// => 1, 2, 3}newSet([1,2,3]).union(newSet([3,4,5]));// => Set {1, 2, 3, 4, 5}newSet([1,2,3]).intersection(newSet([3,4,5]));// => Set {3}newSet([1,2,3]).difference(newSet([3,4,5]));// => Set {1, 2}newSet([1,2,3]).symmetricDifference(newSet([3,4,5]));// => Set {1, 2, 4, 5}newSet([1,2,3]).isDisjointFrom(newSet([4,5,6]));// => truenewSet([1,2,3]).isSubsetOf(newSet([5,4,3,2,1]));// => truenewSet([5,4,3,2,1]).isSupersetOf(newSet([1,2,3]));// => true

WeakMap

Modulees.weak-map.

classWeakMap{constructor(iterable?:Iterable<[key,value]>):WeakMap;delete(key:Object):boolean;get(key:Object):any;has(key:Object):boolean;set(key:Object,val:any): this;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/weak-map

Examples:

leta=[1];letb=[2];letc=[3];letweakmap=newWeakMap([[a,1],[b,2]]);weakmap.set(c,3).set(b,4);console.log(weakmap.has(a));// => trueconsole.log(weakmap.has([1]));// => falseconsole.log(weakmap.get(a));// => 1weakmap.delete(a);console.log(weakmap.get(a));// => undefined// Private properties store:letPerson=(()=>{letnames=newWeakMap();returnclass{constructor(name){names.set(this,name);}getName(){returnnames.get(this);}};})();letperson=newPerson('Vasya');console.log(person.getName());// => 'Vasya'for(letkeyinperson)console.log(key);// => only 'getName'

WeakSet

Modulees.weak-set.

classWeakSet{constructor(iterable?:Iterable<value>):WeakSet;add(key:Object): this;delete(key:Object):boolean;has(key:Object):boolean;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/weak-set

Examples:

leta=[1];letb=[2];letc=[3];letweakset=newWeakSet([a,b,a]);weakset.add(c).add(b).add(c);console.log(weakset.has(b));// => trueconsole.log(weakset.has([2]));// => falseweakset.delete(b);console.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 asWeakMap keys can't be properly polyfilled without memory leaks.

ECMAScript: Explicit Resource Management

Note

This is only built-ins for this Explicit Resource Management,using syntax support requirestranspiler support.

Moduleses.disposable-stack.constructor,es.iterator.dispose,es.async-disposable-stack.constructor,es.async-iterator.async-dispose.

classSymbol{staticasyncDispose: @@asyncDispose;staticdispose: @@dispose;}classDisposableStack{constructor():DisposableStack;dispose():undefined;use(value:Disposable):value;adopt(value:object,onDispose:Function):value;defer(onDispose:Function):undefined;move():DisposableStack;  @@dispose():undefined;  @@toStringTag:'DisposableStack';}classAsyncDisposableStack{constructor():AsyncDisposableStack;disposeAsync():Promise<undefined>;use(value:AsyncDisposable|Disposable):value;adopt(value:object,onDispose:Function):value;defer(onDispose:Function):undefined;move():AsyncDisposableStack;  @@asyncDispose():Promise<undefined>;  @@toStringTag:'AsyncDisposableStack';}classSuppressedErrorextendsError{constructor(error:any,suppressed:any,message?:string):SuppressedError;error:any;suppressed:any;message:string;cause:any;}classIterator{  @@dispose():undefined;}classAsyncIterator{  @@asyncDispose():Promise<undefined>;}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/disposable-stackcore-js(-pure)/es|stable|actual|full/async-disposable-stackcore-js(-pure)/es|stable|actual|full/iterator/disposecore-js(-pure)/es|stable|actual|full/async-iterator/async-dispose

ECMAScript: Typed Arrays

Implementations and fixes forArrayBuffer,DataView, Typed Arrays constructors, static and prototype methods. Typed arrays work only in environments with support descriptors (IE9+),ArrayBuffer andDataView should work anywhere.

Moduleses.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-lengthes.data-view,es.data-view.get-float16,es.data-view.set-float16,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.

classArrayBuffer{constructor(length:any):ArrayBuffer;readonlyattributebyteLength:number;readonlyattributedetached:boolean;slice(start:any,end:any):ArrayBuffer;transfer(newLength?:number):ArrayBuffer;transferToFixedLength(newLength?:number):ArrayBuffer;staticisView(arg:any):boolean;}classDataView{constructor(buffer:ArrayBuffer,byteOffset?:number,byteLength?:number):DataView;getInt8(offset:any):int8;getUint8(offset:any):uint8getInt16(offset:any,littleEndian?:boolean=false):int16;getUint16(offset:any,littleEndian?:boolean=false):uint16;getInt32(offset:any,littleEndian?:boolean=false):int32;getUint32(offset:any,littleEndian?:boolean=false):uint32;getFloat16(offset:any,littleEndian?:boolean=false):float16getFloat32(offset:any,littleEndian?:boolean=false):float32;getFloat64(offset:any,littleEndian?:boolean=false):float64;setInt8(offset:any,value:any):void;setUint8(offset:any,value:any):void;setInt16(offset:any,value:any,littleEndian?:boolean=false):void;setUint16(offset:any,value:any,littleEndian?:boolean=false):void;setInt32(offset:any,value:any,littleEndian?:boolean=false):void;setUint32(offset:any,value:any,littleEndian?:boolean=false):void;setFloat16(offset:any,value:any,littleEndian?:boolean=false):void;setFloat32(offset:any,value:any,littleEndian?:boolean=false):void;setFloat64(offset:any,value:any,littleEndian?:boolean=false):void;readonlyattributebuffer:ArrayBuffer;readonlyattributebyteLength:number;readonlyattributebyteOffset:number;}class[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,]extends%TypedArray%{constructor(length:number):%TypedArray%;constructor(object:%TypedArray%|Iterable|ArrayLike):%TypedArray%;constructor(buffer:ArrayBuffer,byteOffset?:number,length?:number):%TypedArray%}class%TypedArray%{at(index:int): number;copyWithin(target:number,start:number,end?:number):this;entries():Iterator<[index,value]>;every(callbackfn:(value:number,index:number,target:%TypedArray%)=>boolean,thisArg?: any): boolean;fill(value:number,start?:number,end?:number):this;filter(callbackfn:(value:number,index:number,target:%TypedArray%)=>boolean,thisArg?: any):%TypedArray%;find(callbackfn:(value:number,index:number,target:%TypedArray%)=>boolean),thisArg?: any): any;findIndex(callbackfn:(value:number,index:number,target:%TypedArray%)=>boolean,thisArg?: any):uint;findLast(callbackfn:(value: any,index:number,target:%TypedArray%)=>boolean,thisArg?: any): any;findLastIndex(callbackfn:(value: any,index:number,target:%TypedArray%)=>boolean,thisArg?: any):uint;forEach(callbackfn:(value:number,index:number,target:%TypedArray%)=>void,thisArg?:any):void;includes(searchElement: any,from?:number): boolean;indexOf(searchElement: any,from?:number): number;join(separator:string=','): string;keys():Iterator<index>;lastIndexOf(searchElement: any,from?:number): number;map(mapFn:(value:number,index:number,target:%TypedArray%)=>number,thisArg?: any):%TypedArray%;reduce(callbackfn:(memo: any,value:number,index:number,target:%TypedArray%)=>any,initialValue?: any): any;reduceRight(callbackfn:(memo: any,value:number,index:number,target:%TypedArray%)=>any,initialValue?: any): any;reverse():this;set(array:ArrayLike,offset?:number):void;slice(start?:number,end?:number):%TypedArray%;some(callbackfn:(value:number,index:number,target:%TypedArray%)=>boolean,thisArg?: any): boolean;sort(comparefn?:(a:number,b:number)=>number):this;// with modern behavior like stable sortsubarray(begin?:number,end?:number):%TypedArray%;toReversed():%TypedArray%;toSorted(comparefn?:(a:any,b:any)=>number):%TypedArray%;toString(): string;toLocaleString(): string;values():Iterator<value>;with(index:includes,value: any):%TypedArray%;  @@iterator():Iterator<value>;readonlyattributebuffer:ArrayBuffer;readonlyattributebyteLength: number;readonlyattributebyteOffset: number;readonlyattributelength: number;BYTES_PER_ELEMENT: number;staticfrom(items:Iterable|ArrayLike,mapFn?:(value: any,index:number)=>any,thisArg?: any):%TypedArray%;staticof(...args:Array<mixed>):%TypedArray%;staticBYTES_PER_ELEMENT:number;}

CommonJS entry points:

core-js/es|stable|actual|full/array-buffercore-js/es|stable|actual|full/array-buffer/constructorcore-js/es|stable|actual|full/array-buffer/is-viewcore-js/es|stable|actual|full/array-buffer/detachedcore-js/es|stable|actual|full/array-buffer/slicecore-js/es|stable|actual|full/array-buffer/transfercore-js/es|stable|actual|full/array-buffer/transfer-to-fixed-lengthcore-js/es|stable|actual|full/data-viewcore-js/es|stable|actual|full/dataview/get-float16core-js/es|stable|actual|full/dataview/set-float16core-js/es|stable|actual|full/typed-arraycore-js/es|stable|actual|full/typed-array/int8-arraycore-js/es|stable|actual|full/typed-array/uint8-arraycore-js/es|stable|actual|full/typed-array/uint8-clamped-arraycore-js/es|stable|actual|full/typed-array/int16-arraycore-js/es|stable|actual|full/typed-array/uint16-arraycore-js/es|stable|actual|full/typed-array/int32-arraycore-js/es|stable|actual|full/typed-array/uint32-arraycore-js/es|stable|actual|full/typed-array/float32-arraycore-js/es|stable|actual|full/typed-array/float64-arraycore-js/es|stable|actual|full/typed-array/atcore-js/es|stable|actual|full/typed-array/copy-withincore-js/es|stable|actual|full/typed-array/entriescore-js/es|stable|actual|full/typed-array/everycore-js/es|stable|actual|full/typed-array/fillcore-js/es|stable|actual|full/typed-array/filtercore-js/es|stable|actual|full/typed-array/findcore-js/es|stable|actual|full/typed-array/find-indexcore-js/es|stable|actual|full/typed-array/find-lastcore-js/es|stable|actual|full/typed-array/find-last-indexcore-js/es|stable|actual|full/typed-array/for-eachcore-js/es|stable|actual|full/typed-array/fromcore-js/es|stable|actual|full/typed-array/includescore-js/es|stable|actual|full/typed-array/index-ofcore-js/es|stable|actual|full/typed-array/iteratorcore-js/es|stable|actual|full/typed-array/joincore-js/es|stable|actual|full/typed-array/keyscore-js/es|stable|actual|full/typed-array/last-index-ofcore-js/es|stable|actual|full/typed-array/mapcore-js/es|stable|actual|full/typed-array/ofcore-js/es|stable|actual|full/typed-array/reducecore-js/es|stable|actual|full/typed-array/reduce-rightcore-js/es|stable|actual|full/typed-array/reversecore-js/es|stable|actual|full/typed-array/setcore-js/es|stable|actual|full/typed-array/slicecore-js/es|stable|actual|full/typed-array/somecore-js/es|stable|actual|full/typed-array/sortcore-js/es|stable|actual|full/typed-array/subarraycore-js/es|stable|actual|full/typed-array/to-locale-stringcore-js/es|stable|actual|full/typed-array/to-reversedcore-js/es|stable|actual|full/typed-array/to-sortedcore-js/es|stable|actual|full/typed-array/to-stringcore-js/es|stable|actual|full/typed-array/valuescore-js/es|stable|actual|full/typed-array/with

Examples:

newInt32Array(4);// => [0, 0, 0, 0]newUint8ClampedArray([1,2,3,666]);// => [1, 2, 3, 255]newFloat32Array(newSet([1,2,3,2,1]));// => [1, 2, 3]letbuffer=newArrayBuffer(8);letview=newDataView(buffer);view.setFloat64(0,123.456,true);newUint8Array(buffer.slice(4));// => [47, 221, 94, 64]Int8Array.of(1,1.5,5.7,745);// => [1, 1, 5, -23]Uint8Array.from([1,1.5,5.7,745]);// => [1, 1, 5, 233]lettyped=newUint8Array([1,2,3]);leta=typed.slice(1);// => [2, 3]typed.buffer===a.buffer;// => falseletb=typed.subarray(1);// => [2, 3]typed.buffer===b.buffer;// => truetyped.filter(it=>it%2);// => [1, 3]typed.map(it=>it*1.5);// => [1, 3, 4]for(letvalueoftyped)console.log(value);// => 1, 2, 3for(letvalueoftyped.values())console.log(value);// => 1, 2, 3for(letkeyoftyped.keys())console.log(key);// => 0, 1, 2for(let[key,value]oftyped.entries()){console.log(key);// => 0, 1, 2console.log(value);// => 1, 2, 3}newInt32Array([1,2,3]).at(1);// => 2newInt32Array([1,2,3]).at(-1);// => 3buffer=Int8Array.of(1,2,3,4,5,6,7,8).buffer;console.log(buffer.byteLength);// => 8console.log(buffer.detached);// => falseconstnewBuffer=buffer.transfer(4);console.log(buffer.byteLength);// => 0console.log(buffer.detached);// => trueconsole.log(newBuffer.byteLength);// => 4console.log(newBuffer.detached);// => falseconsole.log([...newInt8Array(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.

ECMAScript: Reflect

Moduleses.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.

namespaceReflect{apply(target:Function,thisArgument: any,argumentsList:Array<mixed>): any;construct(target:Function,argumentsList:Array<mixed>,newTarget?:Function):Object;defineProperty(target:Object,propertyKey:PropertyKey,attributes:PropertyDescriptor): boolean;deleteProperty(target:Object,propertyKey:PropertyKey): boolean;get(target:Object,propertyKey:PropertyKey,receiver?: any): any;getOwnPropertyDescriptor(target:Object,propertyKey:PropertyKey):PropertyDescriptor|void;getPrototypeOf(target:Object):Object|null;has(target:Object,propertyKey:PropertyKey): boolean;isExtensible(target:Object): boolean;ownKeys(target:Object):Array<string|symbol>;preventExtensions(target:Object): boolean;set(target:Object,propertyKey:PropertyKey,V:any,receiver?: any): boolean;setPrototypeOf(target:Object,proto:Object|null): boolean;// required __proto__ - IE11+}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/reflectcore-js(-pure)/es|stable|actual|full/reflect/applycore-js(-pure)/es|stable|actual|full/reflect/constructcore-js(-pure)/es|stable|actual|full/reflect/define-propertycore-js(-pure)/es|stable|actual|full/reflect/delete-propertycore-js(-pure)/es|stable|actual|full/reflect/getcore-js(-pure)/es|stable|actual|full/reflect/get-own-property-descriptorcore-js(-pure)/es|stable|actual|full/reflect/get-prototype-ofcore-js(-pure)/es|stable|actual|full/reflect/hascore-js(-pure)/es|stable|actual|full/reflect/is-extensiblecore-js(-pure)/es|stable|actual|full/reflect/own-keyscore-js(-pure)/es|stable|actual|full/reflect/prevent-extensionscore-js(-pure)/es|stable|actual|full/reflect/setcore-js(-pure)/es|stable|actual|full/reflect/set-prototype-of

Examples:

letobject={a:1};Object.defineProperty(object,'b',{value:2});object[Symbol('c')]=3;Reflect.ownKeys(object);// => ['a', 'b', Symbol(c)]functionC(a,b){this.c=a+b;}letinstance=Reflect.construct(C,[20,22]);instance.c;// => 42

ECMAScript: JSON

SinceJSON object is missed only in very old engines like IE7-,core-js does not provide a fullJSON polyfill, however, fix already existing implementations by the current standard, for example,well-formedJSON.stringify.JSON is also fixed in other modules - for example,Symbol polyfill fixesJSON.stringify for correct work with symbols.

Modulees.json.to-string-tag andes.json.stringify.

namespaceJSON{stringify(value: any,replacer?:Array<string|number>|(this:any,key:string,value:any)=>any,space?:string|number): string|void;  @@toStringTag: 'JSON';}

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/json/stringifycore-js(-pure)/es|stable|actual|full/json/to-string-tag

Examples:

JSON.stringify({'𠮷':['\uDF06\uD834']});// => '{"𠮷":["\\udf06\\ud834"]}'

ECMAScript: globalThis

Modulees.global-this.

letglobalThis:GlobalThisValue;

CommonJS entry points:

core-js(-pure)/es|stable|actual|full/global-this

Examples:

globalThis.Array===Array;// => true

ECMAScript proposals

The TC39 process.

core-js/stage/3 entry point contains only stage 3 proposals,core-js/stage/2.7 - stage 2.7 and stage 3, etc.

Finished proposals

Finished (stage 4) proposals already marked incore-js as stable ECMAScript, they are available incore-js/stable andcore-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 likecore-js/proposals/proposal-name.

letglobalThis:GlobalThisValue;

CommonJS entry points:

core-js/proposals/global-this
classArray{at(index:int):any;}classString{at(index:int):string;}class%TypedArray%{at(index:int):number;}

CommonJS entry points:

core-js/proposals/relative-indexing-method
classArray{includes(searchElement:any,from?:number):boolean;}class%TypedArray%{includes(searchElement:any,from?:number):boolean;}

CommonJS entry points:

core-js/proposals/array-includes
classArray{flat(depthArg?:number=1):Array<mixed>;flatMap(mapFn:(value:any,index:number,target:any)=>any,thisArg:any):Array<mixed>;}

CommonJS entry points:

core-js/proposals/array-flat-map
classArray{findLast(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):any;findLastIndex(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):uint;}class%TypedArray%{findLast(callbackfn:(value:any,index:number,target:%TypedArray%)=>boolean,thisArg?:any):any;findLastIndex(callbackfn:(value:any,index:number,target:%TypedArray%)=>boolean,thisArg?:any):uint;}

CommonJS entry points:

core-js/proposals/array-find-from-last
classArray{toReversed():Array<mixed>;toSpliced(start?:number,deleteCount?:number, ...items:Array<mixed>):Array<mixed>;toSorted(comparefn?:(a:any,b:any)=>number):Array<mixed>;with(index:includes,value:any):Array<mixed>;}class%TypedArray%{toReversed():%TypedArray%;toSorted(comparefn?:(a:any,b:any)=>number):%TypedArray%;with(index:includes,value:any):%TypedArray%;}

CommonJS entry points:

core-js/proposals/change-array-by-copy-stage-4core-js(-pure)/es|stable|actual|full/array(/virtual)/to-reversedcore-js(-pure)/es|stable|actual|full/array(/virtual)/to-sortedcore-js(-pure)/es|stable|actual|full/array(/virtual)/to-splicedcore-js(-pure)/es|stable|actual|full/array(/virtual)/withcore-js/es|stable|actual|full/typed-array/to-reversedcore-js/es|stable|actual|full/typed-array/to-sortedcore-js/es|stable|actual|full/typed-array/with
classObject{staticgroupBy(items:Iterable,callbackfn:(value:any,index:number)=>key):{[key]:Array<mixed>};}classMap{staticgroupBy(items:Iterable,callbackfn:(value:any,index:number)=>key):Map<key,Array<mixed>>;}

CommonJS entry points:

core-js/proposals/array-grouping-v2
classArray{staticfromAsync(asyncItems:AsyncIterable|Iterable|ArrayLike,mapfn?:(value:any,index:number)=>any,thisArg?:any):Array;}

CommonJS entry points:

core-js/proposals/array-from-async-stage-2
classArrayBuffer{readonlyattributedetached:boolean;transfer(newLength?:number):ArrayBuffer;transferToFixedLength(newLength?:number):ArrayBuffer;}

CommonJS entry points:

core-js/proposals/array-buffer-transfer
classError{staticisError(value:any):boolean;}

CommonJS entry points:

core-js/proposals/is-error

Warning

We have no bulletproof way to polyfill thisError.isError / check if the object is an error, so it's an enough naive implementation.

Note

This is only built-ins for this Explicit Resource Management,using syntax support requirestranspiler support.

classSymbol{staticasyncDispose: @@asyncDispose;staticdispose: @@dispose;}classDisposableStack{constructor():DisposableStack;dispose():undefined;use(value:Disposable):value;adopt(value:object,onDispose:Function):value;defer(onDispose:Function):undefined;move():DisposableStack;  @@dispose():undefined;  @@toStringTag:'DisposableStack';}classAsyncDisposableStack{constructor():AsyncDisposableStack;disposeAsync():Promise<undefined>;use(value:AsyncDisposable|Disposable):value;adopt(value:object,onDispose:Function):value;defer(onDispose:Function):undefined;move():AsyncDisposableStack;  @@asyncDispose():Promise<undefined>;  @@toStringTag:'AsyncDisposableStack';}classSuppressedErrorextendsError{constructor(error:any,suppressed:any,message?:string):SuppressedError;error:any;suppressed:any;message:string;cause:any;}classIterator{  @@dispose():undefined;}classAsyncIterator{  @@asyncDispose():Promise<undefined>;}

CommonJS entry points:

core-js/proposals/explicit-resource-management
classDataView{getFloat16(offset:any,littleEndian?:boolean=false):float16setFloat16(offset:any,value:any,littleEndian?:boolean=false):void;}namespaceMath{fround(number: any): number;}

CommonJS entry points:

core-js/proposals/float16
classIterator{staticfrom(iterable:Iterable<any>|Iterator<any>):Iterator<any>;drop(limit:uint):Iterator<any>;every(callbackfn:(value:any,counter:uint)=>boolean):boolean;filter(callbackfn:(value:any,counter:uint)=>boolean):Iterator<any>;find(callbackfn:(value:any,counter:uint)=>boolean)):any;flatMap(callbackfn:(value:any,counter:uint)=>Iterable<any>|Iterator<any>):Iterator<any>;forEach(callbackfn:(value:any,counter:uint)=>void):void;map(callbackfn:(value:any,counter:uint)=>any):Iterator<any>;reduce(callbackfn:(memo:any,value:any,counter:uint)=>any,initialValue:any):any;some(callbackfn:(value:any,counter:uint)=>boolean):boolean;take(limit:uint):Iterator<any>;toArray():Array<any>;  @@toStringTag:'Iterator'}

CommonJS entry points:

core-js/proposals/iterator-helpers-stage-3-2
classObject{staticentries(object:Object):Array<[string,mixed]>;staticvalues(object:any):Array<mixed>;}

CommonJS entry points:

core-js/proposals/object-values-entries
classObject{staticfromEntries(iterable:Iterable<[key,value]>):Object;}

CommonJS entry points:

core-js/proposals/object-from-entries
classObject{staticgetOwnPropertyDescriptors(object:any):{[property:PropertyKey]:PropertyDescriptor};}

CommonJS entry points:

core-js/proposals/object-getownpropertydescriptors
classObject{statichasOwn(object:object,key:PropertyKey):boolean;}

CommonJS entry points:

core-js/proposals/accessible-object-hasownproperty
classString{padStart(length:number,fillStr?:string=' '):string;padEnd(length:number,fillStr?:string=' '):string;}

CommonJS entry points:

core-js/proposals/string-padding
classString{matchAll(regexp:RegExp):Iterator;}

CommonJS entry points:

core-js/proposals/string-match-all
classString{replaceAll(searchValue:string|RegExp,replaceString:string|(searchValue,index,this)=>string):string;}

CommonJS entry points:

core-js/proposals/string-replace-all-stage-4
classString{trimLeft():string;trimRight():string;trimStart():string;trimEnd():string;}

CommonJS entry points:

core-js/proposals/string-left-right-trim
// patched for support `RegExp` dotAll (`s`) flag:classRegExp{constructor(pattern:RegExp|string,flags?:string):RegExp;exec():Array<string|undefined>|null;readonlyattributedotAll:boolean;readonlyattributeflags:string;}

CommonJS entry points:

core-js/proposals/regexp-dotall-flag
// patched for support `RegExp` named capture groups:classRegExp{constructor(pattern:RegExp|string,flags?:string):RegExp;exec():Array<string|undefined>|null;  @@replace(string:string,replaceValue:Function|string):string;}

CommonJS entry points:

core-js/proposals/regexp-named-groups
classRegExp{staticescape(value:string):string}

CommonJS entry points:

core-js/proposals/regexp-escaping
classPromise{staticallSettled(iterable:Iterable):Promise;}

CommonJS entry points:

core-js/proposals/promise-all-settled
classAggregateError{constructor(errors:Iterable,message:string):AggregateError;errors:Array<any>;message:string;}classPromise{staticany(promises:Iterable):Promise<any>;}

CommonJS entry points:

core-js/proposals/promise-any
classPromise{finally(onFinally:Function):Promise;}

CommonJS entry points:

core-js/proposals/promise-finally
classPromise{statictry(callbackfn:Function, ...args?:Array<mixed>):Promise;}

CommonJS entry points:

core-js/proposals/promise-try
classPromise{staticwithResolvers():{promise:Promise,resolve:function,reject:function};}

CommonJS entry points:

core-js/proposals/promise-with-resolvers
classSymbol{staticasyncIterator: @@asyncIterator;}

CommonJS entry points:

core-js/proposals/async-iteration
classSymbol{readonlyattributedescription:string|void;}

CommonJS entry points:

core-js/proposals/symbol-description
namespaceJSON{stringify(target: any,replacer?:Function|Array,space?:string|number): string|void;}

CommonJS entry points:

core-js/proposals/well-formed-stringify
classString{isWellFormed():boolean;toWellFormed():string;}

CommonJS entry points:

core-js/proposals/well-formed-unicode-strings
classSet{difference(other:SetLike<mixed>):Set;intersection(other:SetLike<mixed>):Set;isDisjointFrom(other:SetLike<mixed>):boolean;isSubsetOf(other:SetLike<mixed>):boolean;isSupersetOf(other:SetLike<mixed>):boolean;symmetricDifference(other:SetLike<mixed>):Set;union(other:SetLike<mixed>):Set;}

CommonJS entry points:

core-js/proposals/set-methods-v2

Stage 3 proposals

CommonJS entry points:

core-js(-pure)/stage/3

Modulesesnext.json.is-raw-json,esnext.json.parse,esnext.json.raw-json.

namespaceJSON{isRawJSON(O:any): boolean;// patched for source supportparse(text:string,reviver?:(this: any,key:string,value: any,context:{source?:string})=>any): any;rawJSON(text: any):RawJSON;// patched for `JSON.rawJSON` supportstringify(value: any,replacer?:Array<string|number>|(this:any,key:string,value:any)=>any,space?:string|number): string|void;}

CommonJS entry points:

core-js/proposals/json-parse-with-sourcecore-js(-pure)/actual|full/json/is-raw-jsoncore-js(-pure)/actual|full/json/parsecore-js(-pure)/actual|full/json/raw-jsoncore-js(-pure)/actual|full/json/stringify

Examples:

functiondigitsToBigInt(key,val,{ source}){return/^\d+$/.test(source) ?BigInt(source) :val;}functionbigIntToRawJSON(key,val){returntypeofval==='bigint' ?JSON.rawJSON(String(val)) :val;}consttooBigForNumber=BigInt(Number.MAX_SAFE_INTEGER)+2n;JSON.parse(String(tooBigForNumber),digitsToBigInt)===tooBigForNumber;// trueconstwayTooBig=BigInt(`1${'0'.repeat(1000)}`);JSON.parse(String(wayTooBig),digitsToBigInt)===wayTooBig;// trueconstembedded=JSON.stringify({ tooBigForNumber},bigIntToRawJSON);embedded==='{"tooBigForNumber":9007199254740993}';// true

Modulesesnext.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.

classUint8Array{staticfromBase64(string:string,options?:{alphabet?:'base64'|'base64url',lastChunkHandling?:'loose'|'strict'|'stop-before-partial'}):Uint8Array;staticfromHex(string:string):Uint8Array;setFromBase64(string:string,options?:{alphabet?:'base64'|'base64url',lastChunkHandling?:'loose'|'strict'|'stop-before-partial'}):{read:uint,written:uint};setFromHex(string:string):{read:uint,written:uint};toBase64(options?:{alphabet?:'base64'|'base64url',omitPadding?:boolean}):string;toHex():string;}

CommonJS entry points:

core-js/proposals/array-buffer-base64core-js(-pure)/actual|full/typed-array/from-base64core-js(-pure)/actual|full/typed-array/from-hexcore-js(-pure)/actual|full/typed-array/set-from-base64core-js(-pure)/actual|full/typed-array/set-from-hexcore-js(-pure)/actual|full/typed-array/to-base64core-js(-pure)/actual|full/typed-array/to-hex

Example:

letarr=newUint8Array([72,101,108,108,111,32,87,111,114,108,100]);console.log(arr.toBase64());// => 'SGVsbG8gV29ybGQ='console.log(arr.toBase64({omitPadding:true}));// => 'SGVsbG8gV29ybGQ'console.log(arr.toHex());// => '48656c6c6f20576f726c64'console.log(Uint8Array.fromBase64('SGVsbG8gV29ybGQ='));// => Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])console.log(Uint8Array.fromHex('48656c6c6f20576f726c64'));// => Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100])

Moduleesnext.math.sum-precise

classMath{staticsumPrecise(items:Iterable<number>):Number;}

CommonJS entry points:

core-js/proposals/math-sumcore-js(-pure)/full|actual/math/sum-precise

Examples:

1e20+0.1+-1e20;// => 0Math.sumPrecise([1e20,0.1,-1e20]);// => 0.1

Modulesesnext.symbol.metadata andesnext.function.metadata.

classSymbol{staticmetadata: @@metadata;}classFunction{  @@metadata:null;}

CommonJS entry points:

core-js/proposals/decorator-metadata-v2core-js(-pure)/actual|full/symbol/metadatacore-js(-pure)/actual|full/function/metadata

Stage 2.7 proposals

CommonJS entry points:

core-js(-pure)/stage/2.7

Moduleesnext.iterator.concat

classIterator{concat(...items:Array<IterableObject>):Iterator<any>;}

CommonJS entry points:

core-js/proposals/iterator-sequencingcore-js(-pure)/full/iterator/concat

Example:

Iterator.concat([0,1].values(),[2,3],function*(){yield4;yield5;}()).toArray();// => [0, 1, 2, 3, 4, 5]

Modulesesnext.iterator.zip,esnext.iterator.zip-keyed

classIterator{zip<TextendsreadonlyIterable<unknown>[]>(iterables:T,options?:{mode?:'shortest'|'longest'|'strict';padding?:{[KinkeyofT]?:T[K]extendsIterable<inferU> ?U :never};}):IterableIterator<{[KinkeyofT]:T[K]extendsIterable<inferU> ?U :never}>;zipKeyed<KextendsPropertyKey,VextendsRecord<K,Iterable<unknown>>>(iterables:V,options?:{mode?:'shortest'|'longest'|'strict';padding?:{[PinkeyofV]?:V[P]extendsIterable<inferU> ?U :never};}):IterableIterator<{[PinkeyofV]:V[P]extendsIterable<inferU> ?U :never}>;}

CommonJS entry points:

core-js/proposals/joint-iterationcore-js(-pure)/full/iterator/zipcore-js(-pure)/full/iterator/zip-keyed

Example:

Iterator.zip([[0,1,2],[3,4,5],]).toArray();// => [[0, 3], [1, 4], [2, 5]]Iterator.zipKeyed({a:[0,1,2],b:[3,4,5,6],c:[7,8,9],},{mode:'longest',padding:{c:10},}).toArray();/*[  { a: 0,         b: 3, c: 7  },  { a: 1,         b: 4, c: 8  },  { a: 2,         b: 5, c: 9  },  { a: undefined, b: 6, c: 10 },]; */

Modulesesnext.map.get-or-insert,esnext.map.get-or-insert-computed,esnext.weak-map.get-or-insert andesnext.weak-map.get-or-insert-computed

classMap{getOrInsert(key:any,value:any):any;getOrInsertComputed(key:any,(key:any)=>value: any): any;}classWeakMap{getOrInsert(key:any,value:any):any;getOrInsertComputed(key:any,(key:any)=>value: any): any;}

CommonJS entry points:

core-js/proposals/map-upsert-v4core-js(-pure)/full/map/get-or-insertcore-js(-pure)/full/map/get-or-insert-computedcore-js(-pure)/full/weak-map/get-or-insertcore-js(-pure)/full/weak-map/get-or-insert-computed

Examples:

constmap=newMap([['a',1]]);map.getOrInsert('a',2);// => 1map.getOrInsert('b',3);// => 3map.getOrInsertComputed('a',key=>key);// => 1map.getOrInsertComputed('c',key=>key);// => 'c'console.log(map);// => Map { 'a': 1, 'b': 3, 'c': 'c' }

Stage 2 proposals

CommonJS entry points:

core-js(-pure)/stage/2

Modulesesnext.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

classIterator{toAsync():AsyncIterator<any>;}classAsyncIterator{staticfrom(iterable:AsyncIterable<any>|Iterable<any>|AsyncIterator<any>):AsyncIterator<any>;drop(limit:uint):AsyncIterator<any>;every(asynccallbackfn:(value:any,counter:uint)=>boolean):Promise<boolean>;filter(asynccallbackfn:(value:any,counter:uint)=>boolean):AsyncIterator<any>;find(asynccallbackfn:(value:any,counter:uint)=>boolean)):Promise<any>;flatMap(asynccallbackfn:(value:any,counter:uint)=>AsyncIterable<any>|Iterable<any>|AsyncIterator<any>):AsyncIterator<any>;forEach(asynccallbackfn:(value:any,counter:uint)=>void):Promise<void>;map(asynccallbackfn:(value:any,counter:uint)=>any):AsyncIterator<any>;reduce(asynccallbackfn:(memo:any,value:any,counter:uint)=>any,initialValue:any):Promise<any>;some(asynccallbackfn:(value:any,counter:uint)=>boolean):Promise<boolean>;take(limit:uint):AsyncIterator<any>;toArray():Promise<Array>;  @@toStringTag:'AsyncIterator'}

CommonJS entry points:

core-js/proposals/async-iterator-helperscore-js(-pure)/actual|full/async-iteratorcore-js(-pure)/actual|full/async-iterator/dropcore-js(-pure)/actual|full/async-iterator/everycore-js(-pure)/actual|full/async-iterator/filtercore-js(-pure)/actual|full/async-iterator/findcore-js(-pure)/actual|full/async-iterator/flat-mapcore-js(-pure)/actual|full/async-iterator/for-eachcore-js(-pure)/actual|full/async-iterator/fromcore-js(-pure)/actual|full/async-iterator/mapcore-js(-pure)/actual|full/async-iterator/reducecore-js(-pure)/actual|full/async-iterator/somecore-js(-pure)/actual|full/async-iterator/takecore-js(-pure)/actual|full/async-iterator/to-arraycore-js(-pure)/actual|full/iterator/to-async

Examples:

awaitAsyncIterator.from([1,2,3,4,5,6,7]).drop(1).take(5).filter(it=>it%2).map(it=>it**2).toArray();// => [9, 25]await[1,2,3].values().toAsync().map(asyncit=>it**2).toArray();// => [1, 4, 9]
Caveats:
  • For preventing prototypes pollution, in thepure version, new%AsyncIteratorPrototype% methods are not added to the real%AsyncIteratorPrototype%, they available only on wrappers - instead of[].values().toAsync().map(fn) useAsyncIterator.from([]).map(fn).
  • Now, we have access to the real%AsyncIteratorPrototype% only with usage async generators syntax. So, for compatibility of the library with old browsers, we should useFunction constructor. However, that breaks compatibility with CSP. So, if you wanna use the real%AsyncIteratorPrototype%, you should setUSE_FUNCTION_CONSTRUCTOR option in thecore-js/configurator totrue:
constconfigurator=require('core-js/configurator');configurator({USE_FUNCTION_CONSTRUCTOR:true});require('core-js/actual/async-iterator');(asyncfunction*(){/* empty */})()instanceofAsyncIterator;// => true
  • As an alternative, you could pass to thecore-js/configurator an object that will be considered as%AsyncIteratorPrototype%:
constconfigurator=require('core-js/configurator');const{ getPrototypeOf}=Object;configurator({AsyncIteratorPrototype:getPrototypeOf(getPrototypeOf(getPrototypeOf(asyncfunction*(){/* empty */}())))});require('core-js/actual/async-iterator');(asyncfunction*(){/* empty */})()instanceofAsyncIterator;// => true

Moduleesnext.iterator.range

classIterator{range(start:number,end:number,options:{step:number=1,inclusive:boolean=false}|step:number=1):NumericRangeIterator;range(start:bigint,end:bigint|Infinity|-Infinity,options:{step:bigint=1n,inclusive:boolean=false}|step:bigint=1n):NumericRangeIterator;}

CommonJS entry points:

core-js/proposals/number-rangecore-js(-pure)/full/iterator/range

Example:

for(constiofIterator.range(1,10)){console.log(i);// => 1, 2, 3, 4, 5, 6, 7, 8, 9}for(constiofIterator.range(1,10,{step:3,inclusive:true})){console.log(i);// => 1, 4, 7, 10}

Moduleesnext.array.is-template-object

classArray{staticisTemplateObject(value:any):boolean}

CommonJS entry points:

core-js/proposals/array-is-template-objectcore-js(-pure)/full/array/is-template-object

Example:

console.log(Array.isTemplateObject((it=>it)`qwe${123}asd`));// => true

Moduleesnext.number.clamp

classNumber{clamp(min:number,max:number):number;}

CommonJS entry points:

core-js/proposals/math-clamp-v2core-js(-pure)/full/number/clamp

Example:

5.0.clamp(0,10);// => 5-5.0.clamp(0,10);// => 015.0.clamp(0,10);// => 10

Moduleesnext.string.dedent

classString{staticdedent(templateOrTag:{raw:Array<string>}|function, ...substitutions:Array<string>):string|function;}

CommonJS entry points:

core-js/proposals/string-dedentcore-js(-pure)/full/string/dedent

Example:

constmessage=42;console.log(String.dedent`  print('${message}')`);// => print('42')String.dedent(console.log)`  print('${message}')`;// => ["print('", "')", raw: Array(2)], 42

Modulesesnext.symbol.is-registered-symbol,esnext.symbol.is-well-known-symbol.

classSymbol{staticisRegisteredSymbol(value:any):boolean;staticisWellKnownSymbol(value:any):boolean;}

CommonJS entry points:

core-js/proposals/symbol-predicates-v2core-js(-pure)/full/symbol/is-registered-symbolcore-js(-pure)/full/symbol/is-well-known-symbol

Example:

Symbol.isRegisteredSymbol(Symbol.for('key'));// => trueSymbol.isRegisteredSymbol(Symbol('key'));// => falseSymbol.isWellKnownSymbol(Symbol.iterator);// => trueSymbol.isWellKnownSymbol(Symbol('key'));// => false

Moduleesnext.symbol.custom-matcher.

classSymbol{staticcustomMatcher: @@customMatcher;}

CommonJS entry points:

core-js/proposals/pattern-extractorscore-js(-pure)/full/symbol/custom-matcher

Modulesesnext.iterator.chunks,esnext.iterator.slidingandesnext.iterator.windows

classIterator{chunks(chunkSize:number):Iterator<any>;sliding(windowSize:number):Iterator<any>;windows(windowSize:number):Iterator<any>;}

CommonJS entry points:

core-js/proposals/iterator-chunkingcore-js(-pure)/full/iterator/chunkscore-js(-pure)/full/iterator/slidingcore-js(-pure)/full/iterator/windows

Examples

constdigits=()=>[0,1,2,3,4,5,6,7,8,9].values();letchunksOf2=Array.from(digits().chunks(2));// [ [0, 1], [2, 3], [4, 5], [6, 7], [8, 9] ]letslidingOf2=Array.from(digits().sliding(2));// [ [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9] ]letwindowsOf2=Array.from(digits().windows(2));// [ [0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9] ]

Stage 1 proposals

CommonJS entry points:

core-js(-pure)/stage/1

Modulesesnext.observable andesnext.symbol.observable

classObservable{constructor(subscriber:Function):Observable;subscribe(observer:Function|{next?:Function,error?:Function,complete?:Function}):Subscription;  @@observable(): this;staticof(...items:Array<mixed>):Observable;staticfrom(x:Observable|Iterable):Observable;staticreadonlyattribute @@species: this;}classSymbol{staticobservable: @@observable;}

CommonJS entry points:

core-js/proposals/observablecore-js(-pure)/full/observablecore-js(-pure)/full/symbol/observable

Example:

newObservable(observer=>{observer.next('hello');observer.next('world');observer.complete();}).subscribe({next(it){console.log(it);},complete(){console.log('!');},});

Modulesesnext.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

Modulesesnext.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

classSet{staticof(...args:Array<mixed>):Set;staticfrom(iterable:Iterable<mixed>,mapFn?:(value:any,index:number)=>any,thisArg?:any):Set;addAll(...args:Array<mixed>): this;deleteAll(...args:Array<mixed>):boolean;every(callbackfn:(value:any,key:any,target:any)=>boolean,thisArg?:any):boolean;filter(callbackfn:(value:any,key:any,target:any)=>boolean,thisArg?:any):Set;find(callbackfn:(value:any,key:any,target:any)=>boolean),thisArg?:any):any;join(separator:string=','):string;map(callbackfn:(value:any,key:any,target:any)=>any,thisArg?:any):Set;reduce(callbackfn:(memo:any,value:any,key:any,target:any)=>any,initialValue?:any):any;some(callbackfn:(value:any,key:any,target:any)=>boolean,thisArg?:any):boolean;}classMap{staticof(...args:Array<[key,value]>):Map;staticfrom(iterable:Iterable<mixed>,mapFn?:(value:any,index:number)=>[key:any,value:any],thisArg?:any):Map;statickeyBy(iterable:Iterable<mixed>,callbackfn?:(value:any)=>any):Map;deleteAll(...args:Array<mixed>):boolean;every(callbackfn:(value:any,key:any,target:any)=>boolean,thisArg?:any):boolean;filter(callbackfn:(value:any,key:any,target:any)=>boolean,thisArg?:any):Map;find(callbackfn:(value:any,key:any,target:any)=>boolean),thisArg?:any):any;findKey(callbackfn:(value:any,key:any,target:any)=>boolean),thisArg?:any):any;includes(searchElement:any):boolean;keyOf(searchElement:any):any;mapKeys(mapFn:(value:any,index:number,target:any)=>any,thisArg?:any):Map;mapValues(mapFn:(value:any,index:number,target:any)=>any,thisArg?:any):Map;merge(...iterables:Array<Iterable>): this;reduce(callbackfn:(memo:any,value:any,key:any,target:any)=>any,initialValue?:any):any;some(callbackfn:(value:any,key:any,target:any)=>boolean,thisArg?:any):boolean;update(key:any,callbackfn:(value:any,key:any,target:any)=>any,thunk?:(key:any,target:any)=>any): this;}classWeakSet{staticof(...args:Array<mixed>):WeakSet;staticfrom(iterable:Iterable<mixed>,mapFn?:(value:any,index:number)=>Object,thisArg?:any):WeakSet;addAll(...args:Array<mixed>): this;deleteAll(...args:Array<mixed>):boolean;}classWeakMap{staticof(...args:Array<[key,value]>):WeakMap;staticfrom(iterable:Iterable<mixed>,mapFn?:(value:any,index:number)=>[key:Object,value:any],thisArg?:any):WeakMap;deleteAll(...args:Array<mixed>):boolean;}

CommonJS entry points:

core-js/proposals/collection-methodscore-js/proposals/collection-of-fromcore-js(-pure)/full/set/add-allcore-js(-pure)/full/set/delete-allcore-js(-pure)/full/set/everycore-js(-pure)/full/set/filtercore-js(-pure)/full/set/findcore-js(-pure)/full/set/fromcore-js(-pure)/full/set/joincore-js(-pure)/full/set/mapcore-js(-pure)/full/set/ofcore-js(-pure)/full/set/reducecore-js(-pure)/full/set/somecore-js(-pure)/full/map/delete-allcore-js(-pure)/full/map/everycore-js(-pure)/full/map/filtercore-js(-pure)/full/map/findcore-js(-pure)/full/map/find-keycore-js(-pure)/full/map/fromcore-js(-pure)/full/map/includescore-js(-pure)/full/map/key-bycore-js(-pure)/full/map/key-ofcore-js(-pure)/full/map/map-keyscore-js(-pure)/full/map/map-valuescore-js(-pure)/full/map/mergecore-js(-pure)/full/map/ofcore-js(-pure)/full/map/reducecore-js(-pure)/full/map/somecore-js(-pure)/full/map/updatecore-js(-pure)/full/weak-set/add-allcore-js(-pure)/full/weak-set/delete-allcore-js(-pure)/full/weak-set/ofcore-js(-pure)/full/weak-set/fromcore-js(-pure)/full/weak-map/delete-allcore-js(-pure)/full/weak-map/ofcore-js(-pure)/full/weak-map/from

.of /.fromexamples:

Set.of(1,2,3,2,1);// => Set {1, 2, 3}Map.from([[1,2],[3,4]],([key,value])=>[key**2,value**2]);// => Map { 1: 4, 9: 16 }

Modulesesnext.composite-key andesnext.composite-symbol

functioncompositeKey(...args:Array<mixed>):object;functioncompositeSymbol(...args:Array<mixed>):symbol;

CommonJS entry points:

core-js/proposals/keys-compositioncore-js(-pure)/full/composite-keycore-js(-pure)/full/composite-symbol

Examples:

// returns a symbolconstsymbol=compositeSymbol({});console.log(typeofsymbol);// => 'symbol'// works the same, but returns a plain frozen object without a prototypeconstkey=compositeKey({});console.log(typeofkey);// => 'object'console.log({}.toString.call(key));// => '[object Object]'console.log(Object.getPrototypeOf(key));// => nullconsole.log(Object.isFrozen(key));// => trueconsta=['a'];constb=['b'];constc=['c'];/* eslint-disable no-self-compare -- example */console.log(compositeSymbol(a)===compositeSymbol(a));// => trueconsole.log(compositeSymbol(a)!==compositeSymbol(['a']));// => trueconsole.log(compositeSymbol(a,1)===compositeSymbol(a,1));// => trueconsole.log(compositeSymbol(a,b)!==compositeSymbol(b,a));// => trueconsole.log(compositeSymbol(a,b,c)===compositeSymbol(a,b,c));// => trueconsole.log(compositeSymbol(1,a)===compositeSymbol(1,a));// => trueconsole.log(compositeSymbol(1,a,2,b)===compositeSymbol(1,a,2,b));// => trueconsole.log(compositeSymbol(a,a)===compositeSymbol(a,a));// => true

Modulesesnext.array.filter-reject andesnext.typed-array.filter-reject.

classArray{filterReject(callbackfn:(value:any,index:number,target:any)=>boolean,thisArg?:any):Array<mixed>;}class%TypedArray%{filterReject(callbackfn:(value:number,index:number,target:%TypedArray%)=>boolean,thisArg?:any):%TypedArray%;}

CommonJS entry points:

core-js/proposals/array-filtering-stage-1core-js(-pure)/full/array(/virtual)/filter-rejectcore-js/full/typed-array/filter-reject

Examples:

[1,2,3,4,5].filterReject(it=>it%2);// => [2, 4]

Modulesesnext.array.unique-by andesnext.typed-array.unique-by

classArray{uniqueBy(resolver?:(item:any)=>any):Array<mixed>;}class%TypedArray%{uniqueBy(resolver?:(item:any)=>any):%TypedArray%;;}

CommonJS entry points:

core-js/proposals/array-uniquecore-js(-pure)/full/array(/virtual)/unique-bycore-js/full/typed-array/unique-by

Examples:

[1,2,3,2,1].uniqueBy();// [1, 2, 3][{id:1,uid:10000},{id:2,uid:10000},{id:3,uid:10001},].uniqueBy(it=>it.uid);// => [{ id: 1, uid: 10000 }, { id: 3, uid: 10001 }]

Modulesesnext.data-view.get-uint8-clamped andesnext.data-view.set-uint8-clamped

classDataView{getUint8Clamped(offset:any):uint8setUint8Clamped(offset:any,value:any):void;}

CommonJS entry points:

core-js/proposals/data-view-get-set-uint8-clampedcore-js/full/dataview/get-uint8-clampedcore-js/full/dataview/set-uint8-clamped

Examples:

constview=newDataView(newArrayBuffer(1));view.setUint8Clamped(0,100500);console.log(view.getUint8Clamped(0));// => 255

Moduleesnext.number.from-string

classNumber{fromString(string:string,radix:number):number;}

CommonJS entry points:

core-js/proposals/number-from-stringcore-js(-pure)/full/number/from-string

Moduleesnext.string.cooked

classString{staticcooked(template:Array<string>, ...substitutions:Array<string>):string;}

CommonJS entry points:

core-js/proposals/string-cookedcore-js(-pure)/full/string/cooked

Example:

functionsafePath(strings, ...subs){returnString.cooked(strings, ...subs.map(sub=>encodeURIComponent(sub)));}letid='spottie?';safePath`/cats/${id}`;// => /cats/spottie%3F

Moduleesnext.string.code-points

classString{codePoints():Iterator<{codePoint,position}>;}

CommonJS entry points:

core-js/proposals/string-code-pointscore-js(-pure)/full/string/code-points

Example:

for(let{ codePoint, position}of'qwe'.codePoints()){console.log(codePoint);// => 113, 119, 101console.log(position);// => 0, 1, 2}

Moduleesnext.symbol.custom-matcher.

classSymbol{staticcustomMatcher: @@customMatcher;}

CommonJS entry points:

core-js/proposals/pattern-matching-v2core-js(-pure)/full/symbol/custom-matcher

Stage 0 proposals

CommonJS entry points:

core-js(-pure)/stage/0

Moduleesnext.function.demethodize

classFunction{demethodize():Function;}

CommonJS entry points:

core-js/proposals/function-demethodizecore-js(-pure)/full/function/demethodizecore-js(-pure)/full/function/virtual/demethodize

Examples:

constslice=Array.prototype.slice.demethodize();slice([1,2,3],1);// => [2, 3]

Modulesesnext.function.is-callable,esnext.function.is-constructor

classFunction{staticisCallable(value:any):boolean;staticisConstructor(value:any):boolean;}

CommonJS entry points:

core-js/proposals/function-is-callable-is-constructorcore-js(-pure)/full/function/is-callablecore-js(-pure)/full/function/is-constructor

Examples:

/* eslint-disable prefer-arrow-callback -- example */Function.isCallable(null);// => falseFunction.isCallable({});// => falseFunction.isCallable(function(){/* empty */});// => trueFunction.isCallable(()=>{/* empty */});// => trueFunction.isCallable(class{/* empty */});// => falseFunction.isConstructor(null);// => falseFunction.isConstructor({});// => falseFunction.isConstructor(function(){/* empty */});// => trueFunction.isConstructor(()=>{/* empty */});// => falseFunction.isConstructor(class{/* empty */});// => true

Pre-stage 0 proposals

CommonJS entry points:

core-js(-pure)/stage/pre

Modulesesnext.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 andesnext.reflect.metadata.

namespaceReflect{defineMetadata(metadataKey: any,metadataValue: any,target:Object,propertyKey?:PropertyKey):void;getMetadata(metadataKey: any,target:Object,propertyKey?:PropertyKey): any;getOwnMetadata(metadataKey: any,target:Object,propertyKey?:PropertyKey): any;hasMetadata(metadataKey: any,target:Object,propertyKey?:PropertyKey): boolean;hasOwnMetadata(metadataKey: any,target:Object,propertyKey?:PropertyKey): boolean;deleteMetadata(metadataKey: any,target:Object,propertyKey?:PropertyKey): boolean;getMetadataKeys(target:Object,propertyKey?:PropertyKey):Array<mixed>;getOwnMetadataKeys(target:Object,propertyKey?:PropertyKey):Array<mixed>;metadata(metadataKey: any,metadataValue: any):decorator(target:Object,targetKey?:PropertyKey)=>void;}

CommonJS entry points:

core-js/proposals/reflect-metadatacore-js(-pure)/full/reflect/define-metadatacore-js(-pure)/full/reflect/delete-metadatacore-js(-pure)/full/reflect/get-metadatacore-js(-pure)/full/reflect/get-metadata-keyscore-js(-pure)/full/reflect/get-own-metadatacore-js(-pure)/full/reflect/get-own-metadata-keyscore-js(-pure)/full/reflect/has-metadatacore-js(-pure)/full/reflect/has-own-metadatacore-js(-pure)/full/reflect/metadata

Examples:

letobject={};Reflect.defineMetadata('foo','bar',object);Reflect.ownKeys(object);// => []Reflect.getOwnMetadataKeys(object);// => ['foo']Reflect.getOwnMetadata('foo',object);// => 'bar'

Web standards

self

Spec, moduleweb.self

getterself:GlobalThisValue;

CommonJS entry points:

core-js(-pure)/stable|actual|full/self

Examples:

// eslint-disable-next-line no-restricted-globals -- exampleself.Array===Array;// => true

structuredClone

Spec, moduleweb.structured-clone

functionstructuredClone(value:Serializable,{transfer?:Sequence<Transferable>}):any;

CommonJS entry points:

core-js(-pure)/stable|actual|full/structured-clone

Examples:

conststructured=[{a:42}];constsclone=structuredClone(structured);console.log(sclone);// => [{ a: 42 }]console.log(structured!==sclone);// => trueconsole.log(structured[0]!==sclone[0]);// => trueconstcircular={};circular.circular=circular;constcclone=structuredClone(circular);console.log(cclone.circular===cclone);// => truestructuredClone(42);// => 42structuredClone({x:42});// => { x: 42 }structuredClone([1,2,3]);// => [1, 2, 3]structuredClone(newSet([1,2,3]));// => Set{ 1, 2, 3 }structuredClone(newMap([['a',1],['b',2]]));// => Map{ a: 1, b: 2 }structuredClone(newInt8Array([1,2,3]));// => new Int8Array([1, 2, 3])structuredClone(newAggregateError([1,2,3],'message'));// => new AggregateError([1, 2, 3], 'message'))structuredClone(newTypeError('message',{cause:42}));// => new TypeError('message', { cause: 42 })structuredClone(newDOMException('message','DataCloneError'));// => new DOMException('message', 'DataCloneError')structuredClone(document.getElementById('myfileinput'));// => new FileListstructuredClone(newDOMPoint(1,2,3,4));// => new DOMPoint(1, 2, 3, 4)structuredClone(newBlob(['test']));// => new Blob(['test'])structuredClone(newImageData(8,8));// => new ImageData(8, 8)// etc.structuredClone(newWeakMap());// => 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 cloneImageBitmap in Safari 14.0- or Firefox 83-, so it's recommended to look to thepolyfill source if you wanna clone something specific.

Base64 utility methods

Specification,MDN. Modulesweb.atob,web.btoa.

functionatob(data:string):string;functionbtoa(data:string):string;

CommonJS entry points:

core-js(-pure)/stable|actual|full/atobcore-js(-pure)/stable|actual|full/btoa

Examples:

btoa('hi, core-js');// => 'aGksIGNvcmUtanM='atob('aGksIGNvcmUtanM=');// => 'hi, core-js'

setTimeout andsetInterval

Moduleweb.timers. Additional arguments fix for IE9-.

functionsetTimeout(callback:any,time:any, ...args:Array<mixed>):number;functionsetInterval(callback:any,time:any, ...args:Array<mixed>):number;

CommonJS entry points:

core-js(-pure)/stable|actual|full/set-timeoutcore-js(-pure)/stable|actual|full/set-interval
// Before:setTimeout(log.bind(null,42),1000);// After:setTimeout(log,1000,42);

setImmediate

Moduleweb.immediate.setImmediate polyfill.

functionsetImmediate(callback:any, ...args:Array<mixed>):number;functionclearImmediate(id:number):void;

CommonJS entry points:

core-js(-pure)/stable|actual|full/set-immediatecore-js(-pure)/stable|actual|full/clear-immediate

Examples:

setImmediate((arg1,arg2)=>{console.log(arg1,arg2);// => Message will be displayed with minimum delay},'Message will be displayed','with minimum delay');clearImmediate(setImmediate(()=>{console.log('Message will not be displayed');}));

queueMicrotask

Spec, moduleweb.queue-microtask

functionqueueMicrotask(fn:Function):void;

CommonJS entry points:

core-js(-pure)/stable|actual|full/queue-microtask

Examples:

queueMicrotask(()=>console.log('called as microtask'));

URL andURLSearchParams

URL standard implementation. Modulesweb.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.

classURL{constructor(url:string,base?:string);attributehref:string;readonlyattributeorigin:string;attributeprotocol:string;attributeusername:string;attributepassword:string;attributehost:string;attributehostname:string;attributeport:string;attributepathname:string;attributesearch:string;readonlyattributesearchParams:URLSearchParams;attributehash:string;toJSON():string;toString():string;staticcanParse(url:string,base?:string):boolean;staticparse(url:string,base?:string):URL|null;}classURLSearchParams{constructor(params?:string|Iterable<[key,value]>|Object);append(name:string,value:string):void;delete(name:string,value?:string):void;get(name:string):string|void;getAll(name:string):Array<string>;has(name:string,value?:string):boolean;set(name:string,value:string):void;sort():void;toString():string;forEach(callbackfn:(value:any,index:number,target:any)=>void,thisArg:any):void;entries():Iterator<[key,value]>;keys():Iterator<key>;values():Iterator<value>;  @@iterator():Iterator<[key,value]>;readonlyattributesize:number;}

CommonJS entry points:

core-js/proposals/urlcore-js(-pure)/stable|actual|full/urlcore-js(-pure)/stable|actual|full/url/can-parsecore-js/stable|actual|full/url/to-jsoncore-js(-pure)/stable|actual|full/url-search-params

Examples:

URL.canParse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment');// => trueURL.canParse('https');// => falseURL.parse('https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment');// => urlURL.parse('https');// => nullconsturl=newURL('https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment');console.log(url.href);// => 'https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment'console.log(url.origin);// => 'https://example.com:8080'console.log(url.protocol);// => 'https:'console.log(url.username);// => 'login'console.log(url.password);// => 'password'console.log(url.host);// => 'example.com:8080'console.log(url.hostname);// => 'example.com'console.log(url.port);// => '8080'console.log(url.pathname);// => '/foo/bar'console.log(url.search);// => '?a=1&b=2&a=3'console.log(url.hash);// => '#fragment'console.log(url.toJSON());// => 'https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment'console.log(url.toString());// => 'https://login:password@example.com:8080/foo/bar?a=1&b=2&a=3#fragment'for(let[key,value]ofurl.searchParams){console.log(key);// => 'a', 'b', 'a'console.log(value);// => '1', '2', '3'}url.pathname='';url.searchParams.append('c',4);console.log(url.search);// => '?a=1&b=2&a=3&c=4'console.log(url.href);// => 'https://login:password@example.com:8080/?a=1&b=2&a=3&c=4#fragment'constparams=newURLSearchParams('?a=1&b=2&a=3');params.append('c',4);params.append('a',2);params.delete('a',1);params.sort();console.log(params.size);// => 4for(let[key,value]ofparams){console.log(key);// => 'a', 'a', 'b', 'c'console.log(value);// => '3', '2', '2', '4'}console.log(params.has('a'));// => trueconsole.log(params.has('a',3));// => trueconsole.log(params.has('a',4));// => falseconsole.log(params.toString());// => 'a=3&a=2&b=2&c=4'

Warning

  • IE8 does not support setters, so they do not work onURL 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 polyfillby your requirements.
DOMException:

The specification. Modulesweb.dom-exception.constructor,web.dom-exception.stack,web.dom-exception.to-string-tag.

classDOMException{constructor(message:string,name?:string);readonlyattributename:string;readonlyattributemessage:string;readonlyattributecode:string;attributestack:string;// in engines that should have it  @@toStringTag:'DOMException';}

CommonJS entry points:

core-js(-pure)/stable|actual|full/dom-exceptioncore-js(-pure)/stable|actual|full/dom-exception/constructorcore-js/stable|actual|full/dom-exception/to-string-tag

Examples:

constexception=newDOMException('error','DataCloneError');console.log(exception.name);// => 'DataCloneError'console.log(exception.message);// => 'error'console.log(exception.code);// => 25console.log(typeofexception.stack);// => 'string'console.log(exceptioninstanceofDOMException);// => trueconsole.log(exceptioninstanceofError);// => trueconsole.log(exception.toString());// => 'DataCloneError: error'console.log(Object.prototype.toString.call(exception));// => '[object DOMException]'

Iterable DOM collections

Some DOM collections should haveiterable interface or should beinherited fromArray. That means they should haveforEach,keys,values,entries and@@iterator methods for iteration. So add them. Modulesweb.dom-collections.iterator andweb.dom-collections.for-each.

class[CSSRuleList,CSSStyleDeclaration,CSSValueList,ClientRectList,DOMRectList,DOMStringList,DataTransferItemList,FileList,HTMLAllCollection,HTMLCollection,HTMLFormElement,HTMLSelectElement,MediaList,MimeTypeArray,NamedNodeMap,PaintRequestList,Plugin,PluginArray,SVGLengthList,SVGNumberList,SVGPathSegList,SVGPointList,SVGStringList,SVGTransformList,SourceBufferList,StyleSheetList,TextTrackCueList,TextTrackList,TouchList,]{  @@iterator():Iterator<value>;}class[DOMTokenList,NodeList]{forEach(callbackfn:(value: any,index:number,target: any)=>void,thisArg: any):void;entries():Iterator<[key,value]>;keys():Iterator<key>;values():Iterator<value>;  @@iterator():Iterator<value>;}

CommonJS entry points:

core-js(-pure)/stable|actual|full/dom-collections/iteratorcore-js/stable|actual|full/dom-collections/for-each

Examples:

for(let{ id}ofdocument.querySelectorAll('*')){if(id)console.log(id);}for(let[index,{ id}]ofdocument.querySelectorAll('*').entries()){if(id)console.log(index,id);}document.querySelectorAll('*').forEach(it=>console.log(it.id));

Iteration helpers

Helpers for checking iterability / get iterator in thepure version or, for example, forarguments object:

functionisIterable(value:any):boolean;functiongetIterator(value:any):Object;functiongetIteratorMethod(value:any):Function|void;

CommonJS entry points:

core-js-pure/es|stable|actual|full/is-iterablecore-js-pure/es|stable|actual|full/get-iteratorcore-js-pure/es|stable|actual|full/get-iterator-method

Examples:

importisIterablefrom'core-js-pure/actual/is-iterable';importgetIteratorfrom'core-js-pure/actual/get-iterator';importgetIteratorMethodfrom'core-js-pure/actual/get-iterator-method';letlist=(function(){// eslint-disable-next-line prefer-rest-params -- examplereturnarguments;})(1,2,3);console.log(isIterable(list));// true;letiterator=getIterator(list);console.log(iterator.next().value);// 1console.log(iterator.next().value);// 2console.log(iterator.next().value);// 3console.log(iterator.next().value);// undefinedgetIterator({});// TypeError: [object Object] is not iterable!letmethod=getIteratorMethod(list);console.log(typeofmethod);// 'function'iterator=method.call(list);console.log(iterator.next().value);// 1console.log(iterator.next().value);// 2console.log(iterator.next().value);// 3console.log(iterator.next().value);// undefinedconsole.log(getIteratorMethod({}));// undefined

Missing polyfills

  • ESBigInt can't be polyfilled since it requires changes in the behavior of operators, you can find more infohere. You could try to useJSBI.
  • ESProxy can't be polyfilled, you can try to useproxy-polyfill which provides a very small subset of features.
  • ESString#normalize is not a very useful feature, but this polyfill will be very large. If you need it, you can useunorm.
  • ECMA-402Intl is missed because of the size. You can usethose 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 incore-js. Looking at a large number of requests itmight be added in the future. Now you can use, for example,this polyfill.

[8]ページ先頭

©2009-2025 Movatter.jp