@pdftron/webviewer-react-toolkit
Version:
A React component library for integrating with PDFTron WebViewer API.
23 lines (22 loc) • 719 B
JavaScript
var currentId = 0;
/**
* Generates a sequential string to use as a unique identifier. This should be
* used over `getId` if you need to use it as a DOM id, or a React key.
*
* @param prefix Optional. Prefix for the string id.
*/
export function getStringId(prefix) {
if (prefix === void 0) { prefix = 'id'; }
return prefix + "_" + (currentId++).toString(16);
}
/**
* Returns a Symbol to uniquely identify something. Will fallback to using
* string.
*
* @param description Description of the Symbol. Used as string prefix if not supported.
*/
export function getId(description) {
if (typeof Symbol === 'function')
return Symbol(description);
return description + "_" + getStringId();
}