Socket
Socket
Sign inDemoInstall

core-js-pure

Package Overview
Dependencies
0
Maintainers
1
Versions
150
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    core-js-pure

Standard library


Version published
Weekly downloads
9.9M
decreased by-17.17%
Maintainers
1
Install size
846 kB
Created
Weekly downloads
 

Package description

What is core-js-pure?

The core-js-pure package is a version of core-js that doesn't pollute the global namespace. It provides polyfills for ECMAScript features, including promises, symbols, collections, iterators, typed arrays, and many other features that are part of the ECMAScript specification but may not be available in all JavaScript environments.

What are core-js-pure's main functionalities?

Polyfilling Promises

This code sample demonstrates how to polyfill Promises using core-js-pure. It allows you to use Promises in environments where they are not natively supported.

import 'core-js-pure/stable/promise';

const promise = Promise.resolve(42);
promise.then(value => console.log(value));

Polyfilling Array methods

This code sample shows how to polyfill Array.prototype.find method. It enables the use of this method in environments where it is not part of the Array prototype.

import 'core-js-pure/stable/array/find';

const array = [1, 2, 3];
const found = array.find(item => item > 1);
console.log(found); // 2

Polyfilling Object static methods

This code sample illustrates how to polyfill Object.assign method. It allows the merging of multiple source objects into a target object in environments that do not support this method natively.

import 'core-js-pure/stable/object/assign';

const target = { a: 1 };
const source = { b: 2 };
const returnedTarget = Object.assign(target, source);

console.log(returnedTarget); // { a: 1, b: 2 }

Polyfilling String methods

This code sample demonstrates how to polyfill String.prototype.includes method. It provides a way to check if one string may be found within another string, returning true or false as appropriate.

import 'core-js-pure/stable/string/includes';

const string = 'hello world';
const includesHello = string.includes('hello');
console.log(includesHello); // true

Other packages similar to core-js-pure

Changelog

Source

3.22.0 - 2022.04.15

  • Change Array by copy proposal:
    • Moved to Stage 3, March TC39 meeting
    • Disabled forced replacement and added /actual/ entry points for methods from this proposal
    • Array.prototype.toSpliced throws a TypeError instead of RangeError if the result length is more than MAX_SAFE_INTEGER, proposal-change-array-by-copy/70
  • Added some more atob / btoa fixes:
    • NodeJS <17.9 atob does not ignore spaces, node/42530
    • Actual NodeJS atob does not validate encoding, node/42646
    • FF26- implementation does not properly convert argument to string
    • IE / Edge <16 implementation have wrong arity
  • Added /full/ namespace as the replacement for /features/ since it's more descriptive in context of the rest namespaces (/es//stable//actual//full/)
  • Avoided propagation of removed parts of proposals to upper stages. For example, %TypedArray%.prototype.groupBy was removed from the Array grouping proposal a long time ago. We can't completely remove this method since it's a breaking change. But this proposal has been promoted to stage 3 - so the proposal should be promoted without this method, this method should not be available in /actual/ entries - but it should be available in early-stage entries to avoid breakage.
  • Significant internal refactoring and splitting of modules (but without exposing to public API since it will be a breaking change - it will be exposed in the next major version)
  • Bug fixes:
    • Fixed work of non-standard V8 Error features with wrapped Error constructors, #1061
    • null and undefined allowed as the second argument of structuredClone, #1056
  • Tooling:
    • Stabilized proposals are filtered out from the core-js-compat -> core-js-builder -> core-js-bundle output. That mean that if the output contains, for example, es.object.has-own, the legacy reference to it, esnext.object.has-own, no longer added.
    • Aligned modules filters of core-js-builder and core-js-compat, now it's modules and exclude options
    • Added support of entry points, modules, regexes, and arrays of them to those filters
    • Missed targets option of core-js-compat means that the targets filter just will not be applied, so the result will contain modules required for all possible engines
  • Compat data:
    • .stack property on DOMException marked as supported from Deno 1.15
    • Added Deno 1.21 compat data mapping
    • Added Electron 19.0 and updated 18.0 compat data mapping
    • Added Samsung Internet 17.0 compat data mapping
    • Added Opera Android 68 compat data mapping

Readme

Source

logo

Open Collective version core-js downloads core-js-pure downloads tests eslint

Modular standard library for JavaScript. Includes polyfills for ECMAScript up to 2021: 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].groupBy(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-by';   // <- 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].groupBy(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 groupBy from 'core-js-pure/actual/array/group-by';
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]
groupBy([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 version without global namespace pollution (the third example), for more info see core-js documentation.

Keywords

FAQs

Last updated on 15 Apr 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