Created
December 14, 2018 08:34
-
-
Save Insayt/e7b83a792bf9374ad38dc738d591fd06 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function getShortcodeFromTag (tag) { | |
let id = bigInt(tag.split('_', 1)[0]); | |
const alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_'; | |
let remainder; | |
let shortcode = ''; | |
while (id.greater(0)) { | |
let division = id.divmod(64); | |
id = division.quotient; | |
shortcode = `${alphabet.charAt(division.remainder)}${shortcode}`; | |
} | |
return shortcode; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment