Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rwalle61/numbers-to-words
https://github.com/rwalle61/numbers-to-words
Last synced: 21 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/rwalle61/numbers-to-words
- Owner: rwalle61
- Created: 2023-02-04T17:57:36.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2023-02-09T19:06:14.000Z (almost 2 years ago)
- Last Synced: 2024-10-06T02:22:35.758Z (3 months ago)
- Language: TypeScript
- Size: 85 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Numbers to words
A command-line interface (CLI) tool that takes an integer from 0 to 100,000 and converts it into grammatically correct
English words.## Pre-requisties
### Install Node.js
I tested with Node 14, 16 & 19. On Mac, `brew install node`
### Install package manager
I've used `yarn` but `npm` would work too.
`npm` comes with node.
Install yarn: `npm install --global yarn`
### Install dependencies
`yarn` / `npm install`
### Build executable
`yarn build` / `npm build`
## Run
### Success
```bash
> ./bin/numbers-to-words 52
fifty-two
```### Error
```bash
> ./bin/numbers-to-words -1
...
Error: Arg must be between 0-100000
...
```## Tests
`yarn test`
## Notes & Decisions
- behaviour
- matches spec exactly (see `e2e-test.ts` and acceptance tests in `numberToWords.test.ts`)
- standard streams: stdout and stderr
- exit codes: 0 on success, 1 on failure- structure
- flow: `index.ts` -> controller -> parse input -> invoke use case -> output
- Separated business logic (use case) from CLI-specific details (controller and adapters) so they can change independently (e.g. can run this on the cloud instead of CLI without changing core logic)
- minimal abstraction (besides separating concerns) so easy to extend
- functional programming instead of OOP as there is no need to store state
- no external libraries (e.g. [`commander`](https://www.npmjs.com/package/commander)) because simpler
- I used `node` and `TypeScript` because it works well for this problem, I'm familiar with them, and TypeScript provides good compile-time type-safety- testing
- developed using TDD (see commits)
- full unit tests (put next to source files so easy to edit together)
- e2e tests used as they run quickly and are the only full integration tests