-
Notifications
You must be signed in to change notification settings - Fork 13
/
test.js
37 lines (31 loc) · 1.09 KB
/
test.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
var SEMVER = require('semver');
var parseRange = function(range) {
return SEMVER.toComparators(SEMVER.replaceStars(range.trim()));
};
var semverToDebian = function(pkg, ver) {
if(!ver) return pkg;
var ranges = parseRange(ver),
deps = [];
ranges.forEach(function(range) {
range.forEach(function(edge) {
if(!edge) {
deps.push(pkg);
} else {
edge = edge
.replace(/^(\d)/, '= $1')
.replace(/^(<|>)(\d)/, '$1$1 $2')
.replace(/^(>=|<=)/, '$1 ');
deps.push(pkg + ' (' + edge + ')');
}
});
});
return deps.join(' | ');
};
console.log(semverToDebian('nodejs', '*'));
console.log(semverToDebian('nodejs', '0.4.12'));
console.log(semverToDebian('nodejs', '~0.4.0'));
console.log(semverToDebian('nodejs', '0.4'));
console.log(semverToDebian('nodejs', '0.4 || 0.5 || 0.6'));
console.log(semverToDebian('nodejs', '=0.4'));
console.log(semverToDebian('nodejs', '>=0.4.0 <0.7.0'));
console.log(semverToDebian('nodejs', '0.x >=0.0.4'));