core-js-compat
Advanced tools
Comparing version 3.21.1 to 3.22.0
'use strict'; | ||
const { compare, has, intersection } = require('./helpers'); | ||
const { compare, filterOutStabilizedProposals, has, intersection } = require('./helpers'); | ||
const data = require('./data'); | ||
const entries = require('./entries'); | ||
const getModulesListForTargetVersion = require('./get-modules-list-for-target-version'); | ||
const modules = require('./modules'); | ||
const allModules = require('./modules'); | ||
const targetsParser = require('./targets-parser'); | ||
function getModules(filter) { | ||
if (typeof filter == 'string') { | ||
if (has(entries, filter)) return entries[filter]; | ||
return allModules.filter(it => it.startsWith(filter)); | ||
} else if (filter instanceof RegExp) return allModules.filter(it => filter.test(it)); | ||
throw TypeError('Wrong filter!'); | ||
} | ||
function normalizeModules(option) { | ||
// TODO: use `.flatMap` in core-js@4 | ||
return new Set(Array.isArray(option) ? [].concat.apply([], option.map(getModules)) : getModules(option)); | ||
} | ||
function checkModule(name, targets) { | ||
if (!has(data, name)) throw new TypeError(`Incorrect module: ${ name }`); | ||
const requirements = data[name]; | ||
const result = { | ||
required: false, | ||
required: !targets, | ||
targets: {}, | ||
}; | ||
if (!targets) return result; | ||
const requirements = data[name]; | ||
for (const [engine, version] of targets) { | ||
@@ -27,5 +42,13 @@ if (!has(requirements, engine) || compare(version, '<', requirements[engine])) { | ||
module.exports = function ({ targets, filter, version }) { | ||
const parsedTargets = targetsParser(targets); | ||
module.exports = function ({ | ||
filter = null, // TODO: Obsolete, remove from `core-js@4` | ||
modules = null, | ||
exclude = [], | ||
targets = null, | ||
version = null, | ||
} = {}) { | ||
if (modules == null) modules = filter; | ||
const parsedTargets = targets ? targetsParser(targets) : null; | ||
const result = { | ||
@@ -36,16 +59,15 @@ list: [], | ||
let $modules = Array.isArray(filter) ? filter : modules; | ||
exclude = normalizeModules(exclude); | ||
if (filter instanceof RegExp) { | ||
$modules = $modules.filter(it => filter.test(it)); | ||
} else if (typeof filter == 'string') { | ||
$modules = $modules.filter(it => it.startsWith(filter)); | ||
} | ||
modules = modules ? [...normalizeModules(modules)] : allModules; | ||
if (version) { | ||
$modules = intersection($modules, getModulesListForTargetVersion(version)); | ||
} | ||
if (exclude.size) modules = modules.filter(it => !exclude.has(it)); | ||
for (const key of $modules) { | ||
modules = intersection(modules, version ? getModulesListForTargetVersion(version) : allModules); | ||
modules = filterOutStabilizedProposals(modules); | ||
for (const key of modules) { | ||
const check = checkModule(key, parsedTargets); | ||
if (check.required) { | ||
@@ -52,0 +74,0 @@ result.list.push(key); |
@@ -11,2 +11,14 @@ 'use strict'; | ||
function filterOutStabilizedProposals(modules) { | ||
const modulesSet = new Set(modules); | ||
for (const $module of modulesSet) { | ||
if ($module.startsWith('esnext.') && modulesSet.has($module.replace(/^esnext\./, 'es.'))) { | ||
modulesSet.delete($module); | ||
} | ||
} | ||
return [...modulesSet]; | ||
} | ||
function intersection(list, order) { | ||
@@ -26,2 +38,3 @@ const set = list instanceof Set ? list : new Set(list); | ||
compare, | ||
filterOutStabilizedProposals, | ||
has, | ||
@@ -28,0 +41,0 @@ intersection, |
{ | ||
"name": "core-js-compat", | ||
"description": "core-js compat", | ||
"version": "3.21.1", | ||
"version": "3.22.0", | ||
"repository": { | ||
@@ -12,3 +12,3 @@ "type": "git", | ||
"dependencies": { | ||
"browserslist": "^4.19.1", | ||
"browserslist": "^4.20.2", | ||
"semver": "7.0.0" | ||
@@ -21,3 +21,3 @@ }, | ||
"license": "MIT", | ||
"gitHead": "eb9229ae88428edea6b2be250c98a518fd2c22e3" | ||
"gitHead": "c5e56b664756455f9715481eca92f4a3a421f475" | ||
} |
@@ -6,9 +6,18 @@ ![logo](https://user-images.githubusercontent.com/2213682/146607186-8e13ddef-26a4-4ebf-befd-5aac9d77c090.png) | ||
```js | ||
import compat from 'core-js-compat'; | ||
const { | ||
list, // array of required modules | ||
targets, // object with targets for each module | ||
} = require('core-js-compat')({ | ||
targets: '> 2.5%', // browserslist query or object of minimum environment versions to support | ||
filter: /^(es|web)\./, // optional filter - string-prefix, regexp or list of modules | ||
version: '3.21', // used `core-js` version, by default - the latest | ||
list, // array of required modules | ||
targets, // object with targets for each module | ||
} = compat({ | ||
targets: '> 1%', // browserslist query or object of minimum environment versions to support, see below | ||
modules: [ // optional list / filter of modules - regex, sting or an array of them: | ||
'core-js/actual', // - an entry point | ||
'esnext.array.unique-by', // - a module name (or just a start of a module name) | ||
/^web\./, // - regex that a module name must satisfy | ||
], | ||
exclude: [ // optional list / filter of modules to exclude, the signature is similar to `modules` option | ||
'web.atob', | ||
], | ||
version: '3.22', // used `core-js` version, by default - the latest | ||
}); | ||
@@ -19,26 +28,27 @@ | ||
{ | ||
'es.symbol.match-all': { ios: '12.2-12.4' }, | ||
'es.array.unscopables.flat': { ios: '12.2-12.4' }, | ||
'es.array.unscopables.flat-map': { ios: '12.2-12.4' }, | ||
'es.math.hypot': { chrome: '77' }, | ||
'es.promise.all-settled': { firefox: '69', ios: '12.2-12.4' }, | ||
'es.promise.finally': { ios: '12.2-12.4' }, | ||
'es.string.match-all': { chrome: '77', firefox: '69', ios: '12.2-12.4' }, | ||
'es.string.replace': { firefox: '69', ios: '12.2-12.4' }, | ||
'es.typed-array.float32-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.float64-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.int8-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.int16-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.int32-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.uint8-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.uint8-clamped-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.uint16-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.uint32-array': { ios: '12.2-12.4' }, | ||
'es.typed-array.from': { ios: '12.2-12.4' }, | ||
'es.typed-array.of': { ios: '12.2-12.4' }, | ||
'web.dom-collections.iterator': { ios: '12.2-12.4' }, | ||
'web.immediate': { chrome: '77', firefox: '69', ios: '12.2-12.4' }, | ||
'web.url': { ios: '12.2-12.4' }, | ||
'web.url.to-json': { ios: '12.2-12.4' }, | ||
'web.url-search-params': { ios: '12.2-12.4' } | ||
'es.error.cause': { ios: '14.5-14.8', samsung: '16.0' }, | ||
'es.aggregate-error.cause': { ios: '14.5-14.8', samsung: '16.0' }, | ||
'es.array.at': { ios: '14.5-14.8' }, | ||
'es.object.has-own': { ios: '14.5-14.8', samsung: '16.0' }, | ||
'es.string.at-alternative': { ios: '14.5-14.8' }, | ||
'es.typed-array.at': { ios: '14.5-14.8' }, | ||
'es.typed-array.set': { samsung: '16.0' }, | ||
'esnext.array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.group-by': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.group-by-to-map': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.to-reversed': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.to-sorted': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.to-spliced': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.unique-by': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.array.with': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.typed-array.find-last': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.typed-array.find-last-index': { firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.typed-array.to-reversed': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.typed-array.to-sorted': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.typed-array.to-spliced': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'esnext.typed-array.with': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'web.dom-exception.stack': { chrome: '98', edge: '99', ios: '14.5-14.8', samsung: '16.0' }, | ||
'web.immediate': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' }, | ||
'web.structured-clone': { chrome: '98', edge: '99', firefox: '98', ios: '14.5-14.8', samsung: '16.0' } | ||
} | ||
@@ -79,5 +89,5 @@ */ | ||
// equals of of the method from the example above | ||
require('core-js-compat/compat')({ targets, filter, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } } | ||
require('core-js-compat/compat')({ targets, modules, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } } | ||
// or | ||
require('core-js-compat').compat({ targets, filter, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } } | ||
require('core-js-compat').compat({ targets, modules, version }); // => { list: Array<ModuleName>, targets: { [ModuleName]: { [EngineName]: EngineVersion } } } | ||
@@ -100,7 +110,7 @@ // full compat data: | ||
// the subset of modules which available in the passed `core-js` version: | ||
require('core-js-compat/get-modules-list-for-target-version')('3.21'); // => Array<ModuleName> | ||
require('core-js-compat/get-modules-list-for-target-version')('3.22'); // => Array<ModuleName> | ||
// or | ||
require('core-js-compat').getModulesListForTargetVersion('3.21'); // => Array<ModuleName> | ||
require('core-js-compat').getModulesListForTargetVersion('3.22'); // => Array<ModuleName> | ||
``` | ||
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). |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
529796
20873
113
Updatedbrowserslist@^4.20.2