source: imaps-frontend/node_modules/core-js-compat/helpers.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.8 KB
RevLine 
[79a0317]1'use strict';
2// eslint-disable-next-line es/no-object-hasown -- safe
3const has = Object.hasOwn || Function.call.bind({}.hasOwnProperty);
4
5const VERSION_PATTERN = /(\d+)(?:\.(\d+))?(?:\.(\d+))?/;
6
7class SemVer {
8 constructor(input) {
9 const match = VERSION_PATTERN.exec(input);
10 if (!match) throw new TypeError(`Invalid version: ${ input }`);
11 const [, $major, $minor, $patch] = match;
12 this.major = +$major;
13 this.minor = $minor ? +$minor : 0;
14 this.patch = $patch ? +$patch : 0;
15 }
16 toString() {
17 return `${ this.major }.${ this.minor }.${ this.patch }`;
18 }
19}
20
21function semver(input) {
22 return input instanceof SemVer ? input : new SemVer(input);
23}
24
25function compare($a, operator, $b) {
26 const a = semver($a);
27 const b = semver($b);
28 for (const component of ['major', 'minor', 'patch']) {
29 if (a[component] < b[component]) return operator === '<' || operator === '<=' || operator === '!=';
30 if (a[component] > b[component]) return operator === '>' || operator === '>=' || operator === '!=';
31 } return operator === '==' || operator === '<=' || operator === '>=';
32}
33
34function filterOutStabilizedProposals(modules) {
35 const modulesSet = new Set(modules);
36
37 for (const $module of modulesSet) {
38 if ($module.startsWith('esnext.') && modulesSet.has($module.replace(/^esnext\./, 'es.'))) {
39 modulesSet.delete($module);
40 }
41 }
42
43 return [...modulesSet];
44}
45
46function intersection(list, order) {
47 const set = list instanceof Set ? list : new Set(list);
48 return order.filter(name => set.has(name));
49}
50
51function sortObjectByKey(object, fn) {
52 return Object.keys(object).sort(fn).reduce((memo, key) => {
53 memo[key] = object[key];
54 return memo;
55 }, {});
56}
57
58module.exports = {
59 compare,
60 filterOutStabilizedProposals,
61 has,
62 intersection,
63 semver,
64 sortObjectByKey,
65};
Note: See TracBrowser for help on using the repository browser.