1.0.1 • Published 8 years ago

separated-attributes v1.0.1

Weekly downloads
1
License
MIT
Repository
-
Last release
8 years ago

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.