is-pojo.ts
1 /** 2 * Determine if {@linkcode arg} is a Plain Old JavaScript Object. 3 * 4 * @see https://masteringjs.io/tutorials/fundamentals/pojo 5 * 6 * @param arg to test 7 * @returns true if {@linkcode arg} is a POJO 8 */ 9 export function isPOJO(arg: unknown): arg is Record<string, unknown> { 10 if (!arg || typeof arg !== 'object') { 11 return false; 12 } 13 14 const proto = Object.getPrototypeOf(arg); 15 if (!proto) { 16 return true; // `Object.create(null)` 17 } 18 19 return proto === Object.prototype; 20 }