Skip to content

Instantly share code, notes, and snippets.

@Insayt
Created December 14, 2018 08:34
Show Gist options
  • Save Insayt/e7b83a792bf9374ad38dc738d591fd06 to your computer and use it in GitHub Desktop.
Save Insayt/e7b83a792bf9374ad38dc738d591fd06 to your computer and use it in GitHub Desktop.
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