按需加载
不污染全局命名空间
应用广泛
最受欢迎的 JavaScript polyfill,NPM 月下载量超过 2.5 亿次
轻松上手
与 Babel 和 SWC 等工具集成
功能强大
包括对从 ES5 到进行中的 ECMAScript 提案的 polyfill
赞助商
core-js
没有公司支持,所以这个项目的未来取决于你。如果你对 core-js
感兴趣,请成为赞助商或支持者。
使用示例
// https://tinyurl.com/2mknex43
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])
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])
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])
import "https://deno.land/x/corejs@v3.31.1/index.js"; // <- at the top of your entry point
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])