2021-11-06 01:07:02 +03:00
|
|
|
/**
|
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
|
|
|
*
|
|
|
|
* @format
|
|
|
|
*/
|
|
|
|
|
2021-11-06 01:07:02 +03:00
|
|
|
function parseVersion(versionStr) {
|
|
|
|
const match = versionStr.match(/^v?((\d+)\.(\d+)\.(\d+)(?:-(.+))?)$/);
|
2021-11-06 01:07:02 +03:00
|
|
|
if (!match) {
|
|
|
|
throw new Error(
|
2021-11-06 01:07:02 +03:00
|
|
|
`You must pass a correctly formatted version; couldn't parse ${versionStr}`,
|
2021-11-06 01:07:02 +03:00
|
|
|
);
|
|
|
|
}
|
2021-11-06 01:07:02 +03:00
|
|
|
const [, version, major, minor, patch, prerelease] = match;
|
2021-11-06 01:07:02 +03:00
|
|
|
return {
|
2021-11-06 01:07:02 +03:00
|
|
|
version,
|
2021-11-06 01:07:02 +03:00
|
|
|
major,
|
|
|
|
minor,
|
|
|
|
patch,
|
|
|
|
prerelease,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
parseVersion,
|
|
|
|
};
|