I live in London, UK 🏡
This is yet another post from me on a tiny but a very useful tool. Last time, I have written about SqlLocalDB.exe Utility Tool which is a command-line tool to manage SQL Server Express LocalDB instances. Today, I want to tell you about node-semver, a SemVer 2.0.0 parser command-line tool and a node.js library (the one that npm uses). I am huge fan of SemVer. You cannot imagine how many places you can you use semantic versioning to make the internal and external communication easy for your software product. I plan to write more about a few different cases I figured out.
Going back to our topic, the acquisition of this tool is amazingly simple. You basically install this as a global npm package by running "npm install semver -g" and from there, you have access to semver command everywhere.
There are a lot of great things you can do with this but I will give you a few of the basic and useful samples. First useful thing I noticed was the ability to validate a string against a SemVer 2.0.0 spec.
If the validation fails, it exists with non-zero exit code.
You can also increment a version:
By default, it increments the patch version but you can customize this if you want:
One useful feature that I have been using is to giving bunch of string values to node-semver and getting back the valid semantic version strings back:
Notice that it doesn't only sanitize the input, it also orders the versions on the standard output which is very convenient. I have an upcoming blog post where I will show you how I leverage this feature and a few others for a legitimate use case.
Lastly, I want to give you an example on its range feature which allows you to check if a version (or which versions if multiple versions are given) satisfies a range check:
So, did you like it? I hear you screaming "YES!" :) So, go spread this amazing tiny utility by sharing this blog post. There are more but these examples should be enough to give you an idea.
I live in London, UK 🏡