MCPcopy
hub / github.com/redis/node-redis / compareVersions

Method compareVersions

packages/test-utils/lib/index.ts:357–369  ·  view source on GitHub ↗

* Compares two semantic version arrays and returns: * -1 if version a is less than version b * 0 if version a equals version b * 1 if version a is greater than version b * * @param a First version array * @param b Second version array * @returns -1 | 0 | 1

(a: Array<number>, b: Array<number>)

Source from the content-addressed store, hash-verified

355 * @returns -1 | 0 | 1
356 */
357 static compareVersions(a: Array<number>, b: Array<number>): -1 | 0 | 1 {
358 const maxLength = Math.max(a.length, b.length);
359
360 const paddedA = [...a, ...Array(maxLength - a.length).fill(0)];
361 const paddedB = [...b, ...Array(maxLength - b.length).fill(0)];
362
363 for (let i = 0; i < maxLength; i++) {
364 if (paddedA[i] > paddedB[i]) return 1;
365 if (paddedA[i] < paddedB[i]) return -1;
366 }
367
368 return 0;
369 }
370
371 testWithClient<
372 M extends RedisModules = {},

Callers 3

isVersionGreaterThanMethod · 0.80
isVersionInRangeMethod · 0.80
index.spec.tsFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected