Skip to content

Instantly share code, notes, and snippets.

@snakeneedy
Created May 21, 2020 05:22
Show Gist options
  • Save snakeneedy/04f6ce92d358b61207d2ad2b42f072c7 to your computer and use it in GitHub Desktop.
Save snakeneedy/04f6ce92d358b61207d2ad2b42f072c7 to your computer and use it in GitHub Desktop.

Revisions

  1. snakeneedy created this gist May 21, 2020.
    36 changes: 36 additions & 0 deletions typeUtil.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,36 @@
    const getTypeName = (o) => {
    if (o === undefined) return 'undefined';
    if (o === null) return 'null';
    return o.constructor.name;
    };

    const isUndefined = (o) => (o === undefined);

    const isNull = (o) => (o === null);

    const isString = (o) => (getTypeName(o) === 'String');

    const isNumber = (o) => (getTypeName(o) === 'Number');

    const isInteger = (o) => (Number.isInteger(o));

    const isBoolean = (o) => (getTypeName(o) === 'Boolean');

    const isArray = (o) => (Array.isArray(o));

    const isPureObject = (o) => (getTypeName(o) === 'Object');

    const isSymbol = (o) => (getTypeName(o) === 'Symbol');

    export default {
    getTypeName,
    isUndefined,
    isNull,
    isString,
    isNumber,
    isInteger,
    isBoolean,
    isArray,
    isPureObject,
    isSymbol,
    };