Last change
on this file since fa375fe was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
907 bytes
|
Line | |
---|
1 | const eq = require('./eq')
|
---|
2 | const neq = require('./neq')
|
---|
3 | const gt = require('./gt')
|
---|
4 | const gte = require('./gte')
|
---|
5 | const lt = require('./lt')
|
---|
6 | const lte = require('./lte')
|
---|
7 |
|
---|
8 | const 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 | }
|
---|
48 | module.exports = cmp
|
---|
Note:
See
TracBrowser
for help on using the repository browser.