summaryrefslogtreecommitdiff
path: root/static/js/slug.js
blob: f82635c66ff7cc9dbcb67622910713a0d70aad18 (plain)
1
2
3
4
5
6
7
8
9
10
function generateSlug (len = 5) {
    const ALPHA_SIZE = 36;
    const MIN = 36**(len-1);
    const MAX = 36**len;
    const slugNumeric = Math.floor(Math.random() * (MAX-MIN))+MIN;
    return slugNumeric.toString(ALPHA_SIZE);
}

if (typeof module !== 'undefined')
    module.exports = {generateSlug};