source: imaps-frontend/node_modules/core-js-compat/compat.js@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 2.4 KB
Line 
1'use strict';
2const { compare, filterOutStabilizedProposals, has, intersection } = require('./helpers');
3const data = require('./data');
4const entries = require('./entries');
5const getModulesListForTargetVersion = require('./get-modules-list-for-target-version');
6const allModules = require('./modules');
7const targetsParser = require('./targets-parser');
8
9function throwInvalidFilter(filter) {
10 throw new TypeError(`Specified invalid module name or pattern: ${ filter }`);
11}
12
13function atLeastSomeModules(modules, filter) {
14 if (!modules.length) throwInvalidFilter(filter);
15 return modules;
16}
17
18function getModules(filter) {
19 if (typeof filter == 'string') {
20 if (has(entries, filter)) return entries[filter];
21 return atLeastSomeModules(allModules.filter(it => it.startsWith(filter)), filter);
22 }
23 if (filter instanceof RegExp) return atLeastSomeModules(allModules.filter(it => filter.test(it)), filter);
24 throwInvalidFilter(filter);
25}
26
27function normalizeModules(option) {
28 // TODO: use `.flatMap` in core-js@4
29 return new Set(Array.isArray(option) ? [].concat(...option.map(getModules)) : getModules(option));
30}
31
32function checkModule(name, targets) {
33 const result = {
34 required: !targets,
35 targets: {},
36 };
37
38 if (!targets) return result;
39
40 const requirements = data[name];
41
42 for (const [engine, version] of targets) {
43 if (!has(requirements, engine) || compare(version, '<', requirements[engine])) {
44 result.required = true;
45 result.targets[engine] = version;
46 }
47 }
48
49 return result;
50}
51
52module.exports = function ({
53 filter = null, // TODO: Obsolete, remove from `core-js@4`
54 modules = null,
55 exclude = [],
56 targets = null,
57 version = null,
58 inverse = false,
59} = {}) {
60 if (modules === null || modules === undefined) modules = filter;
61 inverse = !!inverse;
62
63 const parsedTargets = targets ? targetsParser(targets) : null;
64
65 const result = {
66 list: [],
67 targets: {},
68 };
69
70 exclude = normalizeModules(exclude);
71
72 modules = modules ? [...normalizeModules(modules)] : allModules;
73
74 if (exclude.size) modules = modules.filter(it => !exclude.has(it));
75
76 modules = intersection(modules, version ? getModulesListForTargetVersion(version) : allModules);
77
78 if (!inverse) modules = filterOutStabilizedProposals(modules);
79
80 for (const key of modules) {
81 const check = checkModule(key, parsedTargets);
82
83 if (check.required ^ inverse) {
84 result.list.push(key);
85 result.targets[key] = check.targets;
86 }
87 }
88
89 return result;
90};
Note: See TracBrowser for help on using the repository browser.