https://github.com/tapjs/clean-yaml-object
Clean up an object prior to serialization
https://github.com/tapjs/clean-yaml-object
Last synced: 3 months ago
JSON representation
Clean up an object prior to serialization
- Host: GitHub
- URL: https://github.com/tapjs/clean-yaml-object
- Owner: tapjs
- License: other
- Created: 2016-01-16T03:29:38.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2022-02-26T20:03:06.000Z (over 3 years ago)
- Last Synced: 2025-04-05T13:43:31.132Z (3 months ago)
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/clean-yaml-object
- Size: 116 KB
- Stars: 3
- Watchers: 3
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
README
# clean-yaml-object [](https://travis-ci.org/tapjs/clean-yaml-object) [](https://coveralls.io/github/tapjs/clean-yaml-object?branch=master)
> Clean up an object prior to serialization.
Replaces circular references, pretty prints Buffers, and numerous other enhancements. Primarily designed to prepare Errors for serialization to JSON/YAML.
Extracted from [`node-tap`](https://github.com/tapjs/node-tap)
## Install
```
$ npm install --save clean-yaml-object
```## Usage
```js
const cleanYamlObject = require('clean-yaml-object');cleanYamlObject(new Error('foo'));
//=> {name: 'Error', message: 'foo', stack: ...}
```## API
### cleanYamlObject(input, [filterFn])
Returns a deep copy of `input` that is suitable for serialization.
#### input
Type: `*`
Any object.
#### filterFn
Type: `callback(propertyName, isRoot, source, target)`
Optional filter callback. Returning `true` will cause the property to be copied. Otherwise it will be skipped
- `propertyName`: The property being copied.
- `isRoot`: `true` only if `source` is the top level object passed to `copyYamlObject`
- `source`: The source from which `source[propertyName]` will be copied.
- `target`: The target object.## License
MIT © [Isaac Z. Schlueter](http://github.com/isaacs) [James Talmage](http://github.com/jamestalmage)