All files / lib/validation validate.ts

62.5% Statements 15/24
55% Branches 11/20
100% Functions 3/3
75% Lines 12/16

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 22 23 24 25 26 27 28 29 30 31 32 33 34 351x           11x 11x 11x       1x         22x 22x   22x       1x         22x 22x   22x    
export const validateBuffer = (
  value: Buffer,
  key: string,
  className: string,
  expectedLength?: number,
): void => {
  Iif (value === undefined) throw Error(`${className} ${key} is undefined`);
  Iif (value.length === 0) throw Error(`${className} ${key} length cannot be 0`);
  Iif (expectedLength && value.length !== expectedLength)
    throw Error(`${className} ${key} length expected to be ${expectedLength}`);
};
 
export const validateBigInt = (
  value: bigint,
  key: string,
  className: string,
): void => {
  Iif (value === undefined) throw Error(`${className} ${key} is undefined`);
  Iif (typeof value !== 'bigint')
    throw Error(`${className} ${key} must be type bigint`);
  Iif (value === BigInt(0))
    throw Error(`${className} ${key} must be greater than 0`);
};
 
export const validateNumber = (
  value: number,
  key: string,
  className: string,
): void => {
  Iif (value === undefined) throw Error(`${className} ${key} is undefined`);
  Iif (typeof value !== 'number')
    throw Error(`${className} ${key} must be type number`);
  Iif (value === 0) throw Error(`${className} ${key} must be greater than 0`);
};