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

Function parseVersion

scripts/website.js:190–215  ·  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

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