Home

Awesome

hast-util-class-list

Simulate the browser's classList API for hast nodes.

Installation

npm install hast-util-class-list

Usage

var ClassList = require('hast-util-class-list')

var el = {type: 'element', tagName: 'div', properties: {className: ['one']}}
var classList = ClassList(el)

classList.contains('one') // => true
classList.toggle('one') // => false
// el: {type: 'element', tagName: 'div', properties: {className: []}}
classList.add('one')
// el: {type: 'element', tagName: 'div', properties: {className: ['one']}}
classList.replace('one', 'two')
// el: {type: 'element', tagName: 'div', properties: {className: ['two']}}
classList.remove('two')
// el: {type: 'element', tagName: 'div', properties: {className: []}}

Acknowledgements

This module was loosely based on class-list by Raynos.

License

Apache-2.0