ixfx
    Preparing search index...

    Function keysToNumbers

    • Returns a copy of object with integer numbers as keys instead of whatever it has.

      keysToNumbers({ '1': true }); // Yields: { 1: true }
      

      The onInvalidKey sets how to handle keys that cannot be converted to integers.

      • 'throw' (default): throws an exception
      • 'ignore': that key & value is ignored
      • 'keep': uses the string key instead
      keysToNumber({ hello: 'there' }, `ignore`); // Yields: {  }
      keysToNumber({ hello: 'there' }, `throw`); // Exception
      keysToNumber({ hello: 'there' }, `keep`); // Yields: { hello: 'there' }

      Floating-point numbers will be converted to integer by rounding.

      keysToNumbers({ '2.4': 'hello' }); // Yields: { 2: 'hello' }
      

      Type Parameters

      • T

      Parameters

      • object: Record<any, T>
      • onInvalidKey: "throw" | "ignore" | "keep" = ...

      Returns Record<number, T>