|
/** |
|
@func |
|
is the value of type obj? |
|
|
|
@notes |
|
an empty obj is also true |
|
|
|
@cons |
|
may not work in IE 11 |
|
|
|
@param {{}} o obj expected |
|
@return {boolean} |
|
*/ |
|
export const isObj = o => isNotNil(o) && o.constructor === Object; |
|
|
|
//@tests |
|
const aTrue = [{}, { id: 166 }, |
|
(() => ({}))(), //a func that returns an empty obj |
|
new Object(), |
|
Object.create({}), |
|
Object.fromEntries([]), //cast a 2D arr of key/value pairs into an obj |
|
Object.fromEntries([...new Map()]), //cast a Map to an obj |
|
JSON.parse("{}"), //deserialize a string into an obj |
|
]; |
|
|
|
const aFalse = [null, undefined, "{}", [{}], () => { }, [], [1, 2, 3], "", Object, |
|
new Array(), new Function(), new String(), new Number(), new Boolean(), |
|
new RegExp(/_/), , new Date(), Infinity, BigInt, Map, new Map(), |
|
new Map(Object.entries({ foo: "bar" })), |
|
new Map([[1, "uno"], [2, "dos"]]), |
|
Object.create(null), |
|
]; |
|
|
|
logForeachParam(isObj, aTrue); |
|
logForeachParam(isObj, aFalse); |
|
|
|
//@perftest |
|
timeInLoop("isObj", 1e9, //1.737 for 1e9 |
|
() => { |
|
isObj(aTrue); |
|
isObj(aFalse); |
|
}); |
|
|
|
/* |
|
logForeachParam sourcecode at: |
|
https://gist.github.com/funfunction/42918a4751ae51828cfc4c2dd4c0678e |
|
|
|
isNil and isNotNil sourcecode at: |
|
https://gist.github.com/funfunction/0e64a5aa3abedfa237823d0bab2ef70b |
|
|
|
timeInLoop sourcecode at: |
|
https://gist.github.com/funfunction/91b5876a5f562e1e352aed0fcabc3858 |
|
*/ |