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

Already on GitHub? Sign in to your account

Stringifier.write doesn't handle Number objects. #128

Merged
merged 1 commit into from Oct 25, 2013

Conversation

Projects
None yet
2 participants
Contributor

whitlockjc commented Sep 6, 2013

While writing a transform that would attempt to turn string versions of booleans and numbers to their real JavaScript types, I ran into a situation where if my transform updated a row value to be a Number, I'd get this:

events.js:72
        throw er; // Unhandled 'error' event
              ^
TypeError: Object 357 has no method 'indexOf'
    at Stringifier.stringify (/home/me/csv2json/node_modules/csv/lib/stringifier.js:106:35)
    at Stringifier.write (/home/me/csv2json/node_modules/csv/lib/stringifier.js:41:33)
    at finish (/home/me/csv2json/node_modules/csv/lib/transformer.js:171:21)
    at done (/home/me/csv2json/node_modules/csv/lib/transformer.js:202:12)
    at run (/home/me/csv2json/node_modules/csv/lib/transformer.js:209:16)
    at Transformer.write (/home/me/csv2json/node_modules/csv/lib/transformer.js:222:3)
    at null.<anonymous> (/home/me/csv2json/node_modules/csv/lib/index.js:192:29)
    at EventEmitter.emit (events.js:95:17)
    at Parser.write (/home/me/csv2json/node_modules/csv/lib/parser.js:140:14)
    at CSV.write (/home/me/csv2json/node_modules/csv/lib/index.js:275:17)

I realize that I can just update my code to use myNum.valueOf() but upon looking at the code, it seems you're already trying to do some casting and such so maybe I wasn't doing anything wrong. Anyway, attached is a patch that handles the Number object just like the Date object. I tried updating the existing number support on line 75 to handle this but since it's a Number object and not a number literal, it seems this patch is legit.

wdavidw added a commit that referenced this pull request Oct 25, 2013

Merge pull request #128 from whitlockjc/master
Stringifier.write doesn't handle Number objects.

@wdavidw wdavidw merged commit aa6f543 into adaltas:master Oct 25, 2013

1 check passed

default The Travis CI build passed
Details
Collaborator

wdavidw commented Oct 25, 2013

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment