/** * Semantic Version * * A version number in the format MAJOR.MINOR.PATCH with optional * prerelease and build metadata. * * @see https://semver.org/ */ interface SemVer { /** Major version - incremented for breaking changes */ readonly major: number; /** Minor version - incremented for new features */ readonly minor: number; /** Patch version - incremented for bug fixes */ readonly patch: number; /** Prerelease identifiers (e.g., ["alpha", "1"]) */ readonly prerelease: readonly string[]; /** Build metadata identifiers (e.g., ["build", "123"]) */ readonly build: readonly string[]; /** Original raw string if parsed */ readonly raw?: string; } /** * Bump type for version increments. */ type BumpType = 'major' | 'minor' | 'patch' | 'premajor' | 'preminor' | 'prepatch' | 'prerelease' | 'none'; /** Required version number components for creating a SemVer. */ interface RequiredVersionComponents { /** Major version number. */ major: number; /** Minor version number. */ minor: number; /** Patch version number. */ patch: number; } /** * Creates a new SemVer object. * * @param options - Version components * @returns A new SemVer object * * @example Create a SemVer object from components * ```typescript * createSemVer({ major: 1, minor: 2, patch: 3 }) * // => { major: 1, minor: 2, patch: 3, prerelease: [], build: [] } * createSemVer({ major: 1, minor: 0, patch: 0, prerelease: ['beta', '1'] }) * // => 1.0.0-beta.1 * ``` */ declare function createSemVer(options: Partial & RequiredVersionComponents): SemVer; /** * Creates a SemVer representing version 0.0.0. * * @returns A SemVer at version 0.0.0 * * @example Create initial 0.0.0 version * ```typescript * const initial = createInitialVersion() * format(initial) // => '0.0.0' * ``` */ declare function createInitialVersion(): SemVer; /** * Creates a SemVer representing version 1.0.0. * * @returns A SemVer at version 1.0.0 * * @example Create first 1.0.0 release version * ```typescript * const first = createFirstRelease() * format(first) // => '1.0.0' * ``` */ declare function createFirstRelease(): SemVer; /** * Checks if the version has prerelease identifiers. * * @param version - The version to check * @returns True if version has prerelease identifiers * * @example Check if version has prerelease identifiers * ```typescript * isPrerelease(parseVersionStrict('1.0.0-beta.1')) // => true * isPrerelease(parseVersionStrict('1.0.0')) // => false * ``` */ declare function isPrerelease(version: SemVer): boolean; /** * Checks if the version is a stable release (>= 1.0.0 with no prerelease). * * @param version - The version to check * @returns True if version is stable * * @example Check if version is a stable release * ```typescript * isStable(parseVersionStrict('1.0.0')) // => true * isStable(parseVersionStrict('0.9.0')) // => false (< 1.0.0) * isStable(parseVersionStrict('1.0.0-beta')) // => false (prerelease) * ``` */ declare function isStable(version: SemVer): boolean; /** * Returns a new version with build metadata stripped. * * @param version - The version to strip * @returns A new SemVer without build metadata * * @example Strip build metadata from version * ```typescript * const v = parseVersionStrict('1.0.0+build.123') * format(stripBuild(v)) // => '1.0.0' * ``` */ declare function stripBuild(version: SemVer): SemVer; /** * Returns a new version with prerelease identifiers stripped. * * @param version - The version to strip * @returns A new SemVer without prerelease identifiers * * @example Strip prerelease identifiers from version * ```typescript * const v = parseVersionStrict('1.0.0-beta.1') * format(stripPrerelease(v)) // => '1.0.0' * ``` */ declare function stripPrerelease(version: SemVer): SemVer; /** * Comparison operator for version ranges. */ type RangeOperator = '=' | '>' | '>=' | '<' | '<=' | '^' | '~'; /** * A single comparator in a range set. * * Examples: * - >=1.2.3 -> { operator: '>=', version: { major: 1, minor: 2, patch: 3 } } * - ^1.2.0 -> { operator: '^', version: { major: 1, minor: 2, patch: 0 } } */ interface Comparator { /** The comparison operator */ readonly operator: RangeOperator; /** The version to compare against */ readonly version: SemVer; } /** * A set of comparators that must all be satisfied. * Represents the space-separated part of a range (AND logic). * * Example: ">=1.0.0 <2.0.0" -> two comparators in one set */ interface ComparatorSet { /** Array of comparators that must all be satisfied (AND logic). */ readonly comparators: readonly Comparator[]; } /** * A version range that can contain multiple comparator sets. * Represents the || separated parts (OR logic). * * Example: "^1.0.0 || ^2.0.0" -> two comparator sets */ interface Range { /** Comparator sets (OR logic between sets, AND logic within) */ readonly sets: readonly ComparatorSet[]; /** Original raw string if parsed */ readonly raw?: string; } /** * Creates a new Comparator. * * @param operator - The comparison operator * @param version - The version to compare against * @returns A new Comparator * * @example Create a comparator for version comparison * ```typescript * createComparator('>=', parseVersionStrict('1.0.0')) * // => { operator: '>=', version: { major: 1, minor: 0, patch: 0, ... } } * ``` */ declare function createComparator(operator: RangeOperator, version: SemVer): Comparator; /** * Creates a new ComparatorSet. * * @param comparators - Array of comparators (AND logic) * @returns A new ComparatorSet * * @example Create a comparator set with AND logic * ```typescript * createComparatorSet([gte100, lt200]) // AND: >=1.0.0 AND <2.0.0 * ``` */ declare function createComparatorSet(comparators: readonly Comparator[]): ComparatorSet; /** * Creates a new Range. * * @param sets - Array of comparator sets (OR logic) * @param raw - Original raw string * @returns A new Range * * @example Create a range with OR logic between sets * ```typescript * createRange([set1, set2], '>=1.0.0 || >=2.0.0 <3.0.0') * ``` */ declare function createRange(sets: readonly ComparatorSet[], raw?: string): Range; /** * Creates a range that matches any version. * * @returns A Range matching any version (*) * * @example Create a range that matches any version * ```typescript * const anyRange = createAnyRange() * satisfies(parseVersionStrict('999.999.999'), anyRange) // => true * ``` */ declare function createAnyRange(): Range; /** * Creates a range that matches exactly one version. * * @param version - The exact version to match * @returns A Range matching exactly the specified version * * @example Create a range that matches exactly one version * ```typescript * const exact = createExactRange(parseVersionStrict('1.2.3')) * satisfies(parseVersionStrict('1.2.3'), exact) // => true * satisfies(parseVersionStrict('1.2.4'), exact) // => false * ``` */ declare function createExactRange(version: SemVer): Range; /** * Checks if a range represents a wildcard/any match. * * @param range - The range to check * @returns True if the range matches any version * * @example Check if a range represents a wildcard * ```typescript * isWildcard(parseRangeStrict('*')) // => true * isWildcard(parseRangeStrict('^1.0.0')) // => false * ``` */ declare function isWildcard(range: Range): boolean; export { createAnyRange, createComparator, createComparatorSet, createExactRange, createFirstRelease, createInitialVersion, createRange, createSemVer, isPrerelease, isStable, isWildcard, stripBuild, stripPrerelease }; export type { BumpType, Comparator, ComparatorSet, Range, RangeOperator, SemVer };