https://github.com/chadnpc/clihelper.semver
PowerShell module for robust and type-safe Semantic Versioning.
https://github.com/chadnpc/clihelper.semver
powershell semver
Last synced: 11 months ago
JSON representation
PowerShell module for robust and type-safe Semantic Versioning.
- Host: GitHub
- URL: https://github.com/chadnpc/clihelper.semver
- Owner: chadnpc
- License: wtfpl
- Created: 2025-03-06T19:08:08.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-03-06T19:45:08.000Z (12 months ago)
- Last Synced: 2025-03-06T20:27:50.515Z (12 months ago)
- Topics: powershell, semver
- Language: PowerShell
- Homepage: https://www.powershellgallery.com/packages/cliHelper.semver
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## [cliHelper.semver](https://www.powershellgallery.com/packages/cliHelper.semver)
PowerShell module for robust and type-safe [Semantic Versioning](https://github.com/semver/semver).
[](https://github.com/chadnpc/cliHelper.semver/actions/workflows/build_module.yaml)
[](https://www.powershellgallery.com/packages/cliHelper.semver)
## Usage
First:
```PowerShell
Install-Module cliHelper.semver
Import-Module cliHelper.semver
```
Once imported,
- **Create version Objects**
```PowerShell
# You can create [Semanticver] objects in a few ways:
#+ 1. Using `New-SemanticVersion` with a version string:
$version = New-SemanticVersion -VersionString "1.2.3-alpha+build123"
$version
#Output:
#goes here
#
# + 2. Using `New-SemanticVersion` with individual components:**
$version = New-SemanticVersion -Major 2 -Minor 0 -Patch 0 -PreRelease "rc.2"
$version
#Output:
#goes here
#+3. Using `ConvertTo-SemanticVersion` from a string:**
$versionString = "3.1.4+meta.info"
$version = ConvertTo-SemanticVersion -InputObject $versionString
$version
```
- **Validate Semantic Versions**
```PowerShell
Test-SemanticVersion -VersionString "1.5.0"
# Output: True
Test-SemanticVersion -VersionString "invalid-version-format"
# Output: False
```
- **Increment Version Components**
```PowerShell
$version = New-SemanticVersion -VersionString "1.2.3-beta"
$incrementedVersion = Step-SemanticVersion -Version $version -Component Minor
$incrementedVersion
```
You can increment `Major`, `Minor`, `Patch`, `PreReleaseIdentifier`, or `BuildMetadata` components.
- **Retrieve individual components**
```PowerShell
$version = New-SemanticVersion -VersionString "2.5.7-rc.1+build.99"
Get-SemanticVersionComponent -Version $version -Component PreReleaseIdentifier
# Output: rc.1
Get-SemanticVersionComponent -Version $version -Component Major
# Output: 2
```
- **Compare versions**
```PowerShell
$version1 = New-SemanticVersion -VersionString "1.0.0-alpha"
$version2 = New-SemanticVersion -VersionString "1.0.0-beta"
$comparisonResult = Compare-SemanticVersion -ReferenceVersion $version1 -DifferenceVersion $version2
$comparisonResult
```
This will output `Lower`, `Equal`, or `Higher` based on SemVer precedence rules.
## License
This project is licensed under the [WTFPL License](LICENSE).