MCPcopy Create free account
hub / github.com/Automattic/mongoose / parseVersion

Function parseVersion

scripts/website.js:191–216  ·  view source on GitHub ↗

* Parse a given semver version string to a number array * @param {string} str The string to parse * @returns number array or undefined

(str)

Source from the content-addressed store, hash-verified

189 * @returns number array or undefined
190 */
191function parseVersion(str) {
192 // there is no ending "$", because of "rc"-like versions
193 const versionReg = /^v?(\d+)\.(\d+)\.(\d+)/i;
194
195 const match = versionReg.exec(str);
196
197 if (match) {
198 const parsed = [parseInt(match[1]), parseInt(match[2]), parseInt(match[3])];
199
200 // fallback just in case some number did not parse
201 if (Number.isNaN(parsed[0]) || Number.isNaN(parsed[1]) || Number.isNaN(parsed[2])) {
202 console.log(`some version was matched but did not parse to int! "${str}"`);
203 return undefined;
204 }
205 return parsed;
206 }
207
208 // special case, to not log a warning
209 if (str === 'test') {
210 return undefined;
211 }
212
213 console.log(`Failed to parse version! got: ${str}`);
214
215 return undefined;
216}
217
218/**
219 * Get versions from git tags and put them into {@link filteredTags}

Callers 1

getCurrentVersionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected