-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
12 changed files
with
119 additions
and
52 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
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,21 @@ | ||
import {base64Map} from "./base64Map.js"; | ||
|
||
/** | ||
* @private | ||
* @description Encodes a semVer-like version string for OS | ||
* @param {string} semVer Input is x.y | ||
* @return {string} A string built from 2 characters of the base64 table that encode the semVer | ||
*/ | ||
export function encodeOSVersion(semVer: string):string { | ||
const [major, minor] = semVer.split('.'); | ||
|
||
//convert to binary | ||
const binaryMajorVersion = parseInt(major).toString(2); | ||
const binaryMinorVersion = parseInt(minor).toString(2); | ||
|
||
//pad to 6 | ||
const paddedMajor = binaryMajorVersion.padStart(6, '0'); | ||
const paddedMinor = binaryMinorVersion.padStart(6, '0'); | ||
|
||
return base64Map[paddedMajor]+base64Map[paddedMinor]; | ||
} |
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
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,25 @@ | ||
import {stringPad} from "./stringPad.js"; | ||
|
||
/** | ||
* @private | ||
* @description Pads each segment with '0' so they have length of 2 | ||
* @param {string} semVer Input can be either x.y.z or x.y | ||
* @return {string} in the form of xx.yy.zz ( | ||
*/ | ||
export function padVersion(semVer: string): string { | ||
if (semVer.split('.').length < 2) { | ||
throw new Error('invalid semVer, must have at least two segments'); | ||
} | ||
|
||
// Split by '.', reverse, create new array with padded values and concat it together | ||
return semVer.split('.').map((segment) => { | ||
// try to cast to number | ||
const asNumber = +segment; | ||
|
||
if (isNaN(asNumber) || asNumber < 0) { | ||
throw 'Invalid version number provided'; | ||
} | ||
|
||
return stringPad(segment, 2, '0'); | ||
}).join('.'); | ||
} |
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