Created
January 17, 2017 17:32
-
-
Save JDMcKinstry/de076d2ca99f086955f769c43982feb4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** isEmpty(varried) | |
* Simple method for testing if item is "empty" | |
**/ | |
;(function() { | |
/** | |
* !a Basic empty check. Takes care of 90% of items passed through. | |
* 0 >= a Catchs '0' strings and empty Arrays | |
* | |
* /\{\}/.test(JSON.stringify(a).replace(/"[^"]*":(0|"0*"|false|null|\{\}|\[(null(,)?)*\]),?/g, '').replace(/"[^"]*":\{\},?/g, '')) // to determine Blank Object | |
* /|\[(null(,)*)*\]/.test(JSON.stringify(a).replace(/(0|"0*"|false|null|\{\}|\[(null(,)?)*\]),?/g, '')) // to determine Blank Array | |
**/ | |
function isEmpty(a) { | |
if (!a || 0 >= a) return !0; | |
if ("object" == typeof a) { | |
var b = JSON.stringify(a).replace(/"[^"]*":(0|"0*"|false|null|\{\}|\[(null(,)?)*\]),?/g, '').replace(/"[^"]*":\{\},?/g, ''); | |
if ( /^$|\{\}|\[\]/.test(b) ) return !0; | |
else if (a instanceof Array) { | |
b = b.replace(/(0|"0*"|false|null|\{\}|\[(null(,)?)*\]),?/g, ''); | |
if ( /^$|\{\}|\[\]/.test(b) ) return !0; | |
} | |
} | |
return false; | |
} | |
window.hasOwnProperty("empty")||(window.empty=isEmpty); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment