Code Monkey home page Code Monkey logo

class-mergesort's Introduction

Class MergeSort

npm version

Class MergeSort is a utility library designed to facilitate the manipulation and combination of CSS classes in TypeScript and JavaScript applications. It provides various utilities to toggle, prefix, suffix, filter, merge, and more.

Installation

Choose your package manager to install class-mergesort.

npm i -D class-mergesort
yarn add -D class-mergesort
pnpm i -D class-mergesort

Documentation

Docs

API Overview

toggleClass

Takes a class name and a boolean condition. If the condition is true, it returns the class name; otherwise, an empty string is returned.

const isActive = true;
const activeClass = toggleClass('active', isActive);
// Output: "active" if isActive is true, "" otherwise.

prefixClass

Prepends a specified prefix to each class name in the list. Particularly useful for frameworks like Bootstrap.

const prefixedClasses = prefixClass('btn-', 'primary', 'large');
// Output: "btn-primary btn-large"

suffixClass

Appends a specified suffix to each class name in the list. Useful for BEM methodology.

const suffixedClasses = suffixClass('--disabled', 'button', 'input');
// Output: "button--disabled input--disabled"

filterClass

Filters class names based on a custom condition function. Only the class names that meet the condition will be included in the result.

const filteredClasses = filterClass(
  (name) => !name.includes('omit'),
  'button',
  'omit-me',
);
// Output: "button"

mergeClass

Combines multiple class names into a single string, while eliminating duplicates and empty strings.

// Multiple class name strings
const merged1 = mergeClass('btn btn-primary', 'btn-secondary', 'btn');
// Output: "btn btn-primary btn-secondary"

// Array of class names
const merged2 = mergeClass(['btn', 'btn-large'], ['btn-small', 'btn']);
// Output: "btn btn-large btn-small"

// Mixed types
const merged3 = mergeClass('btn btn-primary', ['btn-secondary', 'btn-large']);
// Output: "btn btn-primary btn-secondary btn-large"

classNameX

Acts similar to mergeClass but allows more complex structures and types for combining class names.

// Check API documentation for examples.

License

MIT

class-mergesort's People

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.