-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.js
41 lines (31 loc) · 1.01 KB
/
index.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
'use strict';
const semver = require('semver');
const modules = require('./modules');
module.exports = function (moduleName, version, options) {
options = options || {};
const env = options.env || 'development';
if (typeof moduleName !== 'string') {
throw new TypeError('Expected \'moduleName\' to be a string');
}
if (typeof version !== 'string') {
throw new TypeError('Expected \'version\' to be a string');
}
const isModuleAvailable = moduleName in modules;
if (!isModuleAvailable) {
return null;
}
const range = Object.keys(modules[moduleName].versions)
.find(range => semver.satisfies(version, range));
const config = modules[moduleName].versions[range];
if (config == null) {
return null;
}
let url = env === 'development' ? config.development : config.production;
url = url.replace('[version]', version);
return {
name: moduleName,
var: modules[moduleName].var,
url,
version
};
};