Last active
September 4, 2017 00:43
-
-
Save mk-pmb/f0b66d45bd9a8cda784d52d07ae29fad to your computer and use it in GitHub Desktop.
Test / example data for https://github.com/adaltas/node-csv-parse/issues/148
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*jslint indent: 2, maxlen: 80, node: true */ | |
/* -*- tab-width: 2 -*- */ | |
'use strict'; | |
var input, parseCsv = require('csv-parse/lib/sync'), auto, plus, | |
sep = ';', eq = require('assert').deepStrictEqual; | |
input = [ '42.23', '042.23', '042', '0042', | |
'0x42', '0x42.23', '0o42\n' ].join(sep); | |
auto = parseCsv(input, { delimiter: sep, auto_parse: true }); | |
plus = input.trim().split(sep | |
).map(function numberize(x) { return +x; } | |
// v-- required because deepStrictEqual has no special case for NaN | |
).map(function nan2str(x) { return (Number.isNaN(x) ? String(x) : x); }); | |
eq(auto, [ [ 42.23, 42.23, 42, 42, 0, '0x42.23', 0 ] ]); | |
eq(plus, [ 42.23, 42.23, 42, 42, 66, 'NaN', 34 ]); | |
// For '0x42' and '0o42', numberize() yields a more useful result. | |
// For '0x42.23', auto_parse's type guess is smarter and ok for me. | |
// $ node-versions csv-parse | |
// require('csv-parse/package.json').version = 1.2.1 | |
// Node.js v6.11.2, npm v3.10.10, Ubuntu 14.04.5 LTS trusty, | |
// kernel: 3.13.0-119-generic, machine/CPU/platform: i686 i686 i686 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment