This is the backend for the t9 phoneword React frontend.
The API implements a number to word converter in the style of an old T9 mobile phone.
For example given the input 23 the output will be ad,ae,af,bd,be,bf,cd,ce,cf.
It uses "Brute Force" to do this - just iterating through all possible combinations.
Enhanced:
-
I have enhanced this to use prediction via a pre-loaded dictionary.
-
I use a prefix-tree (Trie) data structure to implement the word filtering
-
I use a file stream to read the dictionary.txt file
- Clone this repo
- In the project folder run npm install to install the package dependencies. Please check peer dependencies
- The code uses ECMAScript so please make sure that your node version is >= 14
- The API will run at localhost: 4000
- The API takes one query parameter called num which will be interpreted to text. For example: localhost:8000/?num=322
- API endpoint was tested with various values of the input parameter
- API endpoint tested directly in the URL bar
- Also tested using Postman
- Manual testing of the frontend
- Node.js
- Hapi.js
-
On installing Hapi through npm I got 5 high severity vulnerabilities. I checked the links for more info and it say that all versions of hapi are vulnerable to DOS due to the CORS request handler having a vulnerability.
-
I removed this package and installed @hapi/hapi ... this is "hapi-er"
- That I have a word list available (for now I have hardcoded this in a text file)
-
Only one word will be interpreted. If you enter multiple words separated by spaces this will not work.
-
This is not production ready in any way shape or form. It is a skeleton prototype to prove it works.
-
Not so much as a 404 is provided if anything goes wrong
-
The API could be extended to interpret full messages
-
Case sensitivity could be introduced
-
The word list could be provided by API, or database rather than hardcoded
-
For deployment it would need: Authorisation, Testing, caching, better error handling (Boom plugin) , validation, cookies, process monitoring (Good plugin)
-
env variables and API setup for production not considered here - just localhost.
-
The models folder should contain relevant schema (for database objects mapped to http GET/POST/PUT/DELETE)
-
Very basic testing has been performed this would need full testing.
-
My Trie class can implement auto-complete but this is not turned on.