mazey
    Preparing search index...

    Function isNumber

    • Check whether a value is a number allowed by the supplied options.

      Usage:

      import { isNumber } from "mazey";

      const ret1 = isNumber(123);
      const ret2 = isNumber("123");
      // Default: NaN, Infinity is not Number
      const ret3 = isNumber(Infinity);
      const ret4 = isNumber(Infinity, { isInfinityAsNumber: true });
      const ret5 = isNumber(NaN);
      const ret6 = isNumber(NaN, { isNaNAsNumber: true, isInfinityAsNumber: true });
      const ret7 = isNumber(12, { integer: true, min: 1, max: 31 });
      const ret8 = isNumber(12.5, { integer: true, min: 1, max: 31 });
      console.log(ret1, ret2, ret3, ret4, ret5, ret6, ret7, ret8);

      Output:

      true false false true false true true false
      

      Parameters

      • num: unknown

        Value to check.

      • options: IsNumberOptions = {}

        Controls non-finite values and optional integer or inclusive range constraints.

      Returns boolean

      Whether the value is an allowed number.

      Invalid bounds, reversed bounds, and NaN combined with an integer or range constraint return false. Omitting the new constraints preserves the existing non-finite-number behavior.