class-modify

0.1.1 • Public • Published

Class Modify

A tiny package to manage and modify HTML classes

Install

npm i class-modify

Usage

Add, remove and toggle classes

import { modifyClass } from 'class-modify';
 
const classes = modifyClass('test one two');
console.log(classes.add('three').toString()); // --> test one two three
console.log(classes.remove('two').toString()); // --> test one three
console.log(classes.toggle('three').toString()); // --> test one
console.log(classes.toggle('three').toString()); // --> test one three

Subscribe to changes

import { modifyClass } from 'class-modify';
 
const classes = modify('test one two');
const subscription = classes.subscribe((classes) => {
    console.log(classes); // --> "test one two three" // Called after an operation
});
 
classes.add('three'); // --> This will call the subscribed callbacks
 
subscription.unsubscribe(); // Removes the callback

Reset and reset all

classes.reset(); // Clears all the classes (subscriptions stay intact)
classes.resetAll(); // Clears all the classes and subscriptions

Package Sidebar

Install

npm i class-modify

Weekly Downloads

1

Version

0.1.1

License

MIT

Unpacked Size

66.3 kB

Total Files

15

Last publish

Collaborators

  • scssyworks