Socket
Socket
Sign inDemoInstall

generate_dom_id

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    generate_dom_id

Generate ids for html code


Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Install size
3.43 kB
Created
Weekly downloads
 

Readme

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

FAQs

Last updated on 17 Sep 2018

Did you know?

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc