If you’re a dev, you probably come along timestamps a lot. They’re great to save datetime but horrible to read. Ladies and gentlemen, I decided to take 10 minutes of my time to save a lot more — and hopefully save you some to!
Wanna test it along the article? simply
npm install timestamp-cmd -g or check it out there timestamp-cmd.
Commander helps you build the structure of your command-line tool by setting up flags and automatically parsing arguments.
You can then simply add functions and output the data you want depending on the parameters you got!
I’ve set up 2 flags, one for the language
-l and one for the format
Then I thought it would be cool to actually store some settings that the user would set for himself.
I simply made a config.json file (and a default.config.json) in which one I would simply update the user config.
In order to dynamically update it I added 2 new flags in uppercase for long time use of the previous flags : language
-L and format
I also made it possible to reset the configuration to the default one via a simple flag
So far you’ve seen me using
ts [timestamp] plus some flags. But it would work that way if I hadn’t added something to my package.json : the bin property.
It simply makes your package executable. You can either set the file path (to it would use your package name) or give it an object with as the key your command name and the file path as value.
Check out the npm doc for more information : Bin Property.
Feel free to install the lib
npm install timestamp-cmd -g and share the love by recommending this to your community & friends with a upvote!
Follow me, I don’t mind.