Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate unique alphanumeric incrementing string keys
#!/usr/bin/env node
var base_str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_";
console.log( number_to_base(process.argv[2], base_str) );
function number_to_base(n, str) {
if ( n === 0 ) return "0";
var b = '';
while ( n > 0 ) {
b = str[n%str.length] + b;
n = Math.floor(n / str.length);
}
return b;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment