Given an integer input var i = 1234567890
based on the output of a hash function, I need to create a shortened, case sensitive alphanumeric string. This is for purposes of having a short URL with a case-sensitive hashed parameter such as http://example.com/?hash=1M0nlPk
.
JavaScript's i.toString(36)
would use characters 0-9 and a-z. That's part of the way to a solution. However, I need to operate on a character set of unknown or configureable length, e.g. 012abcABC
. How could I convert an int to a string consisting only of this character set?
UPDATE: I have improved the wording of this question. It is not a duplicate of Fastest way to convert a number to radix 64 in JavaScript? because the character set is arbitrary. Some of the answers in that question may be adaptable to this question, but I believe it to be a fundamentally different question.