collapse-prototypes

6.0.0 • Public • Published

collapse-prototypes

npm version Build status

Return an object with prototype properties included as own properties (for serialization purposes)

Example

import collapse from 'collapse-prototypes';

let parent = {
  foo: 1
};

let child = Object.create(parent);

child.bar = 2;

let collapsed = collapse(child);

console.log(collapsed); // { foo: 1, bar: 2 }

Installation

yarn add collapse-prototypes

API

collapse(obj, {
  // useful if you're going to serialize, because `toJSON` and getters
  // may not like the new prototype-less object
  // Default value (false)
  stripFunctions: true,

  // speeds up collapsing if you don't need them
  // Default value (false)
  excludeNonenumerable: true,

  // useful if you're going to stringify (uses `json-stringify-safe`)
  // Default value (false)
  dropCycles: true,

  // prepend the debug log to differentiate calls using the `debug` package
  // (DEBUG=collapse-prototypes)
  // Default value ('')
  debugLabel: 'obj'
});

Package Sidebar

Install

npm i collapse-prototypes

Weekly Downloads

2

Version

6.0.0

License

MIT

Unpacked Size

7.44 kB

Total Files

4

Last publish

Collaborators

  • kellyselden