September 2017
Intermediate to advanced
216 pages
6h 8m
English
Let's say that you have the following CSV data that you want to parse and use in an Immutable.js collection:
one,1,two,2,three,3four,4,five,5,six,6seven,7,eight,8,nine,9
Each row is a map that you want to insert into a list. Luckily, the format of each of these rows is already something that you can pass to Map.of(). You just need to parse it. To help with this, we'll use the readline module. This works by passing it a readable stream, and in return, it emits the line events every time a line is parsed. From there, you just have to create the map and add it to your list, as follows:
let myMapList = List();const csvInput = readline.createInterface({ input: fs.createReadStream('./input/01-data.csv')});csvInput.on('line', ...Read now
Unlock full access