Skip to content

[feature request] add new isPlainObject predicate function #32

Description

@DerekNonGeneric

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions