facile-clone
Creates a shallow clone of an object, focusing on primitives and omitting or clipping large values.
Last updated 4 years ago by thlorenz .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install facile-clone 
SYNC missed versions from official npm registry.

facile-clone build status

Creates a shallow clone of an object, focusing on primitives and omitting or clipping large values.

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: '<deleted>' },
          buf: { type: 'Buffer', len: 10, included: 0, val: '<deleted>' },
          null: null,
          undefined: undefined,
          object: { type: 'object', val: '<deleted>' } } */

const bufObject = {
  buf: Buffer.from('0123456789')
}
console.log(facileClone(bufObject, { bufferLength: 5 }))
// => { buf: { type: 'Buffer', len: 10, included: 5, val: <Buffer 30 31 32 33 34> } }

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

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 the object to clone
  • $0 Object options to configure how large values are omitted/clipped
    • $0.bufferLength Number? if greater than 0 parts of buffers are included in the clone, default: 0 (optional, default 0)
    • $0.stringLength Number? if greater than 0 parts of strings are included in the clone, default: 0 (optional, default 0)
    • $0.keepFunctions 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

Current Tags

  • 1.2.0                                ...           latest (4 years ago)

5 Versions

  • 1.2.0                                ...           4 years ago
  • 1.1.1                                ...           4 years ago
  • 1.1.0                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (3)
Dependents (3)

Copyright 2014 - 2016 © taobao.org |