Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
636 bytes
|
Rev | Line | |
---|
[6a3a178] | 1 | 'use strict';
|
---|
| 2 | const cmp = require('semver/functions/cmp');
|
---|
| 3 | const semver = require('semver/functions/coerce');
|
---|
| 4 |
|
---|
| 5 | const has = Function.call.bind({}.hasOwnProperty);
|
---|
| 6 |
|
---|
| 7 | function compare(a, operator, b) {
|
---|
| 8 | return cmp(semver(a), operator, semver(b));
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | function intersection(list, order) {
|
---|
| 12 | const set = list instanceof Set ? list : new Set(list);
|
---|
| 13 | return order.filter(name => set.has(name));
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | function sortObjectByKey(object, fn) {
|
---|
| 17 | return Object.keys(object).sort(fn).reduce((memo, key) => {
|
---|
| 18 | memo[key] = object[key];
|
---|
| 19 | return memo;
|
---|
| 20 | }, {});
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | module.exports = {
|
---|
| 24 | compare,
|
---|
| 25 | has,
|
---|
| 26 | intersection,
|
---|
| 27 | semver,
|
---|
| 28 | sortObjectByKey,
|
---|
| 29 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.