makeup-next-id
Advanced tools
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; | ||
}; |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
274705
20
1
90
+ Addednanoid@^2
+ Addednanoid@2.1.11(transitive)