@mapcss/preset-svg
Version:
SVG as CSS for MapCSS
15 lines (14 loc) • 577 B
JavaScript
import { random } from "./random.js";
import { urlAlphabet } from "./urlAlphabet.js";
export const nanoid = (size = 21) => {
let id = "";
const bytes = random(size);
// Compact alternative for `for (var i = 0; i < size; i++)`
// We can’t use bytes bigger than the alphabet. 63 is 00111111 bitmask.
// This mask reduces random byte 0-255 to 0-63 values.
// There is no need in `|| ''` and `* 1.6` hacks in here,
// because bitmask trim bytes exact to alphabet size.
while (size--)
id += urlAlphabet[bytes[size] & 63];
return id;
};