# All files / lib/validation validate.ts

25% Statements 6/24
0% Branches 0/11
0% Functions 0/3
18.75% Lines 3/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

    1x

    1x

     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`);
    };