UNPKG

@sumor/short-id

Version:

This is a short-id library for Node.js and the browser. You can easily use it to generate a short id from number.

13 lines (12 loc) 285 B
export default (number, rule) => { const chars = rule.split('') const radix = chars.length let qutient = +number const arr = [] do { const mod = qutient % radix qutient = (qutient - mod) / radix arr.unshift(chars[mod]) } while (qutient) return arr.join('') }