separated-attributes

1.0.1 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i separated-attributes

Weekly Downloads

3

Version

1.0.1

License

MIT

Last publish

Collaborators

  • gburtini