Standard Library
Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2025: 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.
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.try(() => 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]
Iterator.concat([1, 2], function * (i) { while (true) yield i++; }(3))
.drop(1).take(5)
.filter(it => it % 2)
.map(it => it ** 2)
.toArray(); // => [9, 25]
structuredClone(new Set([1, 2, 3])); // => new Set([1, 2, 3])You can load only required features:
…Or use it without global namespace pollution:
…globalThisArray.prototype.includesArray.prototype.flat / Array.prototype.flatMapArray find from lastArray by copyArray groupingArray.fromAsyncArrayBuffer.prototype.transfer and friendsUint8Array to / from base64 and hexError.isErrorFloat16 methodsIterator helpersIterator sequencingObject.values / Object.entriesObject.fromEntriesObject.getOwnPropertyDescriptorsObject.prototype.hasOwnPropertyString paddingString.prototype.matchAllString.prototype.replaceAllString.prototype.trimStart / String.prototype.trimEndRegExp s (dotAll) flagRegExp named capture groupsRegExp escapingPromise.allSettledPromise.anyPromise.prototype.finallyPromise.tryPromise.withResolversSymbol.asyncIterator for asynchronous iterationSymbol.prototype.descriptionJSON.parse source text accessJSON.stringifySet methodsMap upsertMath.sumPrecise// global version
npm install --save [email protected]
// version without global namespace pollution
npm install --save [email protected]
// bundled global version
npm install --save [email protected]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 silentYou 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:
…[!TIP] The usage of the
/actual/namespace is recommended since it includes all actual JavaScript features and does not include unstable early-stage proposals that are available mainly for experiments.
[!WARNING]
- The
modulespath is an internal API, does not inject all required dependencies and can be changed in minor or patch releases. Use it only for a custom build and/or if you know what are you doing.- If you use
core-jswith the extension of native objects, recommended to load allcore-jsmodules at the top of the entry point of your application, otherwise, you can have conflicts.
- For example, Google Maps use their own
Symbol.iterator, conflicting withArray.from,URLSearchParamsand / or something else fromcore-js, see related issues.- Such conflicts are also resolvable by discovering and manually adding each conflicting entry from
core-js.core-jsis extremely modular and uses a lot of very tiny modules, because of that for usage in browsers bundle upcore-jsinstead of a usage loader for each file, otherwise, you will have hundreds of requests.
In the pure version, we can't pollute prototypes of native constructors. Because of that, prototype methods transformed into static methods like in examples above. But with transpi
邀请 core-js 加入 GithubStarMate,让更多人发现你的作品
So, what's next?
npm warn allow-scripts: postinstall message triggers this warning on every npm install
Support ReadableStream async iteration
Guidance on using core-js with modern toolchains (Vite 8 + OXC, no Babel/SWC)
Temporal implementation in core-js
`URLPattern`
Reuse native methods in array internal modules when possible
Reduce minimalistic bundles size
requestAnimationFrame polyfill