diff options
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 }; + } } |