@phragon-util/plain-object
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

@phragon-util/plain-object

Utilities for plain javascript object

❯ Install

$ npm install --save @phragon-util/plain-object

Usage

Is plain object

Returns true if an object was created by the Object constructor, or Object.create(null).
Function based on https://github.com/jonschlinkert/is-plain-object package, but does not return true if the object is null.

import { isPlainObject } from "@phragon-util/plain-object"

isPlainObject(Object.create({}));
// is: true
isPlainObject(Object.create(Object.prototype));
// is: true
isPlainObject({foo: 'bar'});
// is: true
isPlainObject({});
// is: true
isPlainObject(null);
// is: false

Clone plain object

Function for deep cloning plain objects.

import { clonePlainObject } from "@phragon-util/plain-object"

const original = { foo: 'bar', bar: { foo: '' } };
const clone = clonePlainObject(original);

original.bar.foo = "changed";

console.log(original);
// is: { foo: 'bar', bar: { foo: 'changed' } }

console.log(clone);
// is: { foo: 'bar', bar: { foo: '' } }

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i @phragon-util/plain-object

      Weekly Downloads

      3

      Version

      0.0.4

      License

      MIT

      Unpacked Size

      9.07 kB

      Total Files

      13

      Last publish

      Collaborators

      • websoftlab