Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Buffer's to be non-iterable #11

Open
ubenzer opened this issue Aug 19, 2017 · 2 comments
Open

Allow Buffer's to be non-iterable #11

ubenzer opened this issue Aug 19, 2017 · 2 comments

Comments

@ubenzer
Copy link

ubenzer commented Aug 19, 2017

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 Buffers. 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.

ubenzer added a commit to ubenzer/deep-map that referenced this issue Aug 20, 2017
isObject returns true for Date, Buffer objects. This causes iterating into this objects, eventually, you lose the original Date and Buffer objects. Fixes mcmath#11
ubenzer added a commit to ubenzer/deep-map that referenced this issue Aug 20, 2017
isObject returns true for Date, Buffer objects. This causes iterating into this objects, eventually, you lose the original Date and Buffer objects. Fixes mcmath#11
@rhyek
Copy link

rhyek commented Jun 26, 2019

I am having the same issue with Date objects. All I get is {}. Any way to skip dates?

@rhyek
Copy link

rhyek commented Jun 26, 2019

@mcmath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants