Skip to content

Commit ec326fb

Browse files
Merge branch 'v2.3.0-readme'
2 parents e3035ef + 6f48468 commit ec326fb

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

README.md

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,12 @@
44
A Semantic Version Library for .Net
55
===================================
66

7-
This library implements the `SemVersion` class, which
8-
complies with v2.0.0 of the spec from [semver.org](http://semver.org).
7+
Create, parse, and manipulate semantic version numbers with the `SemVersion` class and semantic
8+
version ranges with the `SemVersionRange` class. This library complies with v2.0.0 of the semantic
9+
versioning spec from [semver.org](http://semver.org).
910

1011
API docs for the most recent release are available online at [semver-nuget.org](https://semver-nuget.org/).
1112

12-
## Installation
13-
14-
With the NuGet console:
15-
16-
```powershell
17-
Install-Package semver
18-
```
19-
2013
## Parsing
2114

2215
```csharp
@@ -65,3 +58,29 @@ Current: 1.1.0-rc.1+nightly.2345
6558
Prerelease: rc.1
6659
Next release version is: 1.1.0
6760
```
61+
62+
## Version Ranges
63+
64+
```csharp
65+
var range = SemVersionRange.Parse("^1.0.0");
66+
var prereleaseRange = SemVersionRange.ParseNpm("^1.0.0", includeAllPrerelease: true);
67+
Console.WriteLine($"Range: {range}");
68+
Console.WriteLine($"Prerelease range: {prereleaseRange}");
69+
Console.WriteLine($"Range includes version {version}: {range.Contains(version)}");
70+
Console.WriteLine($"Prerelease range includes version {version}: {prereleaseRange.Contains(version)}");
71+
72+
// Alternative: another way to call SemVersionRange.Contains(version)
73+
version.Satisfies(range);
74+
75+
// Alternative: slower because it parses the range on every call
76+
version.SatisfiesNpm("^1.0.0", includeAllPrerelease: true)
77+
```
78+
79+
Outputs:
80+
81+
```text
82+
Range: 1.*
83+
Prerelease range: *-* 1.*
84+
Range includes version 1.1.0-rc.1+e471d15: False
85+
Prerelease range includes version 1.1.0-rc.1+e471d15: True
86+
```

0 commit comments

Comments
 (0)