-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
96 lines (90 loc) · 2.27 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const CSV = require('./index');
// Dummy data
const objects = [
{
headerOne: "some data",
headerTwo: "some other data",
headerThree: "kimi"
},
{
headerOne: "some data",
headerTwo: "some other data",
},
{
headerOne: "some data",
headerTwo: "some other data",
headerThree: "kimi"
},
{
headerOne: "some data",
},
{
headerOne: "some data",
headerTwo: "some other data",
headerThree: "kimi",
luckyOne: "I have 4 headers!"
},
{
headerOne: "some data",
headerTwo: 'I already have some "double quotes", can you handle this?',
headerThree: "kimi",
},
]
// Dummy CSV strings from https://people.sc.fsu.edu/~jburkardt/data/csv/csv.html
const csvStrings = [
`"Day of Week", "Number of Crashes"
"Sunday is the best ""day""", "13664"
"Monday is the worst ""day""", "17279"
"Tuesday", "17337"
"Wednesday", "17394"
"Thursday", "17954"
"Friday", "19147"
"Saturday", "15714"`
]
// Dummy options
const optionsArray = [
{
identifier: "default",
options:{
seperator: ",",
isSurrounded: true
}
},{
identifier: "not surrounded and seperated with '|'",
options:{
seperator: "|",
isSurrounded: false
}
},{
identifier: "seperated with ';'",
options:{
seperator: ";",
}
},{
identifier: "not surrounded",
options:{
isSurrounded: false
}
},{
identifier: "surrounded and seperated with '|'",
options:{
seperator: "|",
isSurrounded: true
}
}
]
function testStringify() {
console.log(`\n[[ no options ]]]\n${CSV.stringify(objects)}\n[[[ no options ]]]`)
optionsArray.forEach(options => {
console.log(options)
console.log(
`\n[[[ ${options.identifier} ]]]\n${CSV.stringify(objects, options.options)}\n[[[ ${options.identifier} ]]]`
)
})
}
function testParse() {
console.log(CSV.parse(csvStrings[0], {seperator:',', isSurrounded:true}))
// console.log(CSV.parse(csvStrings[1], {seperator:',', isSurrounded:false}))
}
testParse()
testStringify()