MCPcopy
hub / github.com/sindresorhus/np / setFrom

Method setFrom

source/version.js:83–104  ·  view source on GitHub ↗

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 = ''} = {})

Source from the content-addressed store, hash-verified

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.

Callers 6

filterFunction · 0.95
constructorMethod · 0.95
releaseTaskHelperFunction · 0.80
uiFunction · 0.80
taskFunction · 0.80
version.jsFile · 0.80

Calls 5

toStringMethod · 0.95
#trySetVersionMethod · 0.95
isSemVersionIncrementFunction · 0.85
isInvalidSemVersionFunction · 0.85

Tested by

no test coverage detected