How to use the compare-versions.compare function in compare-versions

To help you get started, we’ve selected a few compare-versions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 10up / distributor / assets / js / admin-external-connection.js View on Github external
&& Object.prototype.hasOwnProperty.call( response.data, 'rest_url' )
				&& ! Object.prototype.hasOwnProperty.call( response.data, 'version' )
			) {
				jQuery( wizardError[0] ).text( dt.no_distributor );
			} else {
				jQuery( wizardError[0] ).text( dt.noconnection );
			}

			return;
		}

		// Remove -dev from the version number, if running from the develop branch
		const version = response.data.version.replace( /-dev/, '' );

		// Requires Distributor version 1.6.0.
		if ( compareVersions.compare( version, '1.6.0', '<' ) ) {
			jQuery( wizardError[0] ).text( dt.minversion );
			return;
		}

		const successURL = addQueryArgs( document.location.href,
			{
				setupStatus: 'success',
				titleField: titleField.value,
				externalSiteUrlField: siteURL,
				restRoot: response.data.rest_url,
			}
		);

		const failureURL = addQueryArgs( document.location.href,
			{
				setupStatus: 'failure'
github 0xProject / 0x-monorepo / packages / website / scripts / algolia_helpers.ts View on Github external
const dirPath = path.join(__dirname, `../mdx/${dirName}`);
    const paths = glob.sync(`${dirPath}/**/*.mdx`);
    const nameToFile: ObjectMap = {};

    for (const p of paths) {
        if (dirName === 'tools') {
            const name = path.basename(path.join(p, '../../'));
            const version = path.basename(path.dirname(p));
            const url = `/docs/tools/${name}/${version}`;

            const fileIfExists = nameToFile[name];

            const fileObject = { name, path: p, version, versions: [version], url };

            if (fileIfExists !== undefined) {
                if (compareVersions.compare(version, fileIfExists.version, '>')) {
                    const versions = [...fileIfExists.versions, version]; // Add current version to versions array
                    nameToFile[name] = { ...fileObject, versions };
                }
            } else {
                nameToFile[name] = fileObject;
            }
        }

        if (dirName === 'guides') {
            const { name } = path.parse(p);
            const url = `/docs/guides/${name}`;
            nameToFile[name] = { name, path: p, url };
        }

        if (dirName === 'core-concepts' || dirName === 'api-explorer') {
            const url = `/docs/${dirName}`;
github nlemoine / acf-country / assets / js / acf-country.js View on Github external
acf.addFilter('select2_args', function (
		args,
		$select,
		settings,
		field,
		instance
	) {
		if (instance.data.field.get('type') !== 'country') {
			return args;
		}

		var templates = {};
		if (compareVersions.compare(acf.get('acf_version'), '5.8.12', '>=')) {
			templates = {
				templateResult: format_country_esc,
				templateSelection: format_country_esc,
			};
		} else {
			templates = {
				templateResult: format_country,
				templateSelection: format_country,
			};
		}

		// Select2 version
		$.extend(args, templates);
		return args;
	});
})(jQuery);
github mdn / browser-compat-data / test / linter / test-consistency.js View on Github external
isVersionAddedGreater(a, b) {
    var a_version_added = this.getVersionAdded(a);
    var b_version_added = this.getVersionAdded(b);

    if (
      typeof a_version_added === 'string' &&
      typeof b_version_added === 'string'
    ) {
      if (a_version_added.startsWith('≤') || b_version_added.startsWith('≤')) {
        return false;
      }
      return compareVersions.compare(a_version_added, b_version_added, '<');
    }

    return false;
  }
github mdn / browser-compat-data / test / linter / test-versions.js View on Github external
hasErrors = true;
          } else if (
            typeof statement.version_added === 'string' &&
            typeof statement.version_removed === 'string'
          ) {
            if (
              (statement.version_added.startsWith('≤') &&
                statement.version_removed.startsWith('≤') &&
                compareVersions.compare(
                  statement.version_added.replace('≤', ''),
                  statement.version_removed.replace('≤', ''),
                  '<',
                )) ||
              ((!statement.version_added.startsWith('≤') ||
                !statement.version_removed.startsWith('≤')) &&
                compareVersions.compare(
                  statement.version_added.replace('≤', ''),
                  statement.version_removed.replace('≤', ''),
                  '>=',
                ))
            ) {
              logger.error(
                chalk`{red → {bold ${relPath}} - {bold version_removed: "${statement.version_removed}"} must be greater than {bold version_added: "${statement.version_added}"}}`,
              );
              hasErrors = true;
            }
          }
        }
        if ('flags' in statement) {
          if (FLAGLESS_BROWSERS.includes(browser)) {
            logger.error(
              chalk`{red → {bold ${relPath}} - This browser ({bold ${browser}}) does not support flags, so support cannot be behind a flag for this feature.}`,
github rule110-io / surge / frontend / src / store / modules / version.js View on Github external
async updateRemoteVersion({ commit }) {
    const data = await axios(
      "https://api.github.com/repos/rule110-io/surge/releases"
    );

    const currentVersion = this.state.version.currentVersion;

    const releases = data.data;

    const remoteVersion = releases ? releases[0].tag_name : currentVersion;
    const isNewVersion = compareVersions.compare(
      remoteVersion,
      currentVersion,
      ">"
    );

    commit("setRemoteVersion", remoteVersion);
    commit("setIsNewVersion", isNewVersion);
  },
};
github ShipChain / engine / src / vaults / Vault.ts View on Github external
async loadMetadata() {
        let metaContent: object = {};
        try {
            const data = await this.getFile(Vault.METADATA_FILE_NAME);
            this.meta = await JSON.parse(data);

            if (compareVersions.compare(this.meta.version, Vault.CURRENT_VAULT_VERSION, '>')) {
                throw new Error(
                    `Vault version is not supported by this Engine.` +
                        `[${this.meta.version}] > [${Vault.CURRENT_VAULT_VERSION}]`,
                );
            }

            this.containers = {};
            for (const name in this.meta.containers) {
                this.containers[name] = await this.getContainerContent(this.meta.containers[name], name);
                metaContent[name] = this.containers[name].meta;
            }

            this.meta.containers = metaContent;
            return this.meta;
        } catch (_err) {
            if (_err instanceof DriverError) {
github dreamnettech / dreamtime / src / electron / src / modules / tools / system.js View on Github external
async _hasCompatiblePower() {
    if (!this.requirements.power.installed) {
      return false
    }

    try {
      const version = await getVersion()

      const minimum = get(nucleus, `projects.dreamtime.releases.v${process.env.npm_package_version}.dreampower.minimum`, 'v1.2.3')
      const maximum = get(nucleus, `projects.dreamtime.releases.v${process.env.npm_package_version}.dreampower.maximum`)

      if (compareVersions.compare(version, minimum, '<')) {
        return false
      }

      if (!isNil(maximum) && compareVersions.compare(version, maximum, '>')) {
        return false
      }

      return true
    } catch (err) {
      logger.warn('An error occurred while verifying the version of DreamPower.', err)
      return false
    }
  }

compare-versions

Compare semver version strings to find greater, equal or lesser.

MIT
Latest version published 9 months ago

Package Health Score

77 / 100
Full package analysis

Popular compare-versions functions