Skip to content

scssyworks/class-modify

Repository files navigation

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

About

A tiny package to manage classes

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published