Zed A. Shaw
||4 months ago|
|README.md||4 months ago|
|package-lock.json||4 months ago|
|package.json||5 months ago|
|step1.js||5 months ago|
|step2.js||5 months ago|
|step3.js||4 months ago|
|step4.js||4 months ago|
|step5.js||4 months ago|
|step6.js||4 months ago|
Exercise 01: CSV is Easy...Right?
This is exercise 01 of
step1.js-- Use two projects to get CSV samples and try to write a simple parser that can parse all of the samples.
step2.js-- This is a starter in case you are stuck, but it still fails and would fail on many CSV files. CSV is more complex than its name lets on.
step3.js-- Take your parser and use the deep-equal project to compare your results to the csv-spectrum project's tests.
step4.js-- Let's up the game and make this a unit test with ava, except it doesn't work because of promises/async/await not working with callbacks and events.
step5.js-- First solution to
Promisedirectly to wrap callbacks and events.
step6.js-- Second solution that uses util.promisify to convert the
spectrumcallback to a
If you attempt this challenge then point me at your solution at @lzsthw and I'll take a look.
You aren't really learning about CSVs, but actually learning about how to deal with old APIs that use callbacks when you need Promises. The
csv-spectrum library uses an old style of operation that loads your data then calls a function for you to process the data. These days APIs need Promises, and use async/await to deal with the promises. Using what you learned from the previous module
If You Get Stuck
Remember the programming process of:
- Write comments in human language describing what the code should do.
- Write pseudo-code (p-code) under those comments to bridge from human to code.
If you're stuck chances are you're not following this process. If you need a clue about how to handle the
csv-spectrum API then jump to the
step5.js file to see one way, and
step6.js to see another. Try to figure it out for yourself, and if you want a clue, remember that the
resolve parameter to a Promise can be called inside a callback.