davidmarkclements / rfdc

Really Fast Deep Clone
MIT License
643 stars 25 forks source link

Support Buffer #8

Closed gajus closed 5 years ago

gajus commented 5 years ago

Is there a reason for not supporting Buffer cloning?

gajus commented 5 years ago

Currently, Buffer becomes a stringified expression, e.g.

import createClone from 'rfdc';

const clone = createClone();

const requestDefinition = {
  foo: Buffer.from('bar')
};

console.log('IN', requestDefinition);
console.log('OUT', clone(requestDefinition));
IN { foo: <Buffer 62 61 72> }
OUT { foo: { '0': 98, '1': 97, '2': 114 } }
gajus commented 5 years ago

Equally, would be nice to have functionality equivalent to https://www.npmjs.com/package/map-obj that would allow to customise cloning behaviour per key/value.

BridgeAR commented 5 years ago

This module is specialist on cloning "simple" objects very fast. The more types get supported, the more special cases have to be supported which slows down the average case. I don't think it's a good idea to go into that direction. Similar with the map-obj module: keeping such functionality in a specialised module seems best to me.

davidmarkclements commented 5 years ago

yes I agree with @BridgeAR - having said that if were able to create a PR with buffer support that includes benchmarks showing zero overhead I'd be happy to accept. closing for now