New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

plainp

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plainp

Check if a value is a plain object, with TypeGuard.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

PlainP

Plain Predicates

MIT License npm version npm download npm bundle size

Introduction

Functions test if values are plain objects or values.

Installation

$ npm install --save plainp

Usage

Typescript types

JSON data types
import type from {
    SerializablePrimitive,
    SerializableValue,
    SerializableArray,
    SerializableObject
} from 'plainp';
JSON data types + undefined
import type from {
    PlainPrimitive,
    PlainValue,
    PlainArray,
    PlainObject,
    PlainObjectShallow
} from 'plainp'

Utility functions

import from {
    isSerializablePrimitive,
    isPlainPrimitive,
    isPlainObjectShallow,
    isPlainArray,
    isPlainObject,
} from 'plainp'
isSerializablePrimitive
// => true
isSerializablePrimitive(1);
isSerializablePrimitive('foo');
isSerializablePrimitive(true);
isSerializablePrimitive(null);

// => false
isSerializablePrimitive(undefined);
isSerializablePrimitive(NaN);
isSerializablePrimitive(Infinity);
isPlainPrimitive
// => true
isPlainPrimitive(1);
isPlainPrimitive('foo');
isPlainPrimitive(true);
isPlainPrimitive(null);
isPlainPrimitive(undefined);

// => false
isPlainPrimitive(NaN);
isPlainPrimitive(Infinity);
isPlainObjectShallow
// => true
isPlainObjectShallow({});
isPlainObjectShallow({foo: 'bar'});
isPlainObjectShallow(new Object());
isPlainObjectShallow(new Object(null));
isPlainObjectShallow(new Object({}));
isPlainObjectShallow(Object.create(Object.prototype));

// => false
isPlainObjectShallow(undefined);
isPlainObjectShallow(null);
isPlainObjectShallow(false);
isPlainObjectShallow(NaN);
isPlainObjectShallow(Infinity);
isPlainObjectShallow(1);
isPlainObjectShallow('foo');
isPlainObjectShallow([]);
isPlainObjectShallow(Object.create(null));
isPlainObjectShallow(Object.create({}));
isPlainObjectShallow(new (class Foo {}));
isPlainArray
// => true
isPlainArray([]);
isPlainArray([undefined]);
isPlainArray([null]);
isPlainArray([true]);
isPlainArray(['foo']);
isPlainArray([['foo'], 1, [true, null]]);
isPlainArray([{foo: 'bar'}, 'baz']);

// => false
isPlainArray(1);
isPlainArray(false);
isPlainArray(undefined);
isPlainArray(null);
isPlainArray([NaN]);
isPlainArray([Infinity]);
isPlainObject
// => true
isPlainObject({});
isPlainObject({foo: 'bar'});
isPlainObject(new Object());
isPlainObject(new Object(null));
isPlainObject(new Object({}));
isPlainObject(Object.create(Object.prototype));
isPlainObject({foo: {}});
isPlainObject({foo: {bar: undefined}});
isPlainObject({foo: {bar: null}});
isPlainObject({foo: {bar: 'baz'}});
isPlainObject({foo: {bar: [[1, true]]}});
isPlainObject({foo: {bar: {baz: []}}});
isPlainObject({foo: {bar: {baz: [1, 'qux', true, undefined, null]}}});
isPlainObject({foo: {bar: new Object()}});
isPlainObject({foo: {bar: new Object(null)}});
isPlainObject({foo: {bar: new Object({})}});
isPlainObject({foo: {bar: Object.create(Object.prototype)}});

// => false
isPlainObject(undefined);
isPlainObject(null);
isPlainObject(false);
isPlainObject(NaN);
isPlainObject(Infinity);
isPlainObject(1);
isPlainObject('foo');
isPlainObject([]);
isPlainObject(['foo', 'bar']);
isPlainObject(Object.create(null));
isPlainObject(Object.create({}));
isPlainObject(new (class Foo {}));
isPlainObject({1: {bar: [NaN]}});
isPlainObject({foo: {bar: [NaN]}});
isPlainObject({foo: {bar: [Infinity]}});
isPlainObject({foo: {bar: {baz: NaN}}});
isPlainObject({foo: {bar: {baz: [1, false, NaN]}}});
isPlainObject({foo: {bar: {baz: [1, false, Infinity]}}});
isPlainObject({foo: {bar: {baz: Object.create(null)}}});
isPlainObject({foo: {bar: {baz: Object.create({})}}});
isPlainObject({foo: {bar: new (class Foo {})}});
isPlainValue
isPlainPrimitive(value) || isPlainArray(value) | isPlainObject(value)

License

MIT licensed.

Keywords

FAQs

Package last updated on 15 Nov 2023

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc