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
Maintainers
1
Install size
1.03 MB
Created

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.27.0 - 2022.12.26

  • Iterator Helpers proposal:
    • Built-ins:
      • Iterator
        • Iterator.from
        • Iterator.prototype.drop
        • Iterator.prototype.every
        • Iterator.prototype.filter
        • Iterator.prototype.find
        • Iterator.prototype.flatMap
        • Iterator.prototype.forEach
        • Iterator.prototype.map
        • Iterator.prototype.reduce
        • Iterator.prototype.some
        • Iterator.prototype.take
        • Iterator.prototype.toArray
        • Iterator.prototype.toAsync
        • Iterator.prototype[@@toStringTag]
      • AsyncIterator
        • AsyncIterator.from
        • AsyncIterator.prototype.drop
        • AsyncIterator.prototype.every
        • AsyncIterator.prototype.filter
        • AsyncIterator.prototype.find
        • AsyncIterator.prototype.flatMap
        • AsyncIterator.prototype.forEach
        • AsyncIterator.prototype.map
        • AsyncIterator.prototype.reduce
        • AsyncIterator.prototype.some
        • AsyncIterator.prototype.take
        • AsyncIterator.prototype.toArray
        • AsyncIterator.prototype[@@toStringTag]
    • Moved to Stage 3, November 2022 TC39 meeting
    • Added /actual/ entries, unconditional forced replacement disabled for features that survived to Stage 3
    • .from accept strings, .flatMap throws on strings returned from the callback, proposal-iterator-helpers/244, proposal-iterator-helpers/250
    • .from and .flatMap throws on non-object iterators, proposal-iterator-helpers/253
  • Set methods proposal:
    • Built-ins:
      • Set.prototype.intersection
      • Set.prototype.union
      • Set.prototype.difference
      • Set.prototype.symmetricDifference
      • Set.prototype.isSubsetOf
      • Set.prototype.isSupersetOf
      • Set.prototype.isDisjointFrom
    • Moved to Stage 3, November 2022 TC39 meeting
    • Reimplemented with new semantics:
      • Optimized performance (iteration over lowest set)
      • Accepted only Set-like objects as an argument, not all iterables
      • Accepted only Sets as this, no @@species support, and other minor changes
    • Added /actual/ entries, unconditional forced replacement changed to feature detection
    • For avoiding breaking changes:
      • New versions of methods are implemented as new modules and available in new entries or entries where old versions of methods were not available before (like /actual/ namespace)
      • In entries where they were available before (like /full/ namespace), those methods are available with fallbacks to old semantics (in addition to Set-like, they accept iterable objects). This behavior will be removed from the next major release
  • Well-Formed Unicode Strings proposal:
    • Methods:
      • String.prototype.isWellFormed
      • String.prototype.toWellFormed
    • Moved to Stage 3, November 2022 TC39 meeting
    • Added /actual/ entries, disabled unconditional forced replacement
  • Explicit resource management Stage 3 and Async explicit resource management Stage 2 proposals:
    • Renamed from "using statement" and split into 2 (sync and async) proposals
    • In addition to already present well-known symbols, added new built-ins:
      • Symbol.dispose
      • Symbol.asyncDispose
      • SuppressedError
      • DisposableStack
        • DisposableStack.prototype.dispose
        • DisposableStack.prototype.use
        • DisposableStack.prototype.adopt
        • DisposableStack.prototype.defer
        • DisposableStack.prototype.move
        • DisposableStack.prototype[@@dispose]
      • AsyncDisposableStack
        • AsyncDisposableStack.prototype.disposeAsync
        • AsyncDisposableStack.prototype.use
        • AsyncDisposableStack.prototype.adopt
        • AsyncDisposableStack.prototype.defer
        • AsyncDisposableStack.prototype.move
        • AsyncDisposableStack.prototype[@@asyncDispose]
      • Iterator.prototype[@@dispose]
      • AsyncIterator.prototype[@@asyncDispose]
    • Sync version of this proposal moved to Stage 3, November 2022 TC39 meeting
    • Added /actual/ namespace entries for Stage 3 proposal
  • Added String.dedent stage 2 proposal
    • Method String.dedent
    • Throws an error on non-frozen raw templates for avoiding possible breaking changes in the future, proposal-string-dedent/75
  • Compat data targets improvements:
    • React Native from 0.70 shipped with Hermes as the default engine. However, bundled Hermes versions differ from standalone Hermes releases. So added react-native target for React Native with bundled Hermes.
    • According to the documentation, Oculus Browser was renamed to Meta Quest Browser, so oculus target was renamed to quest.
    • opera_mobile target name is confusing since it contains data for the Chromium-based Android version, but iOS Opera is Safari-based. So opera_mobile target was renamed to opera-android.
    • android target name is also confusing for someone - that means Android WebView, some think thinks that it's Chrome for Android, but they have some differences. For avoiding confusion, added chrome-android target.
    • For consistency with two previous cases, added firefox-android target.
    • For avoiding breaking changes, the oculus and opera_mobile fields are available in the compat data till the next major release.
  • Compat data improvements:
  • { Map, WeakMap }.prototype.emplace became stricter by the spec draft
  • Smoothed behavior of some conflicting proposals
  • Removed some generic behavior (like @@species pattern) of some .prototype methods from the new collections methods proposal and the Array deduplication proposal that most likely will not be implemented since it contradicts the current TC39 policy
  • Added pure version of the Number constructor, #1154, #1155, thanks @trosos
  • Added set(Timeout|Interval|Immediate) extra arguments fix for Bun 0.3.0- (similarly to IE9-), bun/1633
  • Fixed handling of sparse arrays in structuredClone, #1156
  • Fixed a theoretically possible future conflict of polyfills definitions in the pure version
  • Some refactoring and optimization

Readme

Source

logo

fundraising PRs welcome version core-js downloads

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.

As advertising: the author is looking for a good job -)

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




Example of usage:

import 'core-js/actual'; // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1]));          // => [1, 2, 3]
[1, 2, 3, 4, 5].group(it => it % 2);           // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3]));           // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));

You can load only required features:

import 'core-js/actual/array/from';       // <- at the top of your entry point
import 'core-js/actual/array/group';      // <- at the top of your entry point
import 'core-js/actual/set';              // <- at the top of your entry point
import 'core-js/actual/promise';          // <- at the top of your entry point
import 'core-js/actual/structured-clone'; // <- at the top of your entry point
import 'core-js/actual/queue-microtask';  // <- at the top of your entry point

Array.from(new Set([1, 2, 3, 2, 1]));          // => [1, 2, 3]
[1, 2, 3, 4, 5].group(it => it % 2);           // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3]));           // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));

Or use it without global namespace pollution:

import from from 'core-js-pure/actual/array/from';
import group from 'core-js-pure/actual/array/group';
import Set from 'core-js-pure/actual/set';
import Promise from 'core-js-pure/actual/promise';
import structuredClone from 'core-js-pure/actual/structured-clone';
import queueMicrotask from 'core-js-pure/actual/queue-microtask';

from(new Set([1, 2, 3, 2, 1]));                // => [1, 2, 3]
group([1, 2, 3, 4, 5], it => it % 2);          // => { 1: [1, 3, 5], 0: [2, 4] }
Promise.resolve(42).then(x => console.log(x)); // => 42
structuredClone(new Set([1, 2, 3]));           // => new Set([1, 2, 3])
queueMicrotask(() => console.log('called as microtask'));

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

Keywords

FAQs

Last updated on 25 Dec 2022

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc