mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
cc1e3abb6e
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
29 lines
590 B
JavaScript
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,
|
|
};
|