/truss-work-sample

please ignore this if you're not a Truss work sample reviewer :)

Primary LanguageJavaScript

csv normalizer

A tool that reads a CSV formatted file on stdin and emits a normalized CSV formatted file on stdout.

Table of contents:


installing dependencies

You will need Node.js 8.0.0+ installed to run this utility or work with this code. If you don't already have Node installed, you can download an installer here.

To install dependencies, run the following command from package root:

npm i

^ top ^

running this utility

Since I did not test this on an Ubuntu device, I recommend running it on Mac OS. Theoretically, it should work fine on either.

running without global installation

You can run this utility right from package root with the command:

cat sample.csv | node src

If you run into permission errors, you can try running the getPerms script (npm run getPerms). You can also resolve them by installing globally with the following instructions.

installing globally

Run this command from project root:

npm i -g .

The recommended usage is to pipe an input file into the command:

cat sample.csv | csv-normalize

^ top ^

running tests

from command line

To run the full suite of tests, use command:

npm test

This will output verbose tests. If you prefer not to read passing test descriptions, prefer command:

npm run nyan

Scope the tests down from within a test file with a .only, eg

describe.only('this set of tests', () => {
    // the only tests you want to run
});

Select your preferred test profile, either:

  • Run all tests, or
  • Run Active UI tab test file.

Then hit F5.

You can use the .only modifier here as well. In that case, I find the Run all tests profile more convenient.


^ top ^

dev notes

The spec said not to spend more than 4 hours on this exercise. Because I have not worked much with encoding before, I read several articles about the differences between UTF-8, various UTF-16s, and UTF-32. At the end of this reading and after several experiments in the console, as far as I can tell:

  • Because JavaScript's String implementation is UCS-2 or UTF-16 and the predominant encoding of the web is UTF-8, it already handles automatically for replacing unknown or invalid unicode code points (& bytes representing such) with \uFFFD, the unicode replacement character, as part of the engine's on-the-fly UTF-8 <-> UTF-16 conversions.

So I have left the JavaScript engine to handle this part of the spec for me.

In all honesty, if you count my UTF research as part of the 4 hours, then the 4 hour mark was probably closer to this commit (ed1b8d92). At that point, all the base handling was in place. However, I had not yet connected the command line to the script. The last commit (2a52048e) took another 20-30 minutes of work -- roughly the same as what I had invested in learning about & tasting UTF flavors.

tooling notes

This was developed on Mac OS 10.14.2 with Node 11.4.0 and tested on the same OS with Node 8.0.0, 10.0.0, and 11.4.0. I've committed my launch.json so any other VSCode users would have an easy time running tests. Were this production code, I would only do this if VSCode were the recommended / preferred team IDE. For purposes of this coding challenge, I chose to consider it as such.


^ top ^