Socket
Socket
Sign inDemoInstall

core-js

Package Overview
Dependencies
0
Maintainers
1
Versions
273
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    core-js

Standard library


Version published
Weekly downloads
32M
increased by0.26%
Maintainers
1
Created
Weekly downloads
 

Package description

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

Changelog

Source

3.28.0 - 2023.02.14

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

  • Change Array by copy proposal:
    • Methods:
      • Array.prototype.toReversed
      • Array.prototype.toSorted
      • Array.prototype.toSpliced
      • Array.prototype.with
      • %TypedArray%.prototype.toReversed
      • %TypedArray%.prototype.toSorted
      • %TypedArray%.prototype.with
    • Moved to stable ES, January 2023 TC39 meeting
    • Added es. namespace modules, /es/ and /stable/ namespaces entries
  • Added JSON.parse source text access Stage 3 proposal
    • Methods:
      • JSON.parse patched for support source in reviver function arguments
      • JSON.rawJSON
      • JSON.isRawJSON
      • JSON.stringify patched for support JSON.rawJSON
  • Added ArrayBuffer.prototype.transfer and friends Stage 3 proposal:
    • Built-ins:
      • ArrayBuffer.prototype.detached
      • ArrayBuffer.prototype.transfer (only in runtimes with native structuredClone with ArrayBuffer transfer support)
      • ArrayBuffer.prototype.transferToFixedLength (only in runtimes with native structuredClone with ArrayBuffer transfer support)
    • In backwards, in runtimes with native ArrayBuffer.prototype.transfer, but without proper structuredClone, added ArrayBuffer transfer support to structuredClone polyfill
  • Iterator Helpers proposal:
  • Explicit Resource Management Stage 3 and Async Explicit Resource Management Stage 2 proposals:
  • Added Symbol predicates Stage 2 proposal
    • Methods:
      • Symbol.isRegistered
      • Symbol.isWellKnown
  • Number.range Stage 1 proposal and method renamed to Iterator.range
  • Function.prototype.unThis Stage 0 proposal and method renamed to Function.prototype.demethodize
  • Fixed Safari String.prototype.toWellFormed ToString conversion bug
  • Improved some cases handling of array-replacer in JSON.stringify symbols handling fix
  • Fixed many other old JSON.{ parse, stringify } bugs (numbers instead of strings as keys in replacer, handling negative zeroes, spaces, some more handling symbols cases, etc.)
  • Fixed configurability and ToString conversion of some accessors
  • Added throwing proper errors on an incorrect context in some ArrayBuffer and DataView methods
  • Some minor DataView and %TypedArray% polyfills optimizations
  • Added proper error on the excess number of trailing = in the atob polyfill
  • Fixed theoretically possible ReDoS vulnerabilities in String.prototype.{ trim, trimEnd, trimRight }, parse(Int|Float), Number, atob, and URL polyfills in some ancient engines
  • Compat data improvements:
    • RegExp.prototype.flags marked as fixed from V8 ~ Chrome 111
    • Added Opera Android 73 compat data mapping
  • Added TypeScript definitions to core-js-builder

Readme

Source

logo

fundraising PRs welcome version core-js downloads

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

Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2023: 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.

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, Bitcoin ( bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz ).




Example of usage:

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

It's a global version (first 2 examples), for more info see core-js documentation.

Keywords

FAQs

Last updated on 13 Feb 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc