How to use the cmp function from semver

Find comprehensive JavaScript semver.cmp code examples handpicked from public code repositorys.

33
34
35
36
37
38
39
40
41
42

function getNewComponentPath(customPath) {
    let newComponentPath = `${cwd}/markup/${componentsFolderName}/`;

    // Path to new component. Includes component name
    if (customPath && semver.cmp(currentTarsVersion, '>=', '1.8.0')) {
        newComponentPath += `${customPath}/${newComponentName}`;
    } else {
        newComponentPath += newComponentName;
    }
fork icon28
star icon105
watch icon15

78
79
80
81
82
83
84
85
86
87
  if (semver.cmp(version, operators[0], specifiedVersions[0])) {
    this.result[depName] = `${depVersion}`;
    break;
  }
} else if (operators.length > 1 && specifiedVersions.length > 1) {
  if (semver.cmp(version, operators[0], specifiedVersions[0]) && semver.cmp(version, operators[1], specifiedVersions[1])) {
    this.result[depName] = `${depVersion}`;
    break;
  }
}
fork icon8
star icon20
watch icon2

167
168
169
170
171
172
173
174
175
176
const range = new semver.Range(str);
for (let i = 0; i < range.set.length; i++) {
        const set = range.set[i];
        for (let j = set.length - 1; j >= 0; j--) {
                if (set[j].semver instanceof semver.SemVer) {
                        // console.log(ver, set[j].operator, set[j].semver, semver.cmp(ver, set[j].operator, set[j].semver, set[j].loose));
                        if ((set[j].operator === '<' || set[j].operator === '<=') && !semver.cmp(ver, set[j].operator, set[j].semver, set[j].loose)) {
                                return 'maybe';
                        }
                        break;
fork icon29
star icon11
watch icon53

42
43
44
45
46
47
48
49
50
51
rules.cmp = {
  method: function (cmp, exp) {
    return this.$_addRule({ name: 'cmp', args: { cmp, exp } })
  },
  validate: function (value, helpers, { cmp, exp }) {
    return semver.cmp(value, cmp, exp) ? value : helpers.error(`${extensionName}.cmp`, { cmp, exp })
  },
  args: [
    {
      name: 'cmp',
fork icon4
star icon7
watch icon3

57
58
59
60
61
62
63
64
65
66
                return SemVer[semverFunc](SemVish(a, loose), SemVish(b, loose), loose);
        };
});

SemVish.cmp = function(a, op, b, loose) {
        return SemVer.cmp(SemVish(a, loose), op, SemVish(b, loose), loose);
};

SemVish.clean = function(version, loose) {
        try {
fork icon1
star icon5
watch icon2