All files Record.ts

100% Statements 4/4
100% Branches 11/11
100% Functions 3/3
100% Lines 4/4

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 35 36 37 38 39 40 41 42 43 44 45 46 47 481x               10x         10x                                                             200x      
export function isRecord<
  K extends string | number | symbol = string | number | symbol,
  V = unknown
>(
  obj: unknown,
  isK?: (k: unknown) => k is K,
  isV?: (v: unknown) => v is V
): obj is Record<K, V> {
  return (
    typeof obj === 'object' &&
    obj !== null &&
    Object.keys(obj).reduce(
      (result, key) =>
        result &&
        (!isK || isK(key)) &&
        (!isV || isV(obj[key as keyof typeof obj])),
      true
    ) &&
    [
      Function,
      Boolean,
      Error,
      Number,
      Date,
      String,
      RegExp,
      Array,
      Uint8Array,
      Uint16Array,
      Uint32Array,
      Int16Array,
      Int32Array,
      Float32Array,
      Float64Array,
      Map,
      Set,
      WeakMap,
      WeakSet,
      ArrayBuffer,
      DataView,
      Promise,
      DisposableStack,
      AsyncDisposableStack,
      FormData
    ].reduce((result, T) => result && !(obj instanceof T), true)
  );
}