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
12M
increased by3.91%
Maintainers
1
Install size
1.04 MB
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

Readme

Source

logo

fundraising PRs welcome version core-js-pure 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, Boosty, Bitcoin ( bc1qlea7544qtsmj2rayg0lthvza9fau63ux0fstcz ), Alipay.




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 version without global namespace pollution (the third example), for more info see core-js documentation.

Keywords

FAQs

Last updated on 16 Apr 2024

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