diff options
author | Florian Dold <florian@dold.me> | 2021-11-23 23:51:12 +0100 |
---|---|---|
committer | Florian Dold <florian@dold.me> | 2021-11-23 23:51:12 +0100 |
commit | ae8af3f27c0ed1746c49a7608fe05af24ae8a18b (patch) | |
tree | c28f588071bdd1d4cda2279e62563a3664d79be9 /packages/taler-util/src/libtool-version.ts | |
parent | 829a59e1a24d6a99ce7554d28acfd05f21baeaf8 (diff) | |
download | wallet-core-ae8af3f27c0ed1746c49a7608fe05af24ae8a18b.tar.xz |
wallet: tipping protocol change / merchant version info
Diffstat (limited to 'packages/taler-util/src/libtool-version.ts')
-rw-r--r-- | packages/taler-util/src/libtool-version.ts | 74 |
1 files changed, 38 insertions, 36 deletions
diff --git a/packages/taler-util/src/libtool-version.ts b/packages/taler-util/src/libtool-version.ts index 5e9d0b74e..17d2bbbdc 100644 --- a/packages/taler-util/src/libtool-version.ts +++ b/packages/taler-util/src/libtool-version.ts @@ -40,49 +40,51 @@ interface Version { age: number; } -/** - * Compare two libtool-style version strings. - */ -export function compare( - me: string, - other: string, -): VersionMatchResult | undefined { - const meVer = parseVersion(me); - const otherVer = parseVersion(other); - - if (!(meVer && otherVer)) { - return undefined; - } +export namespace LibtoolVersion { + /** + * Compare two libtool-style version strings. + */ + export function compare( + me: string, + other: string, + ): VersionMatchResult | undefined { + const meVer = parseVersion(me); + const otherVer = parseVersion(other); - const compatible = - meVer.current - meVer.age <= otherVer.current && - meVer.current >= otherVer.current - otherVer.age; + if (!(meVer && otherVer)) { + return undefined; + } - const currentCmp = Math.sign(meVer.current - otherVer.current); + const compatible = + meVer.current - meVer.age <= otherVer.current && + meVer.current >= otherVer.current - otherVer.age; - return { compatible, currentCmp }; -} + const currentCmp = Math.sign(meVer.current - otherVer.current); -function parseVersion(v: string): Version | undefined { - const [currentStr, revisionStr, ageStr, ...rest] = v.split(":"); - if (rest.length !== 0) { - return undefined; + return { compatible, currentCmp }; } - const current = Number.parseInt(currentStr); - const revision = Number.parseInt(revisionStr); - const age = Number.parseInt(ageStr); - if (Number.isNaN(current)) { - return undefined; - } + function parseVersion(v: string): Version | undefined { + const [currentStr, revisionStr, ageStr, ...rest] = v.split(":"); + if (rest.length !== 0) { + return undefined; + } + const current = Number.parseInt(currentStr); + const revision = Number.parseInt(revisionStr); + const age = Number.parseInt(ageStr); - if (Number.isNaN(revision)) { - return undefined; - } + if (Number.isNaN(current)) { + return undefined; + } - if (Number.isNaN(age)) { - return undefined; - } + if (Number.isNaN(revision)) { + return undefined; + } - return { current, revision, age }; + if (Number.isNaN(age)) { + return undefined; + } + + return { current, revision, age }; + } } |