@ulu/frontend
Version:
A framework-agnostic frontend toolkit providing a modular, tree-shakable library of accessible components and utilities. Designed for seamless integration, it features a highly configurable SCSS system for any environment and vanilla JavaScript modules op
22 lines (19 loc) • 342 B
JavaScript
/**
* @module utils/id
*/
let idCount = 0;
/**
* Create new uid
*/
export function newId() {
return `ulu-uid-${ ++idCount }`;
}
/**
* Sets an ID if element doesn't have one vie newUid
* @param {Node} element Element to make sure has an id
*/
export function ensureId(element) {
if (!element.id) {
element.id = newId();
}
}