separated-attributes
Very simple NPM package for working with separated attributes in HTML, e.g., class="hello world"
-> { class: ['hello', 'world'] }
.
Installation
npm install --save separated-attributes
or
yarn add separated-attributes
Usage
const separatedAttributes = ; // for getting attributes, see Potent Tools: https://github.com/gburtini/Potent-Tools-for-XPathconst attributes = ;/* { class: 'a b c', name: 'bob' }*/ const parsedAttributes = separatedAttributes;console;/* { class: ['a', 'b', 'c'], name: 'bob' }*/
Methods
isSeparatedAttribute(attributeName)
: returns a truthy separator for attributeName orfalse
if this is not a separated attribute.splitAttribute(name, value)
: splitsvalue
based on the rule for attributes calledname
, e.g., classes split on spaces, media queries split on commas, styles split on semicolons.splitAttributes(map)
: splits all the attributes in the map, using their key as their name.