Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] add new isPlainObject predicate function #32

Open
DerekNonGeneric opened this issue Aug 1, 2022 · 1 comment · May be fixed by #133
Open

[feature request] add new isPlainObject predicate function #32

DerekNonGeneric opened this issue Aug 1, 2022 · 1 comment · May be fixed by #133
Labels
claimed enhancement question wip Issues and PRs that are still a work in progress
Milestone

Comments

@DerekNonGeneric
Copy link
Member

DerekNonGeneric commented Aug 1, 2022

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?
@DerekNonGeneric
Copy link
Member Author

Very popular published packages for some prior art:

  • is-plain-object: returns true only for objects created by the Object constructor
  • isobject: returns true if the value is an object and not an array or null

@DerekNonGeneric DerekNonGeneric added this to the Version 3.0 milestone Aug 17, 2022
@DerekNonGeneric DerekNonGeneric added wip Issues and PRs that are still a work in progress claimed labels Nov 2, 2022
@DerekNonGeneric DerekNonGeneric linked a pull request Nov 5, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
claimed enhancement question wip Issues and PRs that are still a work in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant