A simple CLI app based on Node.js that determines whether a given version is a pre-release version using semver.
- Detects pre-release versions (e.g.,
1.0.0-alpha.1,2.0.0-beta.3) - Returns exit codes for easy CI/CD integration
- Zero configuration required
- Node.js
^20.11 || ^22 || >=24
npm i -D @kurone-kito/is-prereleaseis-prerelease <version> [pre]| Argument | Required | Description |
|---|---|---|
version |
Yes | The version string to check (JSON format, e.g., "1.0.0" or "1.0.0-alpha.1") |
pre |
No | If provided, the command expects a pre-release version |
| Condition | Exit Code |
|---|---|
Pre-release version and pre argument provided |
0 (success) |
Stable version and pre argument not provided |
0 (success) |
| Otherwise | 1 (failure) |
# Returns exit code 0 if pre-release
is-prerelease '"1.0.0-alpha.1"' pre
# Returns exit code 0 if stable release
is-prerelease '"1.0.0"'{
"scripts": {
"is:prerelease": "is-prerelease $(npm pkg get version) pre",
"is:release": "is-prerelease $(npm pkg get version)"
}
}Note:
npm pkg get versionoutputs a JSON-formatted string (e.g.,"1.0.0"), which is the expected input format.
# Publish to npm only if it's a pre-release version
if npm run is:prerelease; then
npm publish --tag next
fi
# Publish to npm only if it's a stable release
if npm run is:release; then
npm publish --tag latest
fiThis CLI uses the prerelease() function from the
semver package to detect
pre-release identifiers in version strings.
1.0.0β Stable release (no pre-release identifier)1.0.0-alpha.1β Pre-release (identifier:['alpha', 1])2.0.0-beta.3β Pre-release (identifier:['beta', 3])
Welcome to contribute to this repository! For more details, please refer to CONTRIBUTING.md.