UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

17 lines (16 loc) 621 B
const SEQUENCE_KEY = Symbol.for('__esl_sequences'); const sequenceHost = globalThis; const sequences = sequenceHost[SEQUENCE_KEY] || new Map(); sequenceHost[SEQUENCE_KEY] = sequences; /** Create and return sequential id */ export const sequentialUID = (name, prefix = name) => { const uid = (sequences.get(name) || 0) + 1; sequences.set(name, uid); return prefix + uid; }; /** Return random unique identifier */ export const randUID = (prefix = '') => { const time = Date.now().toString(32); const rand = Math.round(Math.random() * 1024 * 1024).toString(32); return prefix + time + '-' + rand; };