The isPlainObject predicate function is another common convenience function in the JS Object domain.
- It is quite frequently used and would be very helpful to have.
- It is distinct from the very similar
isObject predicate function from @openinf/util-types
- It is distinct from the
isObjectLike predicate function, which is often kept private/internal
const isPlainObject = ( obj ) => {
return (
typeof obj === 'object' &&
obj !== null &&
obj.constructor === Object &&
Object.prototype.toString.call( obj ) === '[object Object]'
);
};
- Aside
-
hopefully not a misnomer due to the existence of plain old Java objects (POJOs), which are also a thing in JS
- Open question
- would a more rigorous check be necessary to differentiate btwx the two or is it fine?
The
isPlainObjectpredicate function is another common convenience function in the JS Object domain.isObjectpredicate function from@openinf/util-typesisObjectLikepredicate function, which is often kept private/internalhopefully not a misnomer due to the existence of plain old Java objects (POJOs), which are also a thing in JS