Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brechtcs/hast-util-class-list
Simulate the browser's classList API for HAST nodes
https://github.com/brechtcs/hast-util-class-list
Last synced: about 11 hours ago
JSON representation
Simulate the browser's classList API for HAST nodes
- Host: GitHub
- URL: https://github.com/brechtcs/hast-util-class-list
- Owner: brechtcs
- Created: 2018-09-25T06:13:03.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-09-28T07:28:49.000Z (about 2 months ago)
- Last Synced: 2024-11-02T04:53:16.648Z (14 days ago)
- Language: JavaScript
- Homepage:
- Size: 22.5 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# hast-util-class-list
Simulate the browser's [`classList`](https://developer.mozilla.org/en-US/docs/Web/API/Element/classList) API for [`hast`](https://github.com/syntax-tree/hast) nodes.
## Installation
`npm install hast-util-class-list`
## Usage
```js
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`](https://github.com/npm-dom/class-list) by [Raynos](https://github.com/Raynos).
## License
Apache-2.0