I've created a node.js CLI Tool that converts a users number input into grammatically correct English words (within a range of 0 to 100,000).
Clone this repository to your machine.
Run the below command to install the CLI tool globally (ie you can call the command from any directory on your computer's terminal). BUT, if you'd prefer to call this command within this projects directory only, then instead skip to step 2.b.
npm install -g .
Type the following command in your terminal to run the CLI tool:
numbers-to-words 99999
Please note: if you did not install this CLI tool globally (as per step 1 above) then from the root directory of the project, run the following command in your terminal instead.
npx num-to-words-cli 99999
ninety nine thousand, nine hundred and ninety-nine
From the projects root directory, run the following command to execute the unit tests:
npm run test
I have addressed the following in my code:
Done | Requirement | Evidence |
---|---|---|
[x] | Tests | link & screenshot |
[x] | Documentation | link |
[x] | Error handling | link & link |
[x] | Use of exit codes | link |
I enjoyed the challenge of coding this, especially around:
- learning/researching how to build a CLI tool
- using functional programming and the right data structures, algorithms, and helper functions to ensure the code was clean, aspects of it were reusable, and reflected good software engineering principles
- using a TDD approach (i.e. I wrote my unit tests first and then from there I coded out the functionaility)
I feel my coding approach demonstrates extensibility as e.g.:
- tried to avoid using hard-coded text as part of the algorithms
- aimed for dynamic variables as much as possible, with readability in mind when naming them
- wrote loosely coupled code, so that functionality could be extended (rather than having to re-write blocks of code)
- wrote unit tests (I used a TDD approach)
- wrote pure functions, where I could (i.e. reusable blocks of code)
- tried to incorporate good software engineering principles e.g. D-R-Y, K-I-S-S, etc etc
Future Enhancements:
- refactor the code in
index.js
by abstracting out the helper function code blocks (when I tried moving them to theutils.js
file, I would get a circular dependency error) - add e.g. github actions as part of the CI/CD pipeline so that it can run various automated checks as part of the build
- install fun npm packages to add a cool UI to the CLI tool (to better enhance the users' experience) e.g. with chalk or boxen
I hope you enjoy using it!
Best wishes, Cynthia