All files / src/utils version-compatible.ts

30.77% Statements 4/13
0% Branches 0/4
0% Functions 0/2
33.33% Lines 4/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21  1x 1x 1x                                 1x
import {Context} from '../context';
import {ApiVersion} from '../base-types';
 
/**
 * Check if the current or optionally supplied version is compatible with a given version
 */
export default function versionCompatible(
  referenceVersion: ApiVersion,
  currentVersion: ApiVersion = Context.API_VERSION,
): boolean {
  // Return true if not using a dated version
  if (currentVersion === ApiVersion.Unstable) {
    return true;
  }
  const numericVersion = (version: string) =>
    parseInt(version.replace('-', ''), 10);
  const current = numericVersion(currentVersion);
  const reference = numericVersion(referenceVersion);
  return current >= reference;
}