Skip to content

Instantly share code, notes, and snippets.

@harrynewsome
Created September 19, 2016 11:59
Show Gist options
  • Save harrynewsome/836b29e59c5987823487318dc43fe135 to your computer and use it in GitHub Desktop.
Save harrynewsome/836b29e59c5987823487318dc43fe135 to your computer and use it in GitHub Desktop.
Is Util Object
// Utils
var is = {
arr: function(a) { return Array.isArray(a) },
obj: function(a) { return Object.prototype.toString.call(a).indexOf('Object') > -1 },
svg: function(a) { return a instanceof SVGElement },
dom: function(a) { return a.nodeType || is.svg(a) },
num: function(a) { return !isNaN(parseInt(a)) },
str: function(a) { return typeof a === 'string' },
fnc: function(a) { return typeof a === 'function' },
und: function(a) { return typeof a === 'undefined' },
nul: function(a) { return typeof a === 'null' },
hex: function(a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a) },
rgb: function(a) { return /^rgb/.test(a) },
hsl: function(a) { return /^hsl/.test(a) },
col: function(a) { return (is.hex(a) || is.rgb(a) || is.hsl(a)) }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment