From 3a427d910ec6ac2cf86a4c87e2734b91103b362b Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Mon, 26 Dec 2022 00:29:35 +0700 Subject: [PATCH] update docs --- README.md | 78 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 99a0f369319e..da13399f4653 100644 --- a/README.md +++ b/README.md @@ -28,47 +28,71 @@ --- -[*Example of usage*](https://tinyurl.com/2aj9lkwf): +[*Example of usage*](https://tinyurl.com/2mknex43): ```js -import 'core-js/actual'; // <- at the top of your entry point +import 'core-js/actual'; -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')); +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*: ```js -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 +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'; -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')); +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*: ```js -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 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'; -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')); +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]) ``` ### Index