What is core-js?
The core-js npm package is a modular standard library for JavaScript, which includes polyfills for ECMAScript features. It provides reliable polyfills to ensure that code behaves consistently across different environments, including older browsers.
What are core-js's main functionalities?
Polyfilling ECMAScript features
This feature allows developers to use the latest ECMAScript features while ensuring backward compatibility with older environments that do not support these features natively.
require('core-js/stable');
// Now you can use ES6 features like Promise in environments that do not support them natively.
Polyfilling Web Standards
Core-js can also polyfill web standards, allowing developers to use modern web APIs in environments that have not implemented them.
require('core-js/web');
// This includes polyfills for web standards like DOM collections (e.g., NodeList), timers, and more.
Polyfilling Proposals
Developers can experiment with proposed ECMAScript features before they are finalized and adopted into the standard, ensuring forward compatibility.
require('core-js/proposals');
// This will include polyfills for ECMAScript proposals that are not yet part of the standard.
Other packages similar to core-js
babel-polyfill
Babel-polyfill is a package that provides polyfills necessary for a full ES2015+ environment. It is similar to core-js but is more tightly coupled with Babel's transpilation process.
es6-shim
The es6-shim package provides polyfills for ECMAScript 6 (aka ECMAScript 2015) features. It is similar to core-js but focuses specifically on ES6 features and does not cover proposals or web standards.
polyfill-service
The polyfill-service by Financial Times is an online service that provides polyfills based on the user's browser. It is different from core-js in that it is a service rather than a package you include in your project, but it serves a similar purpose in polyfilling features.
Core.js
Alternative standard library for javascript. Includes polyfills for ECMAScript 5, ECMAScript 6, setImmediate, promises, static array methods, extended object api, console cap and other sugar.
Install
npm i core-js
Usage
Browser:
<script src='core.min.js'></script>
Node.js:
require('core-js');