From ab09d447596acfff24fcb7aaffa184b54257e26d Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Tue, 7 Apr 2026 16:29:20 +0000 Subject: [PATCH] feat(smartversion): add equality comparison methods for SmartVersion instances and version strings --- changelog.md | 7 +++++++ test/test.node+chromium.ts | 10 ++++++++++ ts/00_commitinfo_data.ts | 2 +- ts/index.ts | 11 +++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index 4f8956c..f766f34 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2026-04-07 - 3.1.0 - feat(smartversion) +add equality comparison methods for SmartVersion instances and version strings + +- Adds equals() to compare two SmartVersion instances +- Adds equalsString() to compare a SmartVersion against a version string +- Covers equality behavior with node+chromium tests + ## 2026-04-07 - 3.0.6 - fix(tooling) migrate project config and test tooling while hardening fuzzy version parsing diff --git a/test/test.node+chromium.ts b/test/test.node+chromium.ts index fc86415..351c658 100644 --- a/test/test.node+chromium.ts +++ b/test/test.node+chromium.ts @@ -33,4 +33,14 @@ tap.test('should create a patch version', async () => { console.log(newVersion.versionString); }) +tap.test('should compare versions for equality', async () => { + const v1 = new smartversion.SmartVersion('1.2.3'); + const v2 = new smartversion.SmartVersion('1.2.3'); + const v3 = new smartversion.SmartVersion('1.2.4'); + expect(v1.equals(v2)).toBeTrue(); + expect(v1.equals(v3)).toBeFalse(); + expect(v1.equalsString('1.2.3')).toBeTrue(); + expect(v1.equalsString('1.2.4')).toBeFalse(); +}); + export default tap.start(); diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 0e946c4..0b9c43c 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartversion', - version: '3.0.6', + version: '3.1.0', description: 'A library to handle semantic versioning with ease.' } diff --git a/ts/index.ts b/ts/index.ts index 54b493e..dd599db 100644 --- a/ts/index.ts +++ b/ts/index.ts @@ -54,6 +54,17 @@ export class SmartVersion { return plugins.semver.lt(this.versionString, versionStringArg); } + public equals(smartVersionArg: SmartVersion) { + return this.equalsString(smartVersionArg.versionString); + } + + /** + * compares the version of this against a string for equality + */ + public equalsString(versionStringArg: string) { + return plugins.semver.eq(this.versionString, versionStringArg); + } + /** * tries to get the best match from a range of available versions */