Skip to content

Instantly share code, notes, and snippets.

@glebcha
Created April 21, 2020 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glebcha/16c51a5a85f0e754b626f46030ab650c to your computer and use it in GitHub Desktop.
Save glebcha/16c51a5a85f0e754b626f46030ab650c to your computer and use it in GitHub Desktop.
Check common js types
const modifier = type => item => Object.prototype.toString.call(item) === `[object ${type}]`;
const checkTypes = ['String', 'Function', 'Number', 'Boolean', 'Object', 'Symbol'];
const is = checkTypes.reduce((checkers, type) => ({ ...checkers, [type]: modifier(type) }), {});
is.Function(null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment