A node cli tool text to hex example
So for todays post a node cli tool example from my on my node_cli_tools project I will be writing about a quick tool that I put together that can be used to convert a plain text file to a hex format. This kind of tool might come in handy when it comes to creating a collection of content that I want to store in a format that is not necessary encrypted, but is just in a format that is not human readable. The main use case is that I just want a simple tool that will convert markdown files for example into a format that just makes it so the content is not indexed by Google bot, but can easily be converted back to a plain text format.
1 - The node cli nc-hexer command basics
This is a post on my cd-hexer command that is part of my node_cli_tools project that can be found on my github account. This node cli tool depends on yargs which is one of several npm packages that make part of a stack that is the core of the project as a whole. So the code examples here will not work out of the box by just copying and parsing the code. If you want to reproduce what is going on here it would be best to clone done the project and install it globally.
2 - /bin/hexer/index.js
So each of my commands in the node_cli_tools projects has a bin folder in the root of the project folder. In the package.json file there is a bin key and that points to this file. This is why I am suing the nodejs shebang at the top of the file, as this is the first file to be called when the nc-hexer command is used.
3 - /bin/hexer/commands/default.js
Here I have the default.js file for the default command of the nc-hexer command. The target option can be used to set the file to convert to hex, and the output option can be used to set the file to save the hex format of the fine to. There is also the mode option that can be used to change from converting text to hex, and from hex back to text.
4 - /shared/lib/hexer/index.js
Here I have the actual hexer lib.
5 - Conclusion
So this project even as it currently stands serves the purpose that I had in mind, I just wanted a simple tool that converted plain text files into a from where it is just hex strings for each line with line breaks separating each line. The reason why is I just want to store text in a non human readable form, but a more advanced version might also preform better key-less obfuscation of text, and maybe even encryption.