How to use compare-versions - 10 common examples

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 machsix / Super-preloader / src / index.js View on Github external
case "zh_CN":
                opts.text = SCRIPT_INFO["name-CN"] + " 从 v" + myOldVersion + " 升级到 v" + scriptInfo.version + "。";
                opts.text += upgradeNotification.text.zh_CN;
                break;

              default:
                opts.text = SCRIPT_INFO.name + " is upgraded from v" + myOldVersion + " to v" + scriptInfo.version + ". ";
                opts.text += upgradeNotification.text.en_US;
                break;
            }
            GM.notification(opts);
          }
        }
      }

      if (compareVersions(myOldVersion, scriptInfo.version) !== 0) {
        prefs.factoryCheck = true;
        // preSPinit.push(jsonRuleLoader.updateRule(true)); // rule is always updated after upgrade
        preSPinit.push(GM.setValue("version", scriptInfo.version));
        logger.info(`[UpdateCheck] version is updated ${myOldVersion} => ${scriptInfo.version}`);
      }

      let forceJsonUpdate = false;
      if (prefs.factoryCheck === true || prefs.factoryCheck === undefined) {
        const hasDifferent = assignDifferentProperty(prefs, prefsFactory);
        if (hasDifferent) {
          logger.info("[UpdateCheck] prefs is updated", prefs);
        }
        prefs.factoryCheck = false;
        preSPinit.push(GM.setValue("prefs", prefs));
        if (compareVersions(myOldVersion, scriptInfo.rewriteStorage) === -1) {
          preSPinit.push(GM.setValue("SITEINFO_D", SITEINFO_D));
github machsix / Super-preloader / src / index.js View on Github external
if (compareVersions(myOldVersion, scriptInfo.rewriteStorage) === -1) {
        if (_.isString(prefs)) prefs = JSON.parse(prefs);
        if (_.isString(SITEINFO_D)) SITEINFO_D = JSON.parse(SITEINFO_D);
        if (_.isString(autoMatch)) autoMatch = JSON.parse(autoMatch);
      }
      if (typeof prefs.debug !== "undefined") {
        logger.setLevel(prefs.debug ? "debug" : "info");
      }
      let jsonRule = jsonRuleLoader.getRule();

      const preSPinit = [];
      // check the consistency of script settings
      if (compareVersions(myOldVersion, scriptInfo.version) < 0) {
        // update rule if the script is upgraded or it is installed for the first time
        if (upgradeNotification) {
          if (upgradeNotification.show(myOldVersion, scriptInfo.version) || compareVersions(myOldVersion, "1.0.0") === 0) {
            const opts = {
              text: "",
              title: upgradeNotification.title,
              image: upgradeNotification.image,
              onload: upgradeNotification.onload
            };
            switch (i8n()) {
              case "zh_CN":
                opts.text = SCRIPT_INFO["name-CN"] + " 从 v" + myOldVersion + " 升级到 v" + scriptInfo.version + "。";
                opts.text += upgradeNotification.text.zh_CN;
                break;

              default:
                opts.text = SCRIPT_INFO.name + " is upgraded from v" + myOldVersion + " to v" + scriptInfo.version + ". ";
                opts.text += upgradeNotification.text.en_US;
                break;
github machsix / Super-preloader / src / index.js View on Github external
(function() {
  logger.setLevel("debug");
  // use charset from currentDocument
  const gotConfig = {
    html: true,
    encoding: document.characterSet
  };
  logger.debug(`Script Manager: ${SCRIPT_MANAGER.name}  v${SCRIPT_MANAGER.version}`);
  logger.debug("Browser: ", BROWSER);

  if (BROWSER.name === "firefox") {
    if ((SCRIPT_MANAGER.name === "Violentmonkey" && compareVersions(SCRIPT_MANAGER.version, "2.12.3") <= 0) || SCRIPT_MANAGER.name === "Tampermonkey") {
      // `options.cookie`, dirty fix for TM and VM on Firefox
      // TODO: remove when TM releases new version
      logger.warn(`${SCRIPT_MANAGER.name}  v${SCRIPT_MANAGER.version} has a flaw on Firefox, which may affect this script`);
      logger.warn("Check https://github.com/Tampermonkey/tampermonkey/issues/786 and https://github.com/violentmonkey/violentmonkey/issues/606 to learn more");
      gotConfig.cookie = true;
    }
  }

  const got = gotStock.create(gotConfig);
  const scriptInfo = SCRIPT_INFO;
  const upgradeNotification = NOTIFICATION;

  // ----------------------------------
  // all rules
  let SSRules = [];
  // ----------------------------------
github peggyrayzis / react-native-create-bridge / src / file-operations.js View on Github external
export function parseFile(
  fileData,
  { templateName, packageName, app, rnVersion }
) {
  let kotlinPackage;
  let javaPackage;

  // TODO: figure out a better way to handle one off breaking changes
  if (rnVersion && compareVersions(rnVersion, "0.47.2") < 0) {
    kotlinPackage = `
    override fun createJSModules(): List> {
        return emptyList()
    }

    `;

    javaPackage = `
    @Override
    public List> createJSModules() {
        return Collections.emptyList();
    }
    
    `;
  } else {
    kotlinPackage = "";
github NOtherDev / whatwebcando / _new / src / utils / caniuse.js View on Github external
let info = {};

    // workaround for https://github.com/Fyrd/caniuse/issues/1939
    let useSingleVersionWorkaround = Object.keys(browserVersions).length === 1;

    for (let version of Object.keys(browserVersions)) {
      let flag = CaniuseReport.$normalizeSupportFlag(browserVersions[version]);

      // collect total share values
      info[flag] = info[flag] || {min: version, max: version, share: 0};
      info[flag].share += versionsUsage[version] || (useSingleVersionWorkaround && versionsUsage['0']) || 0;

      // find min and max version with given support flag
      if (compareVersions(info[flag].min, version) === 1) {
        info[flag].min = version;
      } else if (compareVersions(info[flag].max, version) === -1) {
        info[flag].max = version;
      }
    }

    return {
      browserKey,
      browserName: BROWSERS[browserKey] || capitalizeFirst(browserKey),
      noSupport: info.n || {},
      partialSupport: info.p || {},
      hasSupport: info.y || {}
    };
  }
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.}`,

compare-versions

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

MIT
Latest version published 4 months ago

Package Health Score

77 / 100
Full package analysis

Popular compare-versions functions