UNPKG

vite-plugin-vue-css-modules

Version:

✨ Ultimate solution for using CSS modules without any hassle. Automatic replacement for Vue templates and scripts

35 lines (34 loc) 1.05 kB
export default function ({ alphabet, lastId = "" }) { let digitsArray; const maxDigit = alphabet.length - 1; function nextId() { for (var i = 0; i < digitsArray.length; i += 1) { if (digitsArray[i] === maxDigit) { digitsArray[i] = 0; continue; } digitsArray[i]++; break; } if (i === digitsArray.length) { digitsArray.push(0); } return nextId.lastId; } Object.defineProperty(nextId, "lastId", { get() { return digitsArray.map(digit => alphabet[digit]).join(""); }, set(idString) { digitsArray = [...idString].map(char => { const digit = alphabet.indexOf(char); if (digit === -1) { throw new RangeError(`Character '${char}' is not in the alphabet "${alphabet}"`); } return digit; }); }, }); nextId.lastId = lastId; return nextId; }