makeup-next-id

0.4.1 • Public • Published

makeup-next-id

Assigns the next id in sequence to an element, if an id property does not already exist.

The id will consist of a configurable prefix (default: 'nid'), followed by three randomly generated chars, then a number in sequence. For example: nid-sdv-1, nid-sdv-2, nid-sdv-3, etc.

Experimental

This module is still in an experimental state, until it reaches v1 you must consider all minor releases as breaking changes.

Example

// import the module
import nextId from 'makeup-next-id';

// get NodeList
const widgetEls = document.querySelectorAll('.widget');

// assign next id to each element
widgetEls.forEach((el) => nextId(el));

Markup before:

<div class="widget"></div>
<div class="widget"></div>
<div class="widget"></div>

Markup after:

<div class="widget" id="nid-tCa-1"></div>
<div class="widget" id="nid-tCa-2"></div>
<div class="widget" id="nid-tCa-3"></div>

Custom Events

  • None

Dependencies

Polyfills

  • None

Package Sidebar

Install

npm i makeup-next-id

Weekly Downloads

320

Version

0.4.1

License

MIT

Unpacked Size

5.53 kB

Total Files

7

Last publish

Collaborators

  • saiponnada
  • lulavalva
  • artblue
  • dylanpiercey
  • sendlo
  • ianmcburnie
  • agliga