Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
18 lines (14 sloc) 444 Bytes
const base = chars => {
const max = chars.length
const baseLoop = (num, res='') => {
const mod = num % max
const remaining = Math.floor(num / max)
const c = chars[mod] + res
return (remaining <= 0) ? c : baseLoop(remaining, c)
}
return baseLoop
}
const _chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
base.safe64 = base(`${_chars}-_`)
base.base64 = base(`${_chars}+/`)
module.exports = base