Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

separated-attributes

gburtini3MIT1.0.1

Methods for handling separated HTML attributes.

readme

separated-attributes

Build Status Known Vulnerabilities npm version

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 = require('separated-attributes');

// for getting attributes, see Potent Tools: https://github.com/gburtini/Potent-Tools-for-XPath
const attributes = getAttributes(domElement);
/*
 {
   class: 'a b c',
   name: 'bob'
 }
*/

const parsedAttributes = separatedAttributes.splitAttributes(attributes);
console.log(parsedAttributes);
/*
 {
   class: ['a', 'b', 'c'],
   name: 'bob'
 }
*/

Methods

  • isSeparatedAttribute(attributeName): returns a truthy separator for attributeName or false if this is not a separated attribute.
  • splitAttribute(name, value): splits value based on the rule for attributes called name, 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.