diff --git a/__snapshots__/tsnapi/index.snapshot.d.ts b/__snapshots__/tsnapi/index.snapshot.d.ts index 5b657e3..2086e90 100644 --- a/__snapshots__/tsnapi/index.snapshot.d.ts +++ b/__snapshots__/tsnapi/index.snapshot.d.ts @@ -89,6 +89,7 @@ export declare function isOutsideRange(_: VersionInput, _: RangeInput, _: RangeD export declare function isPrerelease(_: VersionInput, _?: VersionOptions): boolean | null; export declare function isRangeSubset(_: string, _: string, _?: RangeOptions): boolean; export declare function isRangeSubset(_: RangeInput, _: RangeInput): boolean; +export declare function isStable(_: VersionInput, _?: VersionOptions): boolean | null; export declare function isValid(_: VersionInput, _?: VersionOptions): boolean; export declare function isValidRange(_: string, _?: RangeOptions): boolean; export declare function isValidRange(_: RangeInput): boolean; diff --git a/__snapshots__/tsnapi/index.snapshot.js b/__snapshots__/tsnapi/index.snapshot.js index b8dab83..1d9042a 100644 --- a/__snapshots__/tsnapi/index.snapshot.js +++ b/__snapshots__/tsnapi/index.snapshot.js @@ -34,6 +34,7 @@ export function isNotEqual(_, _, _) {} export function isOutsideRange(_, _, _, _) {} export function isPrerelease(_, _) {} export function isRangeSubset(_, _, _) {} +export function isStable(_, _) {} export function isValid(_, _) {} export function isValidRange(_, _) {} export function normalize(_, _) {} diff --git a/src/index.ts b/src/index.ts index 8e9d013..f4c7b93 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,6 +56,7 @@ export { getPrerelease, increment, isPrerelease, + isStable, isValid, normalize, normalizeFull, diff --git a/src/version.ts b/src/version.ts index 76df825..6363567 100644 --- a/src/version.ts +++ b/src/version.ts @@ -38,6 +38,15 @@ export function isPrerelease( return !!parsed.prerelease?.length } +export function isStable( + version: VersionInput, + options: VersionOptions = {}, +): boolean | null { + const parsed = tryParse(version, options) + if (!parsed) return null + return !parsed.prerelease?.length +} + export function normalizeFull( version: VersionInput, options: VersionOptions = {}, diff --git a/tests/version.test.ts b/tests/version.test.ts index 6f39777..bd21aac 100644 --- a/tests/version.test.ts +++ b/tests/version.test.ts @@ -11,6 +11,7 @@ import { getPrerelease, increment, isPrerelease, + isStable, isValid, normalize, normalizeFull, @@ -111,6 +112,7 @@ describe('version parsing and accessors', () => { expect(isValid(version)).toBe(true) expect(isPrerelease(version)).toBe(true) + expect(isStable(version)).toBe(false) expect(normalizeFull(version)).toBe('1.2.4-beta.1+next') expect(normalize(version)).toBe('1.2.4-beta.1') expect(clean(version)).toBe('1.2.4-beta.1') @@ -136,6 +138,7 @@ describe('version parsing and accessors', () => { expect(getPrerelease(version)).toEqual([]) expect(getBuild(version)).toEqual([]) expect(isPrerelease(version)).toBe(false) + expect(isStable(version)).toBe(true) }) it('accepts every valid node-semver fixture', () => { @@ -146,6 +149,7 @@ describe('version parsing and accessors', () => { expect(isValid(version)).toBe(true) expect(isPrerelease(version)).toBe(prerelease.length > 0) + expect(isStable(version)).toBe(prerelease.length === 0) expect(normalizeFull(version)).toBe(full) expect(normalize(version)).toBe(comparable) expect(getMajor(version)).toBe(major) @@ -163,6 +167,7 @@ describe('version parsing and accessors', () => { const options = versionOptions(rawOptions) expect(isValid(version, options)).toBe(false) expect(isPrerelease(version, options)).toBeNull() + expect(isStable(version, options)).toBeNull() expect(normalizeFull(version, options)).toBeNull() expect(normalize(version, options)).toBeNull() }