How to use the minor function from semver

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

semver.minor is a function in the SemVer library that returns the minor version number of a given semantic version string.

207
208
209
210
211
212
213
214
215
216
 * @returns {int}
 */
function versionToReleaseWeight(version) {
  return semver.major(version) > 0
    ? RELEASE_WEIGHT.MAJOR
    : semver.minor(version) > 0
    ? RELEASE_WEIGHT.MINOR
    : RELEASE_WEIGHT.PATCH
}

fork icon202
star icon563
watch icon40

+ 2 other calls in file

34
35
36
37
38
39
40
41
42
43
}

// Special handling for major version 0
if (semver.major(min) === 0 && semver.major(max) === 0) {
    // ^0.0.5
    if (semver.minor(min) === 0 && semver.minor(max) === 0) {
        return `^${min}`;
    }

    // ~0.0.5
fork icon0
star icon0
watch icon1

How does semver.minor work?

The semver.minor function is a part of the semver library and is used to retrieve the minor version number from a given semver version string, according to the semver specification. It takes a version string as an argument and returns the minor version number as an integer. If the version string does not have a minor version number, the function returns 0.

13
14
15
16
17
18
19
20
21
22
 * as the value.  For example, the version `9.6.0-beta.1` would return the object
 * `{ firefox: { version: '9.6.0.beta1' }, chrome: { version: '9.6.0.1', version_name: '9.6.0-beta.1' } }`.
 */
function getBrowserVersionMap(platforms, version) {
  const major = semver.major(version);
  const minor = semver.minor(version);
  const patch = semver.patch(version);
  const prerelease = semver.prerelease(version);
  let buildType, buildVersionSummary, buildVersion;
  if (prerelease) {
fork icon0
star icon0
watch icon0

5
6
7
8
9
10
11
12
13
14
if (!semver.valid(version)) return '';

const changelogs = 'https://github.com/nodejs/node/blob/main/doc/changelogs';
const clean = semver.clean(version);
const major = semver.major(clean);
const minor = semver.minor(clean);

if (major >= 4) return `${changelogs}/CHANGELOG_V${major}.md#${clean}`;
if (major >= 1) return `${changelogs}/CHANGELOG_IOJS.md#${clean}`;
if (minor === 12 || minor === 10) {
fork icon0
star icon0
watch icon0

Ai Example

1
2
3
4
5
6
const semver = require("semver");

const version = "1.2.3";
const minor = semver.minor(version);

console.log(minor); // output: 2

In this example, we require the semver module and assign a version string '1.2.3' to a variable version. We then call semver.minor() with the version string as an argument, which returns the minor version number 2. Finally, we log the value of minor to the console.