0.1.1 • Published 4 years ago

class-modify v0.1.1

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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