source: trip-planner-front/node_modules/semver/functions/cmp.js@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 907 bytes
RevLine 
[6a3a178]1const eq = require('./eq')
2const neq = require('./neq')
3const gt = require('./gt')
4const gte = require('./gte')
5const lt = require('./lt')
6const lte = require('./lte')
7
8const cmp = (a, op, b, loose) => {
9 switch (op) {
10 case '===':
11 if (typeof a === 'object')
12 a = a.version
13 if (typeof b === 'object')
14 b = b.version
15 return a === b
16
17 case '!==':
18 if (typeof a === 'object')
19 a = a.version
20 if (typeof b === 'object')
21 b = b.version
22 return a !== b
23
24 case '':
25 case '=':
26 case '==':
27 return eq(a, b, loose)
28
29 case '!=':
30 return neq(a, b, loose)
31
32 case '>':
33 return gt(a, b, loose)
34
35 case '>=':
36 return gte(a, b, loose)
37
38 case '<':
39 return lt(a, b, loose)
40
41 case '<=':
42 return lte(a, b, loose)
43
44 default:
45 throw new TypeError(`Invalid operator: ${op}`)
46 }
47}
48module.exports = cmp
Note: See TracBrowser for help on using the repository browser.