UNPKG

rafale

Version:

Deploy every services, everywhere, in just a few seconds

1 lines 1.3 kB
"use strict";function reset(){shuffled=!1}function setCharacters(e){if(!e)return void(alphabet!==ORIGINAL&&(alphabet=ORIGINAL,reset()));if(e!==alphabet){if(e.length!==ORIGINAL.length)throw new Error("Custom alphabet for shortid must be "+ORIGINAL.length+" unique characters. You submitted "+e.length+" characters: "+e);var t=e.split("").filter(function(e,t,r){return t!==r.lastIndexOf(e)});if(t.length)throw new Error("Custom alphabet for shortid must be "+ORIGINAL.length+" unique characters. These characters were not unique: "+t.join(", "));alphabet=e,reset()}}function characters(e){return setCharacters(e),alphabet}function setSeed(e){randomFromSeed.seed(e),previousSeed!==e&&(reset(),previousSeed=e)}function shuffle(){alphabet||setCharacters(ORIGINAL);for(var e,t=alphabet.split(""),r=[],a=randomFromSeed.nextValue();t.length>0;)a=randomFromSeed.nextValue(),e=Math.floor(a*t.length),r.push(t.splice(e,1)[0]);return r.join("")}function getShuffled(){return shuffled?shuffled:shuffled=shuffle()}function lookup(e){var t=getShuffled();return t[e]}var randomFromSeed=require("./random/random-from-seed"),ORIGINAL="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_-",alphabet,previousSeed,shuffled;module.exports={characters:characters,seed:setSeed,lookup:lookup,shuffled:getShuffled};