import { getType } from './get-type';

const typeCheck = function (type: string, val: any): boolean {
  if (getType(val) === type) {
    return true;
  } else {
    return false;
  }
};

type TypeChecking = {
  number: (val: any) => boolean;
  string: (val: any) => boolean;
  array: (val: any) => boolean;
  object: (val: any) => boolean;
};

export const is: TypeChecking = {
  number: (val: any) => {
    return Number.isFinite(val);
  },
  string: (val: any) => {
    return typeCheck('String', val);
  },
  array: (val: any) => {
    return typeCheck('Array', val);
  },
  object: (val: any) => {
    return typeCheck('Object', val);
  },
};
