-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2c0dc8f
commit c508e91
Showing
3 changed files
with
105 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export class Version { | ||
constructor(string) { | ||
const [major, minor, patch] = string.split("."); | ||
this.major = parseInt(major); | ||
this.minor = parseInt(minor); | ||
this.patch = parseInt(patch); | ||
} | ||
|
||
toString() { | ||
return `${this.major}.${this.minor}.${this.patch}`; | ||
} | ||
|
||
greaterOrEqualThan(version) { | ||
return ( | ||
this.major >= version.major || | ||
(this.major === version.major && | ||
(this.minor >= version.minor || | ||
(this.minor === version.minor && this.patch >= version.patch))) | ||
); | ||
} | ||
|
||
lessOrEqualThan(version) { | ||
return ( | ||
this.major <= version.major || | ||
(this.major === version.major && | ||
(this.minor <= version.minor || | ||
(this.minor === version.minor && this.patch <= version.patch))) | ||
); | ||
} | ||
|
||
isBetween(version1, version2) { | ||
return this.greaterOrEqualThan(version1) && this.lessOrEqualThan(version2); | ||
} | ||
} | ||
|
||
export function compatible(type, version) { | ||
const minV = new Version(type.MIN_VERSION); | ||
const maxV = new Version(type.MAX_VERSION); | ||
|
||
const v = new Version(version); | ||
|
||
return v.isBetween(minV, maxV); | ||
} |