Socket
Book a DemoInstallSign in
Socket

collapse-prototypes

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

collapse-prototypes

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

latest
Source
npmnpm
Version
7.0.0
Version published
Maintainers
1
Created
Source

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'
});

Keywords

circular

FAQs

Package last updated on 21 Jun 2025

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