Files
apps.apple.com/shared/utils/src/is-pojo.ts
Akshat Mehta edd5728428 main code
2025-11-23 11:03:57 +05:30

21 lines
508 B
TypeScript

/**
* Determine if {@linkcode arg} is a Plain Old JavaScript Object.
*
* @see https://masteringjs.io/tutorials/fundamentals/pojo
*
* @param arg to test
* @returns true if {@linkcode arg} is a POJO
*/
export function isPOJO(arg: unknown): arg is Record<string, unknown> {
if (!arg || typeof arg !== 'object') {
return false;
}
const proto = Object.getPrototypeOf(arg);
if (!proto) {
return true; // `Object.create(null)`
}
return proto === Object.prototype;
}