Sets a new version based on `input`. If `input` is a valid `SemVer` increment, the current version will be incremented by that amount. If `input` is a valid `SemVer` version, the current version will be set to `input` if it is greater than the current version. @param {string | SemVerIncrement} inp
(input, {prereleasePrefix = ''} = {})
| 81 | @throws If `input` is not a valid `SemVer` version or increment, or if `input` is a valid `SemVer` version but is not greater than the current version. |
| 82 | */ |
| 83 | setFrom(input, {prereleasePrefix = ''} = {}) { |
| 84 | this.#prereleasePrefix ??= prereleasePrefix; |
| 85 | const previousVersion = this.toString(); |
| 86 | |
| 87 | if (isSemVersionIncrement(input)) { |
| 88 | this.#version.inc(input, this.#prereleasePrefix); |
| 89 | } else { |
| 90 | if (isInvalidSemVersion(input)) { |
| 91 | throw new Error(`New version ${input} should either be one of ${SEMVER_INCREMENTS_LIST}, or a valid SemVer version.`); |
| 92 | } |
| 93 | |
| 94 | if (this.#isGreaterThanOrEqualTo(input)) { |
| 95 | throw new Error(`New version ${input} should be higher than current version ${this.toString()}.`); |
| 96 | } |
| 97 | |
| 98 | this.#trySetVersion(input); |
| 99 | } |
| 100 | |
| 101 | // Set `this.#diff` to format version diffs |
| 102 | this.#diff = semver.diff(previousVersion, this.#version); |
| 103 | return this; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | Formats the current version with `options.color`, pretty-printing the version's diff with `options.diffColor` if possible. |
no test coverage detected