1.0.2 • Published 4 years ago
@alexspirgel/normalize-elements v1.0.2
Normalize Elements
A utility function that returns an array of element references from a variety of argument types.
Valid argument types include:
- element reference
- css selector string
- query selectors (
document.querySelector,document.querySelectorAll, or any node list) - an array including any combination of the above
Installation
Using NPM:
npm install @alexspirgel/normalize-elementsconst normalizeElements = require('@alexspirgel/normalize-elements');Usage
let elements = normalizeElements(document.body); // element reference
let elements = normalizeElements('.example-selector'); // css selector string
let elements = normalizeElements(document.querySelectorAll('.another-selector')); // query selector (node list)
let elements = normalizeElements([ // an array including any combination of the above.
document.body,
'.example-selector',
document.querySelectorAll('.another-selector')
]);