helpers.js 636 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const cmp = require('semver/functions/cmp');
  3. const semver = require('semver/functions/coerce');
  4. const has = Function.call.bind({}.hasOwnProperty);
  5. function compare(a, operator, b) {
  6. return cmp(semver(a), operator, semver(b));
  7. }
  8. function intersection(list, order) {
  9. const set = list instanceof Set ? list : new Set(list);
  10. return order.filter(name => set.has(name));
  11. }
  12. function sortObjectByKey(object, fn) {
  13. return Object.keys(object).sort(fn).reduce((memo, key) => {
  14. memo[key] = object[key];
  15. return memo;
  16. }, {});
  17. }
  18. module.exports = {
  19. compare,
  20. has,
  21. intersection,
  22. semver,
  23. sortObjectByKey,
  24. };