Description
Hello and thanks for this useful library!
I am trying to use this library in a nodejs project of mine. I have a complex object which also includes Buffer
s. When I deepMap
on this object, I receive each Buffer
byte one-by-one in map.
The reason is due to lodash
, isObject
returning true for Buffers:
const buf = new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
const _ = require('lodash')
console.log(_.isObject(buf)) // true :(
So if I run deep-map like this:
const deepMap = require('deep-map')
const iterateThis = {
numberTest: 1,
arrayTest: ['one', 'two'],
stringTest: "string",
bufferTest: new Buffer([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])
}
const shouldBeTheSame = deepMap(iterateThis, (value) => value)
console.log(shouldBeTheSame)
In the response I get:
arrayTest: ["one", "two"]
bufferTest: Object {0: 98, 1: 117, 2: 102, 3: 102, 4: 101, 5: 114}
numberTest: 1
stringTest: "string"
As it can be seen, although I do nothing on map function, Buffer is not a buffer but a simple object now. Please click this link to run it yourself.
Is it possible to treat Buffers as non-iterable or offer a way to select what should be iterable and what not?
Thanks!
PS. I also see Date
's are also tried to be iterated and in the end you lose the date value. I updated linked demo to show this as well.