forked from zloirock/core-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
42 lines (34 loc) · 965 Bytes
/
helpers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const cmp = require('semver/functions/cmp');
const semver = require('semver/functions/coerce');
const has = Function.call.bind({}.hasOwnProperty);
function compare(a, operator, b) {
return cmp(semver(a), operator, semver(b));
}
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) {
const set = list instanceof Set ? list : new Set(list);
return order.filter(name => set.has(name));
}
function sortObjectByKey(object, fn) {
return Object.keys(object).sort(fn).reduce((memo, key) => {
memo[key] = object[key];
return memo;
}, {});
}
module.exports = {
compare,
filterOutStabilizedProposals,
has,
intersection,
semver,
sortObjectByKey,
};