|
3 | 3 |
|
4 | 4 | //// export
|
5 | 5 |
|
| 6 | +/** |
| 7 | + * The Chronologic Version parser. |
| 8 | + * |
| 9 | + * ```ts |
| 10 | + * import { ChronVer } from "jsr:@chronver/chronver"; |
| 11 | + * |
| 12 | + * // create new version |
| 13 | + * const version = new ChronVer("2024.04.03.1"); |
| 14 | + * |
| 15 | + * // convert to string |
| 16 | + * console.log(version.toString()); // "2024.04.03.1" |
| 17 | + * |
| 18 | + * // access version components |
| 19 | + * console.log(version.year); // 2024 |
| 20 | + * console.log(version.month); // 4 |
| 21 | + * console.log(version.day); // 3 |
| 22 | + * console.log(version.changeset); // 1 |
| 23 | + * ``` |
| 24 | + * |
| 25 | + * ### Validation |
| 26 | + * |
| 27 | + * ```ts |
| 28 | + * console.log(ChronVer.isValid("2024.04.03")); // true |
| 29 | + * console.log(ChronVer.isValid("invalid")); // false |
| 30 | + * console.log(ChronVer.isValid("2024.13.19")); // false (invalid month) |
| 31 | + * ``` |
| 32 | + * |
| 33 | + * ### Comparison |
| 34 | + * |
| 35 | + * ```ts |
| 36 | + * const v1 = "2024.04.03.1"; |
| 37 | + * const v2 = "2024.04.03.2"; |
| 38 | + * |
| 39 | + * console.log(ChronVer.compare(v1, v2)); // -1 (v1 is older than v2) |
| 40 | + * console.log(ChronVer.compare(v2, v1)); // 1 (v2 is newer than v1) |
| 41 | + * console.log(ChronVer.compare(v1, v1)); // 0 (versions are equal) |
| 42 | + * ``` |
| 43 | + * |
| 44 | + * ### Feature Branches and Breaking Changes |
| 45 | + * |
| 46 | + * ```ts |
| 47 | + * // feature branch |
| 48 | + * const feature = new ChronVer("2024.04.03-feature"); |
| 49 | + * console.log(feature.feature); // "feature" |
| 50 | + * console.log(feature.toString()); // "2024.04.03-feature" |
| 51 | + * |
| 52 | + * // breaking change |
| 53 | + * const breaking = new ChronVer("2024.04.03.1-break"); |
| 54 | + * console.log(breaking.isBreaking); // true |
| 55 | + * console.log(breaking.toString()); // "2024.04.03.1-break" |
| 56 | + * ``` |
| 57 | + */ |
6 | 58 | export class ChronVer {
|
7 | 59 | /** changeset number (0 if not specified) */
|
8 | 60 | readonly changeset: number;
|
|
0 commit comments