Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kellyselden/collapse-prototypes
Return an object with prototype properties included as own properties (for serialization purposes)
https://github.com/kellyselden/collapse-prototypes
Last synced: 16 days ago
JSON representation
Return an object with prototype properties included as own properties (for serialization purposes)
- Host: GitHub
- URL: https://github.com/kellyselden/collapse-prototypes
- Owner: kellyselden
- License: mit
- Created: 2017-05-14T21:11:14.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-12-02T17:53:41.000Z (about 2 months ago)
- Last Synced: 2024-12-26T03:32:13.557Z (about 1 month ago)
- Language: JavaScript
- Homepage:
- Size: 314 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# collapse-prototypes
[![npm version](https://badge.fury.io/js/collapse-prototypes.svg)](https://badge.fury.io/js/collapse-prototypes)
[![Build status](https://ci.appveyor.com/api/projects/status/ojx0e1dmu7nousgb/branch/main?svg=true)](https://ci.appveyor.com/project/kellyselden/collapse-prototypes/branch/main)Return an object with prototype properties included as own properties (for serialization purposes)
### Example
```js
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
```sh
yarn add collapse-prototypes
```### API
```js
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'
});
```