Files
react-native/scripts/version-utils.js
T
Luna Wei cc1e3abb6e Extract version parsing from release script
Summary: Changelog: [Internal] - extract logic for parsing version in bump-oss-version and add tests

Reviewed By: cortinico

Differential Revision: D32196238

fbshipit-source-id: 6ea7af3d282eea1d876118f056bca94a151e6182
2021-11-05 15:09:11 -07:00

29 lines
590 B
JavaScript

/**
* 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
*/
function parseVersion(version) {
const match = version.match(/^(\d+)\.(\d+)\.(\d+)(?:-(.+))?$/);
if (!match) {
throw new Error(
`You must pass a correctly formatted version; couldn't parse ${version}`,
);
}
const [, major, minor, patch, prerelease] = match;
return {
major,
minor,
patch,
prerelease,
};
}
module.exports = {
parseVersion,
};