New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@plandek-utils/plain-object

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plandek-utils/plain-object

TypeScript types and predicate `isPlainObject` and `isPlainObjectValue`, which are serializable POJOs.

latest
Source
npmnpm
Version
2.2.0
Version published
Maintainers
2
Created
Source

@plandek-utils/plain-object

npm version CI Maintainability Test Coverage

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); // => true
isPlainObjectValue(undefined); // => true
isPlainObjectValue(1); // => true
isPlainObjectValue(Infinite); // => false
isPlainObjectValue(NaN); // => false
isPlainObjectValue("something"); // => true
isPlainObjectValue(true); // => true
isPlainObjectValue(false); // => true
isPlainObjectValue([]); // => true
isPlainObjectValue([1, 2]); // => true
isPlainObjectValue([1, "something", 2]); // => true
isPlainObjectValue([1, "something", [2, 3]]); // => true
isPlainObjectValue(() => "oh no"); // => false
isPlainObjectValue({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } }); // => true
isPlainObjectValue({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: () => "oh no" } }); // => false

isPlainObject(null); // => false
isPlainObject(undefined); // => false
isPlainObject(1); // => false
isPlainObject(Infinite); // => false
isPlainObject(NaN); // => false
isPlainObject("something"); // => false
isPlainObject(true); // => false
isPlainObject(false); // => false
isPlainObject([]); // => false
isPlainObject([1, 2]); // => false
isPlainObject([1, "something", 2]); // => false
isPlainObject([1, "something", [2, 3]]); // => false
isPlainObject(() => "oh no"); // => false
isPlainObject({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } }); // => true
isPlainObject({ a: 1, b: "stuff", c: [1], d: {}, e: { e1: () => "oh no" } }); // => false

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 } }); // => true
isPlainObjectValueAnArrayOfObjects([{ a: 1, b: "stuff", c: [1], d: {}, e: { e1: true } }]); // => 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)

FAQs

Package last updated on 17 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts