Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vm(inputVersion = '') {
- let [ major, minor, patch ] = inputVersion.split('.');
- let currentVersion = {
- major: major && parseInt(major, 10) || 0,
- minor: minor && parseInt(minor, 10) || 0,
- patch: patch && parseInt(patch, 10) || 1,
- };
- let previousVersion = null;
- this.release = () => {
- return `${currentVersion.major}.${currentVersion.minor}.${currentVersion.patch}`;
- }
- this.major = () => {
- previousVersion = { ...currentVersion };
- currentVersion.major += 1;
- currentVersion.minor = 0;
- currentVersion.patch = 0;
- return this;
- }
- this.minor = () => {
- previousVersion = { ...currentVersion };
- currentVersion.minor += 1;
- currentVersion.patch = 0;
- return this;
- }
- this.patch = () => {
- previousVersion = { ...currentVersion };
- currentVersion.patch += 1;
- return this;
- }
- this.rollback = () => {
- if (!Boolean(previousVersion)){
- throw new Error('Can`t rollback.')
- }
- currentVersion = { ...previousVersion };
- return this;
- }
- return this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement