Socket
Book a DemoInstallSign in
Socket

generate_dom_id

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate_dom_id

Generate ids for html code

latest
Source
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

generate_dom_id

This module facilitates generate ids for dom elements

Getting Started

Installing

 npm install generate_dom_id@latest -S

Examples

  const GenerateDomId = require('../generate_dom_id');

  var gen = new GenerateDomId('main');

  gen.inc();
  // <input id=main_1_1 type="text" /><label for="main_1_1"></label>
  // <input id=main_1_2 type="text" /><label for="main_1_2">
  console.log(blockA(gen.getSub()));

  gen.inc();
  // <div id=main_2_1>
  //  <p id=main_2_2>Hello world</p>
  // </div>
  console.log(blockB(gen.getSub()));

  gen.inc();
  // main_3_1
  console.log(blockC(gen.getSub()));

  function blockA(gen) {
    var html = '';
    for (var i = 0; i < 100; i++) {
      var id = gen.inc();
      html +=
        '<input id='+id+' type="text" />'+
        '<label for="'+id+'"></label>';
    }
    return html;
  }


  function blockB(gen) {
    var html =
    `<div id=${gen}>
      <p id=${gen}>Hello world</p>
     </div>`;
    return html;
  }


  function blockC(gen) {
    var id = gen.inc();
    var html =
    `<div>
        <button id=${gen}>Remove</button>
     </div>`;
    return id;
  }

Running the tests

 npm run test

Keywords

id for DOM

FAQs

Package last updated on 17 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.