UNPKG

balena-semver

Version:
220 lines (219 loc) 8.53 kB
import * as semver from 'semver'; type VersionInput = string | null | undefined; type Release = 'premajor' | 'preminor' | 'prepatch' | 'prerelease' | 'major' | 'minor' | 'patch'; /** * @summary Compare order of versions * @name compare * @public * @function * * @description Accepts string or null values and compares them, returning a number * indicating sort order. Values are parsed for valid semver strings. Sorts an array * of versions in ascending order if passed to `Array.sort()`. * * * @param {string|null|undefined} versionA - The first version to compare * @param {string|null|undefined} versionB - The second version to compare * * @returns {number} Returns `0` if `versionA == versionB`, * or `1` if `versionA` is greater, or `-1` if `versionB` is greater. * Null values are sorted before invalid semver values, and invalid semver values * are sorted before valid semver values * If both values are invalid semver values, then the values are compared alphabetically. */ export declare const compare: ((versionA: VersionInput, versionB: VersionInput) => number) & import("lodash").MemoizedFunction; /** * @summary Compare order of versions in reverse * @name rcompare * @public * @function * * @description The reverse of `.compare()`. Accepts string or null values and compares * them, returning a number indicating sort order. Values are parsed for valid semver * strings. Sorts an array of versions in descending order when passed to `Array.sort()`. * * @param {string|null|undefined} versionA - The first version to compare * @param {string|null|undefined} versionB - The second version to compare * * @returns {number} Returns `0` if `versionA == versionB`, * or `-1` if `versionA` is greater, or `1` if `versionB` is greater. * Valid semver values are sorted before invalid semver values, and invalid semver values are * sorted before null values. * If both values are non-null invalid semver values, then the values are compared alphabetically. */ export declare const rcompare: (versionA: VersionInput, versionB: VersionInput) => number; /** * @summary Return the major version number * @name major * @public * @function * * @description Returns the major version number in a semver string. * If the version is not a valid semver string, or a valid semver string cannot be * found, it returns null. * * @param {string|null|undefine} version - The version string to evaluate * * @returns {number|null} - The major version number */ export declare const major: (version: VersionInput) => number | null; /** * @summary Return prerelease components * @name prerelease * @public * @function * * @description Returns an array of prerelease components, or null if none exist * * @param {string|null|undefined} version - The version string to evaluate * * @returns {Array.<string|number>|null} - An array of prerelease component, or null if none exist */ export declare const prerelease: (version: VersionInput) => readonly (string | number)[] | null; /** * @summary Check if a version is greater than or equal to another * @name gte * @public * @function * * @description Returns true if versionA is greater than or equal to versionB. * Valid semver versions are always weighted above non semver strings. * Non-semver strings are compared alphabetically. * * @param {string|null|undefined} versionA - The version string to compare against * @param {string|null|undefined} versionB - The version string to compare to versionA * * @returns {boolean} - true if versionA is greater than or equal to versionB, otherwise false. */ export declare const gte: (versionA: VersionInput, versionB: VersionInput) => boolean; /** * @summary Check if a version is greater than another * @name gt * @public * @function * * @description Returns true if versionA is greater than versionB. * Valid semver versions are always weighted above non semver strings. * Non-semver strings are compared alphabetically. * * @param {string|null|undefined} versionA - The version string to compare against * @param {string|null|undefined} versionB - The version string to compare to versionA * * * @returns {boolean} - true if versionA is greater than versionB, otherwise false. */ export declare const gt: (versionA: VersionInput, versionB: VersionInput) => boolean; /** * @summary Check if a version is less than or equal to another * @name lte * @public * @function * * @description Returns true if versionA is less than or equal to versionB. * Valid semver versions are always weighted above non semver strings. * Non-semver strings are compared alphabetically. * * @param {string|null|undefined} versionA - The version string to compare against * @param {string|null|undefined} versionB - The version string to compare to versionA * * @returns {boolean} - true if versionA is greater than or equal to versionB, otherwise false. */ export declare const lte: (versionA: VersionInput, versionB: VersionInput) => boolean; /** * @summary Check if a version is less than another * @name lt * @public * @function * * @description Returns true if versionA is less than versionB. * Valid semver versions are always weighted above non semver strings. * Non-semver strings are compared alphabetically. * * @param {string|null|undefined} versionA - The version string to compare against * @param {string|null|undefined} versionB - The version string to compare to versionA * * @returns {boolean} - true if versionA is less than versionB, otherwise false. */ export declare const lt: (versionA: VersionInput, versionB: VersionInput) => boolean; /** * @summary Check if a version satisfies a range * @name satisfies * @public * @function * * @description Return true if the parsed version satisfies the range. * This method will always return false if the provided version doesn't contain a valid semver string. * * @param {string|null|undefined} version - The version to evaluate * @param {string} range - A semver range string, see the [node-semver](https://github.com/npm/node-semver#ranges) * docs for details * * @returns {boolean} - True if the parsed version satisfies the range, false otherwise * */ export declare const satisfies: (version: VersionInput, range: string) => boolean; /** * @summary Return the highest version in the list that satisfies the range * @name maxSatisfying * @public * @function * * @description Return the highest version in the list that satisfies the range, or null if none of them do. * If multiple versions are found that have equally high values, the last one in the array is returned. * Note that only version that contain a valid semver string can satisfy a range. * * @param {Array.<string|null|undefined>} versions - An array of versions to evaluate * @param {string} range - A semver range string, see the [node-semver](https://github.com/npm/node-semver#ranges) * docs for details * * @returns {string|null} - The highest matching version string, or null. * */ export declare const maxSatisfying: (versions: VersionInput[], range: string) => null; /** * @summary Parse a version into an object * @name parse * @public * @function * * @description Returns an object representing the semver version. Returns null * if a valid semver string can't be found. * * @param {string|null|undefined} version * * @returns {SemverObject|null} - An object representing the version string, or * null if a valid semver string could not be found */ export declare const parse: (version: VersionInput) => semver.SemVer | null; /** * @summary Check if a version string is valid * @name valid * @public * @function * * @description Return the parsed version, or null if it's not valid. * * @param {string|null|undefined} version * * @returns {string|null} - The parsed version string, or * null if a valid semver string could not be found */ export declare const valid: (version: VersionInput) => string | null; /** * @summary Return an incremented version * @name inc * @public * @function * * @description Return the version incremented by the release type * (major, premajor, minor, preminor, patch, prepatch, or prerelease), or null * if it's not valid. * * @param {string|null|undefined} version * @param {string} release * * @returns {string|null} - The incremented version string, or * null if a valid semver string could not be found */ export declare const inc: (version: VersionInput, release: Release) => string | null; export {};