-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
getConditionsForCategory.js
50 lines (45 loc) · 1.12 KB
/
getConditionsForCategory.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
43
44
45
46
47
48
49
50
'use strict';
var entries = require('object.entries');
var ranges = require('./ranges');
/** @type {import('./getConditionsForCategory')} */
module.exports = function getConditionsForCategory(category) {
var rangeEntries = entries(ranges);
var found = false;
for (var i = 0; !found && i < rangeEntries.length; i++) {
var entry = rangeEntries[i];
found = entry[1] === category;
}
if (!found) {
throw new RangeError('invalid category ' + category);
}
var moduleSystem = arguments.length > 1 ? arguments[1] : null;
if (arguments.length > 1 && moduleSystem !== 'import' && moduleSystem !== 'require') {
throw new TypeError('invalid moduleSystem: must be `\'require\'` or `\'import\'` if provided, got' + moduleSystem);
}
if (category === 'experimental') {
return ['default'];
}
if (category !== 'broken' && category !== 'pre-exports') {
if (moduleSystem === 'import') {
return [
'import',
'node',
'default'
];
}
if (moduleSystem === 'require') {
return [
'node',
'require',
'default'
];
}
return [
'import',
'node',
'require',
'default'
];
}
return null;
};