[79a0317] | 1 | ![logo](https://user-images.githubusercontent.com/2213682/146607186-8e13ddef-26a4-4ebf-befd-5aac9d77c090.png)
|
---|
| 2 |
|
---|
| 3 | <div align="center">
|
---|
| 4 |
|
---|
| 5 | [![fundraising](https://opencollective.com/core-js/all/badge.svg?label=fundraising)](https://opencollective.com/core-js) [![PRs welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/zloirock/core-js/blob/master/CONTRIBUTING.md) [![version](https://img.shields.io/npm/v/core-js-compat.svg)](https://www.npmjs.com/package/core-js-compat) [![core-js-compat downloads](https://img.shields.io/npm/dm/core-js-compat.svg?label=npm%20i%20core-js-compat)](https://npm-stat.com/charts.html?package=core-js&package=core-js-pure&package=core-js-compat&from=2014-11-18)
|
---|
| 6 |
|
---|
| 7 | </div>
|
---|
| 8 |
|
---|
| 9 | **I highly recommend reading this: [So, what's next?](https://github.com/zloirock/core-js/blob/master/docs/2023-02-14-so-whats-next.md)**
|
---|
| 10 | ---
|
---|
| 11 |
|
---|
| 12 | [`core-js-compat` package](https://github.com/zloirock/core-js/tree/master/packages/core-js-compat) contains data about the necessity of [`core-js`](https://github.com/zloirock/core-js) modules and API for getting a list of required core-js modules by browserslist query.
|
---|
| 13 |
|
---|
| 14 | ```js
|
---|
| 15 | import compat from 'core-js-compat';
|
---|
| 16 |
|
---|
| 17 | const {
|
---|
| 18 | list, // array of required modules
|
---|
| 19 | targets, // object with targets for each module
|
---|
| 20 | } = compat({
|
---|
| 21 | targets: '> 1%', // browserslist query or object of minimum environment versions to support, see below
|
---|
| 22 | modules: [ // optional list / filter of modules - regex, string or an array of them:
|
---|
| 23 | 'core-js/actual', // - an entry point
|
---|
| 24 | 'esnext.array.unique-by', // - a module name (or just a start of a module name)
|
---|
| 25 | /^web\./, // - regex that a module name must satisfy
|
---|
| 26 | ],
|
---|
| 27 | exclude: [ // optional list / filter of modules to exclude, the signature is similar to `modules` option
|
---|
| 28 | 'web.atob',
|
---|
| 29 | ],
|
---|
| 30 | version: '3.40', // used `core-js` version, by default - the latest
|
---|
| 31 | inverse: false, // inverse of the result - shows modules that are NOT required for the target environment
|
---|
| 32 | });
|
---|
| 33 |
|
---|
| 34 | console.log(targets);
|
---|
| 35 | /* =>
|
---|
| 36 | {
|
---|
| 37 | 'es.error.cause': { ios: '14.5-14.8' },
|
---|
| 38 | 'es.aggregate-error.cause': { ios: '14.5-14.8' },
|
---|
| 39 | 'es.array.at': { ios: '14.5-14.8' },
|
---|
| 40 | 'es.array.find-last': { firefox: '100', ios: '14.5-14.8' },
|
---|
| 41 | 'es.array.find-last-index': { firefox: '100', ios: '14.5-14.8' },
|
---|
| 42 | 'es.array.includes': { firefox: '100' },
|
---|
| 43 | 'es.array.push': { chrome: '100', edge: '101', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 44 | 'es.array.unshift': { ios: '14.5-14.8', safari: '15.4' },
|
---|
| 45 | 'es.object.has-own': { ios: '14.5-14.8' },
|
---|
| 46 | 'es.regexp.flags': { chrome: '100', edge: '101' },
|
---|
| 47 | 'es.string.at-alternative': { ios: '14.5-14.8' },
|
---|
| 48 | 'es.typed-array.at': { ios: '14.5-14.8' },
|
---|
| 49 | 'es.typed-array.find-last': { firefox: '100', ios: '14.5-14.8' },
|
---|
| 50 | 'es.typed-array.find-last-index': { firefox: '100', ios: '14.5-14.8' },
|
---|
| 51 | 'esnext.array.group': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 52 | 'esnext.array.group-by': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 53 | 'esnext.array.group-by-to-map': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 54 | 'esnext.array.group-to-map': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 55 | 'esnext.array.to-reversed': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 56 | 'esnext.array.to-sorted': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 57 | 'esnext.array.to-spliced': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 58 | 'esnext.array.unique-by': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 59 | 'esnext.array.with': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 60 | 'esnext.typed-array.to-reversed': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 61 | 'esnext.typed-array.to-sorted': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 62 | 'esnext.typed-array.to-spliced': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 63 | 'esnext.typed-array.with': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 64 | 'web.dom-exception.stack': { chrome: '100', edge: '101', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 65 | 'web.immediate': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' },
|
---|
| 66 | 'web.structured-clone': { chrome: '100', edge: '101', firefox: '100', ios: '14.5-14.8', safari: '15.4' }
|
---|
| 67 | }
|
---|
| 68 | */
|
---|
| 69 | ```
|
---|
| 70 |
|
---|
| 71 | ### `targets` option
|
---|
| 72 | `targets` could be [a `browserslist` query](https://github.com/browserslist/browserslist) or a targets object that specifies minimum environment versions to support:
|
---|
| 73 | ```js
|
---|
| 74 | // browserslist query:
|
---|
| 75 | 'defaults, not IE 11, maintained node versions';
|
---|
| 76 | // object (sure, all those fields optional):
|
---|
| 77 | ({
|
---|
| 78 | android: '4.0', // Android WebView version
|
---|
| 79 | bun: '0.1.2', // Bun version
|
---|
| 80 | chrome: '38', // Chrome version
|
---|
| 81 | 'chrome-android': '18', // Chrome for Android version
|
---|
| 82 | deno: '1.12', // Deno version
|
---|
| 83 | edge: '13', // Edge version
|
---|
| 84 | electron: '5.0', // Electron framework version
|
---|
| 85 | firefox: '15', // Firefox version
|
---|
| 86 | 'firefox-android': '4', // Firefox for Android version
|
---|
| 87 | hermes: '0.11', // Hermes version
|
---|
| 88 | ie: '8', // Internet Explorer version
|
---|
| 89 | ios: '13.0', // iOS Safari version
|
---|
| 90 | node: 'current', // NodeJS version, you can use 'current' for set it to currently used
|
---|
| 91 | opera: '12', // Opera version
|
---|
| 92 | 'opera-android': '7', // Opera for Android version
|
---|
| 93 | phantom: '1.9', // PhantomJS headless browser version
|
---|
| 94 | quest: '5.0', // Meta Quest Browser version
|
---|
| 95 | 'react-native': '0.70', // React Native version (default Hermes engine)
|
---|
| 96 | rhino: '1.7.13', // Rhino engine version
|
---|
| 97 | safari: '14.0', // Safari version
|
---|
| 98 | samsung: '14.0', // Samsung Internet version
|
---|
| 99 | esmodules: true, // That option set target to minimum supporting ES Modules versions of all browsers
|
---|
| 100 | browsers: '> 0.25%', // Browserslist query or object with target browsers
|
---|
| 101 | });
|
---|
| 102 | ```
|
---|
| 103 |
|
---|
| 104 | ### Additional API:
|
---|
| 105 |
|
---|
| 106 | ```js
|
---|
| 107 | // equals of of the method from the example above
|
---|
| 108 | require('core-js-compat/compat')({ targets, modules, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } }
|
---|
| 109 | // or
|
---|
| 110 | require('core-js-compat').compat({ targets, modules, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } }
|
---|
| 111 |
|
---|
| 112 | // full compat data:
|
---|
| 113 | require('core-js-compat/data'); // => { [ModuleName]: { [EngineName]: EngineVersion } }
|
---|
| 114 | // or
|
---|
| 115 | require('core-js-compat').data; // => { [ModuleName]: { [EngineName]: EngineVersion } }
|
---|
| 116 |
|
---|
| 117 | // map of modules by `core-js` entry points:
|
---|
| 118 | require('core-js-compat/entries'); // => { [EntryPoint]: Array<ModuleName> }
|
---|
| 119 | // or
|
---|
| 120 | require('core-js-compat').entries; // => { [EntryPoint]: Array<ModuleName> }
|
---|
| 121 |
|
---|
| 122 | // full list of modules:
|
---|
| 123 | require('core-js-compat/modules'); // => Array<ModuleName>
|
---|
| 124 | // or
|
---|
| 125 | require('core-js-compat').modules; // => Array<ModuleName>
|
---|
| 126 |
|
---|
| 127 | // the subset of modules which available in the passed `core-js` version:
|
---|
| 128 | require('core-js-compat/get-modules-list-for-target-version')('3.40'); // => Array<ModuleName>
|
---|
| 129 | // or
|
---|
| 130 | require('core-js-compat').getModulesListForTargetVersion('3.40'); // => Array<ModuleName>
|
---|
| 131 | ```
|
---|
| 132 |
|
---|
| 133 | If you wanna help to improve this data, you could take a look at the related section of [`CONTRIBUTING.md`](https://github.com/zloirock/core-js/blob/master/CONTRIBUTING.md#how-to-update-core-js-compat-data). The visualization of compatibility data and the browser tests runner is available [here](http://zloirock.github.io/core-js/compat/), the example:
|
---|
| 134 |
|
---|
| 135 | ![compat-table](https://user-images.githubusercontent.com/2213682/217452234-ccdcfc5a-c7d3-40d1-ab3f-86902315b8c3.png)
|
---|