/** * Semantic version parsing, validation, comparison, and increment helpers. * * @packageDocumentation */ import type { SchemeRules, SemVer, SemVerConfig, ValidationResult } from './types'; /** * Parses a semantic version string. * * @remarks * This helper enforces the standard SemVer structure and returns `null` when the input does not * match. It preserves prerelease and build identifiers as ordered string segments. * * @param version - Version string to parse. * @returns Parsed semantic version components, or `null` when the input is invalid. * * @example * ```ts * import { parse } from 'versionguard'; * * parse('1.2.3-alpha.1+build.5')?.prerelease; * // => ['alpha', '1'] * ``` * * @public * @since 0.1.0 */ export declare function parse(version: string): SemVer | null; /** * Validates that a string is a supported semantic version. * * @remarks * When validation fails, the result includes targeted structural errors for common cases such as * leading `v` prefixes and numeric segments with leading zeroes. * * When a {@link SemVerConfig} is provided, additional policy checks are applied * (v-prefix tolerance, build-metadata restrictions, prerelease requirements). * When {@link SchemeRules} are provided, the prerelease tag is validated against * the allowed modifiers list — the same logic CalVer uses for its modifiers. * * @param version - Version string to validate. * @param semverConfig - Optional SemVer-specific configuration. * @param schemeRules - Optional scheme rules for modifier validation. * @returns A validation result containing any detected errors and the parsed version on success. * * @example * ```ts * import { validate } from 'versionguard'; * * validate('1.2.3').valid; * // => true * ``` * * @public * @since 0.1.0 */ export declare function validate(version: string, semverConfig?: SemVerConfig, schemeRules?: SchemeRules): ValidationResult; /** * Compares two semantic version strings. * * @remarks * Comparison follows SemVer precedence rules, including special handling for prerelease * identifiers and ignoring build metadata. * * @param a - Left-hand version string. * @param b - Right-hand version string. * @returns `1` when `a` is greater, `-1` when `b` is greater, or `0` when they are equal. * * @example * ```ts * import { compare } from 'versionguard'; * * compare('1.2.3', '1.2.3-alpha.1'); * // => 1 * ``` * * @public * @since 0.1.0 */ export declare function compare(a: string, b: string): number; /** * Checks whether one semantic version is greater than another. * * @remarks * This is a convenience wrapper around {@link compare} for callers that only need a boolean. * * @param a - Left-hand version string. * @param b - Right-hand version string. * @returns `true` when `a` has higher precedence than `b`. * * @example * ```ts * import { gt } from 'versionguard'; * * gt('1.2.4', '1.2.3'); * // => true * ``` * * @see {@link compare} for full precedence ordering. * @public * @since 0.1.0 */ export declare function gt(a: string, b: string): boolean; /** * Checks whether one semantic version is less than another. * * @remarks * This is a convenience wrapper around {@link compare} for callers that only need a boolean. * * @param a - Left-hand version string. * @param b - Right-hand version string. * @returns `true` when `a` has lower precedence than `b`. * * @example * ```ts * import { lt } from 'versionguard'; * * lt('1.2.3-alpha.1', '1.2.3'); * // => true * ``` * * @see {@link compare} for full precedence ordering. * @public * @since 0.1.0 */ export declare function lt(a: string, b: string): boolean; /** * Checks whether two semantic versions are equal in precedence. * * @remarks * This is a convenience wrapper around {@link compare}. Build metadata is ignored because * precedence comparisons in SemVer do not consider it. * * @param a - Left-hand version string. * @param b - Right-hand version string. * @returns `true` when both versions compare as equal. * * @example * ```ts * import { eq } from 'versionguard'; * * eq('1.2.3', '1.2.3'); * // => true * ``` * * @see {@link compare} for full precedence ordering. * @public * @since 0.1.0 */ export declare function eq(a: string, b: string): boolean; /** * Increments a semantic version string by release type. * * @remarks * Incrementing `major` or `minor` resets lower-order numeric segments. When a prerelease label is * provided, it is appended to the newly generated version. * * @param version - Current semantic version string. * @param release - Segment to increment. * @param prerelease - Optional prerelease suffix to append to the next version. * @returns The incremented semantic version string. * * @example * ```ts * import { increment } from 'versionguard'; * * increment('1.2.3', 'minor', 'beta.1'); * // => '1.3.0-beta.1' * ``` * * @public * @since 0.1.0 */ export declare function increment(version: string, release: 'major' | 'minor' | 'patch', prerelease?: string): string; /** * Formats a parsed semantic version object. * * @remarks * Prerelease and build metadata segments are only included when their arrays contain values. * * @param version - Parsed semantic version to serialize. * @returns The normalized semantic version string. * * @example * ```ts * import { format } from 'versionguard'; * * const version = { major: 1, minor: 2, patch: 3, prerelease: ['rc', '1'], build: ['build', '5'], raw: '1.2.3-rc.1+build.5' }; * * format(version); * // => '1.2.3-rc.1+build.5' * ``` * * @public * @since 0.1.0 */ export declare function format(version: SemVer): string; //# sourceMappingURL=semver.d.ts.map