Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

makeup-next-id

Package Overview
Dependencies
Maintainers
5
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

makeup-next-id - npm Package Compare versions

Comparing version 0.0.3 to 0.1.0

15

index.js
'use strict';
var nanoid = require('nanoid');
var sequenceMap = {};
var defaultPrefix = 'nid';
var randomPortion = nanoid(3);
module.exports = function (el) {
var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultPrefix;
// join first prefix with random portion to create key
var key = "".concat(prefix).concat(randomPortion); // initialise key in sequence map if necessary
// prevent empty string
var _prefix = prefix === '' ? defaultPrefix : prefix; // initialise prefix in sequence map if necessary
sequenceMap[key] = sequenceMap[key] || 0;
sequenceMap[_prefix] = sequenceMap[_prefix] || 0;
if (!el.id) {
el.setAttribute('id', "".concat(_prefix, "-").concat(sequenceMap[_prefix]++));
el.setAttribute('id', "".concat(key, "-").concat(sequenceMap[key]++));
}
return el.id;
};

7

package.json
{
"name": "makeup-next-id",
"description": "Assign the next id in sequence to an element, if an id property does not already exist.",
"version": "0.0.3",
"version": "0.1.0",
"main": "index.js",

@@ -33,2 +33,5 @@ "repository": "https://github.com/makeup-js/makeup-next-id.git",

],
"dependencies": {
"nanoid": "^2"
},
"devDependencies": {

@@ -51,3 +54,3 @@ "@babel/cli": "^7",

"lasso-cli": "^2",
"onchange": "^5",
"onchange": "^6",
"parallelshell": "^3",

@@ -54,0 +57,0 @@ "puppeteer": "^1",

@@ -10,3 +10,3 @@ # makeup-next-id

Assigns the next id in sequence to an element, if an id property does not already exist.
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. If you need a <em>known</em> id, ahead of time, please use a different approach!

@@ -40,3 +40,3 @@ A vanilla JavaScript port of <a href="https://github.com/ianmcburnie/jquery-next-id">jquery-next-id</a>.

widgets.forEach(function(el) {
nextId(el, 'widget');
nextId(el);
});

@@ -56,5 +56,5 @@ ```

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

@@ -66,6 +66,2 @@

## Dependencies
* None
## Polyfills

@@ -72,0 +68,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc