I highly recommend reading this: So, what's next?
Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2024: promises, symbols, collections, iterators, typed arrays, many other features, ECMAScript proposals, some cross-platform WHATWG / W3C features and proposals like
URL
. You can load only required features or use it without global namespace pollution.
If you are looking for documentation for obsolete core-js@2
, please, check this branch.
core-js@3, babel and a look into the future
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 in core-js
: Open Collective, Patreon, Boosty, Bitcoin ( bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz ), Alipay.
import 'core-js/actual';
Promise.resolve(42).then(it => console.log(it)); // => 42
Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5]
[1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2]
(function * (i) { while (true) yield i++; })(1)
.drop(1).take(5)
.filter(it => it % 2)
.map(it => it ** 2)
.toArray(); // => [9, 25]
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
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)); // => 42
Array.from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5]
[1, 2].flatMap(it => [it, it]); // => [1, 1, 2, 2]
(function * (i) { while (true) yield i++; })(1)
.drop(1).take(5)
.filter(it => it % 2)
.map(it => it ** 2)
.toArray(); // => [9, 25]
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
Or use it without global namespace pollution:
import Promise from 'core-js-pure/actual/promise';
import Set from 'core-js-pure/actual/set';
import Iterator from 'core-js-pure/actual/iterator';
import from from 'core-js-pure/actual/array/from';
import flatMap from 'core-js-pure/actual/array/flat-map';
import structuredClone from 'core-js-pure/actual/structured-clone';
Promise.resolve(42).then(it => console.log(it)); // => 42
from(new Set([1, 2, 3]).union(new Set([3, 4, 5]))); // => [1, 2, 3, 4, 5]
flatMap([1, 2], it => [it, it]); // => [1, 1, 2, 2]
Iterator.from(function * (i) { while (true) yield i++; }(1))
.drop(1).take(5)
.filter(it => it % 2)
.map(it => it ** 2)
.toArray(); // => [9, 25]
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])
Index
- Usage
- Supported engines and compatibility data
- Features
- ECMAScript
- ECMAScript: Object
- ECMAScript: Function
- ECMAScript: Error
- ECMAScript: Array
- ECMAScript: String and RegExp
- ECMAScript: Number
- ECMAScript: Math
- ECMAScript: Date
- ECMAScript: Promise
- ECMAScript: Symbol
- ECMAScript: Collections
- ECMAScript: Typed Arrays
- ECMAScript: Reflect
- ECMAScript: JSON
- ECMAScript: globalThis
- ECMAScript proposals
- Finished proposals
globalThis
- Relative indexing method
Array.prototype.includes
Array.prototype.flat
/Array.prototype.flatMap
Array
find from last- Change
Array
by copy Array
groupingArrayBuffer.prototype.transfer
and friendsObject.values
/Object.entries
Object.fromEntries
Object.getOwnPropertyDescriptors
- Accessible
Object.prototype.hasOwnProperty
String
paddingString.prototype.matchAll
String.prototype.replaceAll
String.prototype.trimStart
/String.prototype.trimEnd
RegExp
s
(dotAll
) flagRegExp
named capture groupsPromise.allSettled
Promise.any
Promise.prototype.finally
Promise.withResolvers
Symbol.asyncIterator
for asynchronous iterationSymbol.prototype.description
- Well-formed
JSON.stringify
- Well-formed unicode strings
- New
Set
methods
- Stage 3 proposals
- Stage 2.7 proposals
- Stage 2 proposals
- Stage 1 proposals
Observable
- New collections methods
.of
and.from
methods on collection constructorscompositeKey
andcompositeSymbol
Array
filteringArray
deduplicationDataView
get / setUint8Clamped
methodsNumber.fromString
String.cooked
String.prototype.codePoints
Symbol.customMatcher
for pattern matchingSymbol.customMatcher
for extractors
- Stage 0 proposals
- Pre-stage 0 proposals
- Finished proposals
- Web standards
- Iteration helpers
- ECMAScript
- Missing polyfills
- Contributing
- Security policy
- Changelog
Usage⬆
Installation:⬆
// global version
npm install --save core-js@3.38.0
// version without global namespace pollution
npm install --save core-js-pure@3.38.0
// bundled global version
npm install --save core-js-bundle@3.38.0
Or you can use core-js
from CDN.
postinstall
message⬆
The core-js
project needs your help, so the package shows a message about it after installation. If it causes problems for you, you can disable it:
ADBLOCK=true npm install
// or
DISABLE_OPENCOLLECTIVE=true npm install
// or
npm install --loglevel silent
CommonJS API⬆
You can import only-required-for-you polyfills, like in the examples at the top of README.md
. Available CommonJS entry points for all polyfilled methods / constructors and namespaces. Just some examples:
// 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