JSPM

@phragon-util/plain-object

0.0.4
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q30395F
  • License MIT

Package Exports

  • @phragon-util/plain-object
  • @phragon-util/plain-object/esm/index.js
  • @phragon-util/plain-object/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@phragon-util/plain-object) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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: '' } }