core-js-compat 3.4.5 → 3.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,33 +1,26 @@
1
- [`core-js-compat` package](https://github.com/zloirock/core-js/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.
1
+ [`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.
2
2
 
3
3
  ```js
4
4
  const {
5
5
  list, // array of required modules
6
6
  targets, // object with targets for each module
7
7
  } = require('core-js-compat')({
8
- targets: '> 2.5%', // browserslist query
8
+ targets: '> 2.5%', // browserslist query or object of minimum environment versions to support
9
9
  filter: /^(es|web)\./, // optional filter - string-prefix, regexp or list of modules
10
+ version: '3.4', // used `core-js` version, by default - the latest
10
11
  });
11
12
 
12
13
  console.log(targets);
13
14
  /* =>
14
15
  {
15
- 'es.symbol.description': { ios: '12.2-12.4' },
16
16
  'es.symbol.match-all': { ios: '12.2-12.4' },
17
- 'es.array.reverse': { ios: '12.2-12.4' },
18
17
  'es.array.unscopables.flat': { ios: '12.2-12.4' },
19
18
  'es.array.unscopables.flat-map': { ios: '12.2-12.4' },
20
- 'es.array-buffer.slice': { ios: '12.2-12.4' },
21
- 'es.global-this': { ios: '12.2-12.4' },
22
- 'es.json.stringify': { ios: '12.2-12.4' },
23
19
  'es.math.hypot': { chrome: '77' },
24
- 'es.object.from-entries': { ios: '12.2-12.4' },
25
20
  'es.promise.all-settled': { firefox: '69', ios: '12.2-12.4' },
26
21
  'es.promise.finally': { ios: '12.2-12.4' },
27
22
  'es.string.match-all': { chrome: '77', firefox: '69', ios: '12.2-12.4' },
28
23
  'es.string.replace': { firefox: '69', ios: '12.2-12.4' },
29
- 'es.string.trim': { ios: '12.2-12.4' },
30
- 'es.string.trim-end': { ios: '12.2-12.4' },
31
24
  'es.typed-array.float32-array': { ios: '12.2-12.4' },
32
25
  'es.typed-array.float64-array': { ios: '12.2-12.4' },
33
26
  'es.typed-array.int8-array': { ios: '12.2-12.4' },
@@ -41,7 +34,6 @@ console.log(targets);
41
34
  'es.typed-array.of': { ios: '12.2-12.4' },
42
35
  'web.dom-collections.iterator': { ios: '12.2-12.4' },
43
36
  'web.immediate': { chrome: '77', firefox: '69', ios: '12.2-12.4' },
44
- 'web.queue-microtask': { ios: '12.2-12.4' },
45
37
  'web.url': { ios: '12.2-12.4' },
46
38
  'web.url.to-json': { ios: '12.2-12.4' },
47
39
  'web.url-search-params': { ios: '12.2-12.4' }
@@ -49,4 +41,33 @@ console.log(targets);
49
41
  */
50
42
  ```
51
43
 
44
+ Additional API:
45
+
46
+ ```js
47
+ // equals of of the method from the example above
48
+ require('core-js-compat/compat')({ targets, filter, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } }
49
+ // or
50
+ require('core-js-compat').compat({ targets, filter, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } }
51
+
52
+ // full compat data:
53
+ require('core-js-compat/data'); // => { [ModuleName]: { [EngineName]: EngineVersion } }
54
+ // or
55
+ require('core-js-compat').data; // => { [ModuleName]: { [EngineName]: EngineVersion } }
56
+
57
+ // map of modules by `core-js` entry points:
58
+ require('core-js-compat/entries'); // => { [EntryPoint]: Array<ModuleName> }
59
+ // or
60
+ require('core-js-compat').entries; // => { [EntryPoint]: Array<ModuleName> }
61
+
62
+ // full list of modules:
63
+ require('core-js-compat/modules'); // => Array<ModuleName>
64
+ // or
65
+ require('core-js-compat').modules; // => Array<ModuleName>
66
+
67
+ // the subset of modules which available in the passed `core-js` version:
68
+ require('core-js-compat/get-modules-list-for-target-version')('3.3'); // => Array<ModuleName>
69
+ // or
70
+ require('core-js-compat').getModulesListForTargetVersion('3.3'); // => Array<ModuleName>
71
+ ```
72
+
52
73
  If you want to add new / update data about modules required for target engines, [follow this instruction](https://github.com/zloirock/core-js/blob/master/CONTRIBUTING.md#updating-core-js-compat-data).
package/compat.js ADDED
@@ -0,0 +1,56 @@
1
+ 'use strict';
2
+ const { compare, has, intersection } = require('./helpers');
3
+ const data = require('./data');
4
+ const getModulesListForTargetVersion = require('./get-modules-list-for-target-version');
5
+ const modules = require('./modules');
6
+ const targetsParser = require('./targets-parser');
7
+
8
+ function checkModule(name, targets) {
9
+ if (!has(data, name)) throw new TypeError(`Incorrect module: ${ name }`);
10
+
11
+ const requirements = data[name];
12
+ const result = {
13
+ required: false,
14
+ targets: {},
15
+ };
16
+
17
+ for (const [engine, version] of targets) {
18
+ if (!has(requirements, engine) || compare(version, '<', requirements[engine])) {
19
+ result.required = true;
20
+ result.targets[engine] = version;
21
+ }
22
+ }
23
+
24
+ return result;
25
+ }
26
+
27
+ module.exports = function ({ targets, filter, version }) {
28
+ const parsedTargets = targetsParser(targets);
29
+
30
+ const result = {
31
+ list: [],
32
+ targets: {},
33
+ };
34
+
35
+ let $modules = Array.isArray(filter) ? filter : modules;
36
+
37
+ if (filter instanceof RegExp) {
38
+ $modules = $modules.filter(it => filter.test(it));
39
+ } else if (typeof filter == 'string') {
40
+ $modules = $modules.filter(it => it.startsWith(filter));
41
+ }
42
+
43
+ if (version) {
44
+ $modules = intersection($modules, getModulesListForTargetVersion(version));
45
+ }
46
+
47
+ for (const key of $modules) {
48
+ const check = checkModule(key, parsedTargets);
49
+ if (check.required) {
50
+ result.list.push(key);
51
+ result.targets[key] = check.targets;
52
+ }
53
+ }
54
+
55
+ return result;
56
+ };