I’m thinking about using the encode/decode technique here (Encoding to base 36/decoding from base 36 is simple in Ruby)
how to implement a short url like urls in twitter?
Idea being to track user referrals, invite URLs. I can use Rails to decode, but it there a way to encode with Javascript or jQuery?
The
toStringmethod onNumberhas an optional argument of radix:Note this doesn’t work, because numbers expect decimal digits after a period, not letters:
Also, you can decode with JS as well:
EDIT:
The easiest is to reduce the base by number of characters you’re skipping, then make a translation: Note that only one of
1-lor0-Ois a problem, since base36 encodes only lowercase (in which case you have1-l, but not0-O) which you can make uppercase (in which case, vice versa).If you want to have a base larger than 36, you would have to have your own base-changing function, as 36 is as high as
toStringsupports. In that case, it is easy enough to make your own digit inventory as you want.Go ahead 🙂 Note the
nsuffix that turns the number intoBigInt: