plainp
v1.0.0
Published
Check if a value is a plain object, with TypeGuard.
Downloads
4
Maintainers
Readme
PlainP
Plain Predicates
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)