@plandek-utils/plain-object

TypeScript types and predicate utils isPlainObject and isPlainObjectValue. Also includes fast checks isPlainObjectValueAnObject and `isPlainObjectValueAnArrayOfObjects.
A PlainObject is a POJO where all values are PlainObjectValue.
A PlainObjectValue is one of:
null or undefined
- Finite number (no NaN or Infinite)
- String
- Boolean
- Dayjs
- Array of PlainObjectValue (or readonly array of PlainObjectValue)
- PlainObject
Usage
import { isPlainObject, isPlainObjectValue } from "@plandek-utils/plain-object";
isPlainObjectValue(null);
isPlainObjectValue(undefined);
isPlainObjectValue(1);
isPlainObjectValue(Infinite);
isPlainObjectValue(NaN);
isPlainObjectValue("something");
isPlainObjectValue(true);
isPlainObjectValue(false);
isPlainObjectValue([]);
isPlainObjectValue([1, 2]);
isPlainObjectValue([1, "something", 2]);
isPlainObjectValue([1, "something", [2, 3]]);
isPlainObjectValue(() => "oh no");
isPlainObjectValue({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } });
isPlainObjectValue({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: () => "oh no" } });
isPlainObject(null);
isPlainObject(undefined);
isPlainObject(1);
isPlainObject(Infinite);
isPlainObject(NaN);
isPlainObject("something");
isPlainObject(true);
isPlainObject(false);
isPlainObject([]);
isPlainObject([1, 2]);
isPlainObject([1, "something", 2]);
isPlainObject([1, "something", [2, 3]]);
isPlainObject(() => "oh no");
isPlainObject({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } });
isPlainObject({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: () => "oh no" } });
isPlainObject will check exhaustively all values of the given object using zod. This can be slow for large quantities of data. If we already know that the given data is a PlainObjectValue, we can use isPlainObjectValueAnObject or isPlainObjectValueAnArrayOfObjects to check if the value is an object or an array of objects respectively.
import { isPlainObjectValueAnObject, isPlainObjectValueAnArrayOfObjects } from "@plandek-utils/plain-object";
isPlainObjectValueAnObject({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } });
isPlainObjectValueAnArrayOfObjects([{ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } }]);
Development
TypeScript types and predicate isPlainObject and isPlainObjectValue. PlainObject = POJO where all values are
PlainObjectValue. PlainObjectValue = serializable value (Dayjs, nil, number, string, boolean, PlainObjectValue[],
PlainObject)