aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md33
1 files changed, 32 insertions, 1 deletions
diff --git a/README.md b/README.md
index 5711b57..c6dad42 100644
--- a/README.md
+++ b/README.md
@@ -35,6 +35,37 @@ YYYY.MM.DD[.CHANGESET][-FEATURE|-break]
+## Rules
+
+A version is a date, then an optional changeset, then at most one label: a feature or `-break`. Every valid version has exactly one spelling, so `toString()` gives back the string it was parsed from.
+
+- **Date**: `YYYY.MM.DD`, always 4 + 2 + 2 digits. The year runs from `0001` to `9999` and is zero-padded. It must be a real calendar date: `2024.02.29` is valid, but `2023.02.29` and `2024.04.31` aren't.
+- **Changeset**: `.N`, where `N` is a whole number from 1 to 9007199254740991 (`Number.MAX_SAFE_INTEGER`) with no leading zeros. Leave it out for 0, since `.0` and `.01` are rejected.
+- **Feature**: `-name`, where the name uses letters, digits and hyphens and contains at least one letter or digit (`2024.04.03--` is rejected).
+- **Breaking**: `-break`. A version is a feature or breaking, never both. `2024.04.03-ui-break` is the feature `ui-break`, and `-breaking` is a feature too.
+- Nothing follows the label, so `2024.04.03-feature.5` and `2024.04.03-break.1` are rejected. Put the changeset first: `2024.04.03.5-feature`.
+- `new ChronVer()` with no argument is today's version, but an empty string is invalid.
+
+### Ordering
+
+Versions compare by year, month, day, then changeset. When all four match, `-break` sorts after the version without it. Features are ignored, so `2024.04.03-a`, `2024.04.03-b` and `2024.04.03` are equal.
+
+```
+2024.04.03 < 2024.04.03-break < 2024.04.03.1 < 2024.04.03.1-break < 2024.04.04
+```
+
+### Incrementing
+
+`increment()` works from today's local date:
+
+- **Same day**: the changeset goes up by 1 (`2025.07.21.1` → `2025.07.21.2`).
+- **Earlier day**: today's version with no changeset (`2025.07.20.3` → `2025.07.21`).
+- **Later day**: it throws, because a version dated in the future can't be incremented.
+
+The result never keeps the feature or `-break`: `2025.07.21.1-break` becomes `2025.07.21.2` that day.
+
+
+
## Installation
### Deno
@@ -127,7 +158,7 @@ console.log(v2.isNewerThan(v1)); // true
// increment version
const incremented = version.increment();
-console.log(incremented.toString()); // "2024.07.19.1" (if same day)
+console.log(incremented.toString()); // "2025.07.21.1" (if same day)
```
### Static Methods