Last active
October 15, 2019 05:57
-
-
Save molvqingtai/f01e0e7f3bd6916fb0fa02ac148c7067 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
/** | |
* 检测空值 | |
* by: molvqingtai 2019-8-16 | |
* @param {[all]} value [检测对象] | |
* @return {[Boolean]} [是否为空] | |
*/ | |
const typesMap = new Map([ | |
['[object Null]', value => true], | |
['[object Date]', value => false], | |
['[object Math]', value => false], | |
['[object Number]', value => false], | |
['[object Symbol]', value => false], | |
['[object Boolean]', value => false], | |
['[object Function]', value => false], | |
['[object Undefined]', value => true], | |
['[object String]', value => !value], | |
['[object Set]', value => !value.size], | |
['[object Map]', value => !value.size], | |
['[object Array]', value => !value.length], | |
['[object Object]', value => !Object.entries(value).length] | |
]) | |
const isEmpty = value => typesMap.get(Object.prototype.toString.call(value))(value) | |
export default isEmpty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment