OpenINF / openinf-util-object

Common JavaScript object type-related utilities
https://github.com/OpenINF/openinf-util-object#readme
Other
3 stars 3 forks source link

[feature request] add new `isPlainObject` predicate function #32

Open DerekNonGeneric opened 1 year ago

DerekNonGeneric commented 1 year ago

The isPlainObject predicate function is another common convenience function in the JS Object domain.




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)](https://en.wikipedia.org/wiki/Plain_old_Java_object), which are [also a thing in JS](https://web.archive.org/web/20140913151352/http://ajaxian.com/archives/return-of-the-pojo-plain-ole-javascript)
Open question
would a more rigorous check be necessary to differentiate btwx the two or is it fine?
DerekNonGeneric commented 1 year ago

Very popular published packages for some prior art: