Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/facile-clone
Creates a shallow clone of an object, focusing on primitives and omitting or clipping large values.
https://github.com/thlorenz/facile-clone
Last synced: 26 days ago
JSON representation
Creates a shallow clone of an object, focusing on primitives and omitting or clipping large values.
- Host: GitHub
- URL: https://github.com/thlorenz/facile-clone
- Owner: thlorenz
- License: mit
- Created: 2017-01-24T16:03:23.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-10T23:29:54.000Z (almost 8 years ago)
- Last Synced: 2024-11-22T16:44:59.084Z (about 1 month ago)
- Language: JavaScript
- Homepage: https://thlorenz.github.io/facile-clone
- Size: 1.13 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# facile-clone [![build status](https://secure.travis-ci.org/thlorenz/facile-clone.png)](http://travis-ci.org/thlorenz/facile-clone)
Creates a shallow clone of an object, focusing on primitives and omitting or clipping large values.
```js
const facileClone = require('facile-clone')const o = {
num: 1
, bool: true
, string: '0123456789'
, buf: Buffer.from('0123456789')
, null: null
, undefined: undefined
, object: { foo: 'bar' }
}console.log(facileClone(o))
/* => { num: 1,
bool: true,
string: { type: 'string', len: 10, included: 0, val: '' },
buf: { type: 'Buffer', len: 10, included: 0, val: '' },
null: null,
undefined: undefined,
object: { type: 'object', val: '' } } */const bufObject = {
buf: Buffer.from('0123456789')
}
console.log(facileClone(bufObject, { bufferLength: 5 }))
// => { buf: { type: 'Buffer', len: 10, included: 5, val: } }const stringObject = {
string: '0123456789'
}
console.log(facileClone(stringObject, { stringLength: 5 }))
// => { string: { type: 'string', len: 10, included: 5, val: '01234' } }
```## Installation
npm install facile-clone
## [API](https://thlorenz.github.io/facile-clone)
### facileClone
Creates a shallow clone of the object, focusing on primitives and omitting
or clipping large values.For objects it also attempts to detect their prototype and provides it via the `proto`
property.**Parameters**
- `x` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the object to clone
- `$0` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** options to configure how large values are omitted/clipped
- `$0.bufferLength` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** if greater than `0` parts of buffers are included in the clone, default: `0` (optional, default `0`)
- `$0.stringLength` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** if greater than `0` parts of strings are included in the clone, default: `0` (optional, default `0`)
- `$0.keepFunctions` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** if `true` functions are kept attached to the object, NOTE that this
will be a reference to the actual function of the original, i.e. not a clone (optional, default `false`)## License
MIT