How to use the coerce function from semver

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

360
361
362
363
364
365
366
367
368
369
  qx.tool.config.Lockfile.getInstance().getVersion(),
  true
).raw;
let fileVersion =
  lockfileContent && lockfileContent.version
    ? semver.coerce(lockfileContent.version, true).raw
    : "1.0.0";
if (semver.major(schemaVersion) > semver.major(fileVersion)) {
  if (this.argv.force) {
    let config = {
fork icon255
star icon758
watch icon77

+ 3 other calls in file

69
70
71
72
73
74
75
76
77
78
.filter(instrumentation => instrumentation.name === moduleName)
.forEach(instrumentation => {
  instrumentation.versions
    .filter(version => !process.env.RANGE || semver.subset(version, process.env.RANGE))
    .forEach(version => {
      const min = semver.coerce(version).version
      const max = require(`../../../../versions/${moduleName}@${version}`).version()

      testVersions.set(min, { range: version, test: min })
      testVersions.set(max, { range: version, test: version })
fork icon243
star icon449
watch icon0

217
218
219
220
221
222
223
224
225
226
 * @param {"react-native" | "react-native-macos" | "react-native-windows"} packageName
 * @param {string} targetVersion
 * @returns {Record<string, string> | undefined}
 */
function getPlatformPackage(packageName, targetVersion) {
  const v = semver.coerce(targetVersion);
  if (!v) {
    throw new Error(`Invalid ${packageName} version: ${targetVersion}`);
  }

fork icon55
star icon363
watch icon20

768
769
770
771
772
773
774
775
776
777
versions = Object.values(versions) || [];
try {
	versions = versions.sort((a, b) => {
		let result = 0;
		try {
			const a_ver = semver.coerce(a.version);
			const b_ver = semver.coerce(b.version);
			if (semver.lt(a_ver, b_ver)) {
				result = 1;
			}
fork icon45
star icon74
watch icon14

+ 2 other calls in file

776
777
778
779
780
781
782
783
784
785
	if (!diff.updated) {
		diff.updated = {};
	}
	diff.updated.channel = updated.channel;
}
if (semver.neq(semver.coerce(current.orderer), semver.coerce(updated.orderer))) {
	if (!diff.updated) {
		diff.updated = {};
	}
	diff.updated.orderer = updated.orderer;
fork icon45
star icon72
watch icon14

+ 20 other calls in file

1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
let highest = '';
versions.forEach(version => {
	const revised = version.replace(/_/g, '.');
	if (highest) {
		try {
			if (semver.lt(semver.coerce(highest), semver.coerce(revised))) {
				highest = revised;
			}
		} catch (err) {
			console.error(err);
fork icon45
star icon72
watch icon14

+ 9 other calls in file

914
915
916
917
918
919
920
921
922
923
}

if (updateMessage && updateMessage.updateavailable === true) {
   // Always use a loose parse as Volumio versions aren't properly semver.
   // For example 3.054 isn't valid due to the leading '0'.
   var updateVersion = semver.coerce(updateMessage.title, { loose: true });
   if(updateVersion !== null) {
       var broken = self.commandRouter.pluginManager.listPluginsBrokenByNewVersion(updateVersion.version);
       if(broken.length > 0) {
          updateMessage.description += '<br><p><strong>The following plugins will be broken by this update:</strong></p> ' + broken;
fork icon28
star icon20
watch icon4

+ 3 other calls in file

12
13
14
15
16
17
18
19
20
21
let published = releases.filter( release =>
	! release.draft && ! release.prerelease
);

let sorted = published.sort( ( a, b ) =>
	semver.rcompare( semver.coerce( a.tag_name ), semver.coerce( b.tag_name ) )
);

let changelog = sorted.reduce( ( changelog, release ) =>
	`${changelog}
fork icon2
star icon8
watch icon0

119
120
121
122
123
124
125
126
127
128
    reject("Error!! Package.json File does not have correct json");
  }
}

//validate if cypress config file is passed and exists
cypress_version = semver.coerce(cypress_version).version;
// validate cypress.json only in case of cypress<10
if (
  semverCompare(cypress_version, "10.0.0") == -1 &&
  lt_config["run_settings"]["cypress_config_file"]
fork icon17
star icon4
watch icon7

129
130
131
132
133
134
135
136
137
138

// if peregrine is on version 3.2.0/2023.04 or newer, or on a branch, use
// the peregrine endpoint. if not, use the deprecated pidgin endpoint
const minSemVer = '3.2.0';
// We need two dots here to achieve proper comparison later with other monthly versions
const minMonthlyRelease = semver.coerce('2023.04.0', { loose: true });
const monthlyReleaseCutoff = semver.coerce('2020', { loose: true });

const url = await I.sendGetRequest(peregrineProps.endpoints.version)
.then((response) => {
fork icon2
star icon4
watch icon26

+ 2 other calls in file

94
95
96
97
98
99
100
101
102
103

for (const product of products) {
    if (!Array.isArray(packageMap[product.name])) continue;

    for (const package of packageMap[product.name]) {
        const coercedVersion = semver.coerce(package.version, { loose: true })?.version;
        const satisfies = semver.satisfies(coercedVersion, product.version, { loose: true });
        if (!satisfies) continue;

        if (ecosystems && !ecosystems.includes(package.ecosystem)) continue;
fork icon6
star icon0
watch icon1

444
445
446
447
448
449
450
451
452
453
    packageInfo,
    templateInfo,
  }))
)
.then(({ isOnline, packageInfo, templateInfo }) => {
  let packageVersion = semver.coerce(packageInfo.version);

  const templatesVersionMinimum = '3.3.0';

  // Assume compatibility if we can't test the version.
fork icon1
star icon0
watch icon2

+ 2 other calls in file

55
56
57
58
59
60
61
62
63
64
    const curVersion = get(tapPackage, [depKey, repoName])
    if(!curVersion) return

    semver.neq(
      semver.coerce(cleanVersion(curVersion)),
      semver.coerce(cleanVersion(repoVersion))
    ) && (versionsDiff[repoName] = { current: curVersion, repo: repoVersion } )
  
  })
})
fork icon1
star icon0
watch icon0

+ 3 other calls in file

101
102
103
104
105
106
107
108
109
110
if (pageVersion !== 'enterprise-server' || existingVersionRangeIsAll) continue

const rangeOfVersionToAddIsAll = page.versions[pageVersion] === '*'
// see if the version to add is a superset of the existing version
const existingVersionIsSubsetOfNewVersion = semver.lt(
  semver.coerce(page.versions[pageVersion].replace('*', 0)),
  semver.coerce(imageVersions[pageVersion].replace('*', 0))
)

// only update the version range if the existing range is not '*' or
fork icon0
star icon2
watch icon0

+ 3 other calls in file

333
334
335
336
337
338
339
340
341
342
if (argv.variant) {
  envars.VARIANT = true;
}

if (argv.reactVersion) {
  envars.REACT_VERSION = semver.coerce(argv.reactVersion);
}

if (argv.sourceMaps) {
  // This is off by default because it slows down the test runner, but it's
fork icon0
star icon1
watch icon1

232
233
234
235
236
237
238
239
240
241
242
243
}


function createApp(name, verbose, version, template, useYarn, usePnp) {
  const unsupportedNodeVersion = !semver.satisfies(
    // Coerce strings with metadata (i.e. `15.0.0-nightly`).
    semver.coerce(process.version),
    '>=14'
  );


  if (unsupportedNodeVersion) {
fork icon0
star icon0
watch icon1

+ 45 other calls in file

88
89
90
91
92
93
94
95
96
97
  error('Warning: React version not specified in eslint-plugin-react settings. '
    + 'See https://github.com/jsx-eslint/eslint-plugin-react#configuration .');
  warnedForMissingVersion = true;
}
confVer = /^[0-9]+\.[0-9]+$/.test(confVer) ? `${confVer}.0` : confVer;
const result = semver.coerce(confVer.split('.').map((part) => Number(part)).join('.'));
if (!result) {
  error(`Warning: React version specified in eslint-plugin-react-settings must be a valid semver version, or "detect"; got “${confVer}”`);
}
return result ? result.version : defaultVersion;
fork icon0
star icon0
watch icon1

+ 3 other calls in file

147
148
149
150
151
152
153
154
155
156
}
const coercedActualKibanaVersion = semver_1.coerce(actualKibanaVersion);
if (coercedActualKibanaVersion == null) {
    return false;
}
const coercedExpectedKibanaVersion = semver_1.coerce(expectedKibanaVersion);
if (coercedExpectedKibanaVersion == null) {
    return false;
}
// Compare coerced versions, e.g. `1.2.3` ---> `1.2.3` and `7.0.0-alpha1` ---> `7.0.0`.
fork icon0
star icon0
watch icon0

+ 7 other calls in file

18
19
20
21
22
23
24
25
26
27
if (!dependencies[pkg.name]) {
  return null
}

const manifestPath = resolveFrom.silent(workDir, path.join(pkg.name, 'package.json'))
const installed = semver.coerce(
  manifestPath ? readPackageJson(manifestPath).version : dependencies[pkg].replace(/[\D.]/g, '')
)

const supported = pkg.supported.join(' || ')
fork icon0
star icon0
watch icon0

+ 2 other calls in file