All Projects → lukewestby → class-name-builder

lukewestby / class-name-builder

Licence: MIT license
A small, chainable, immutable utility for building up class name strings in application logic

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to class-name-builder

opentab
开源的轻应用后端(Open Tiny App Backend),轻量,高效,易部署。
Stars: ✭ 27 (-41.3%)
Mutual labels:  deprecated
Azure-AppServices-Diagnostics
Azure App Service Diagnostics provides developers ability to write various diagnostics features which helps customers to diagnose and troubleshoot their applications hosted on app services.
Stars: ✭ 42 (-8.7%)
Mutual labels:  deprecated
prestans
A WSGI compliant REST micro-framework.
Stars: ✭ 14 (-69.57%)
Mutual labels:  deprecated
perfectum
A set of tools for working with project performance
Stars: ✭ 43 (-6.52%)
Mutual labels:  deprecated
passion
An object-oriented LÖVE game engine
Stars: ✭ 35 (-23.91%)
Mutual labels:  deprecated
pages
DEPRECATED: Publishing platform for 18F sites a la GitHub pages
Stars: ✭ 63 (+36.96%)
Mutual labels:  deprecated
dcos-launch
Turn-key deployments of DC/OS on AWS (template and onprem), Azure, and GCE
Stars: ✭ 16 (-65.22%)
Mutual labels:  deprecated
sassquatch
CSS foundation & framework for Meetup
Stars: ✭ 25 (-45.65%)
Mutual labels:  deprecated
dashboard-extension-simple-table
⛔ DEPRECATED. This project was moved to a new repository. Visit https://github.com/DevExpress/dashboard-extensions to find an updated version.
Stars: ✭ 37 (-19.57%)
Mutual labels:  deprecated
wallet-lib
DEPRECATED A pure and extensible JavaScript Wallet Library for Dash
Stars: ✭ 13 (-71.74%)
Mutual labels:  deprecated
rok4
ROK4 est une suite d'outils open source développée par l'IGN France permettant la diffusion de données raster et vecteur en WMS, WMTS ou TMS. DEPRECATED ! Projet maintenu ici : https://github.com/rok4/documentation
Stars: ✭ 18 (-60.87%)
Mutual labels:  deprecated
user-info
Node.js `os.userInfo()` ponyfill
Stars: ✭ 33 (-28.26%)
Mutual labels:  deprecated
atom-fixmyjs
[DEPRECATED] Automagically fix JSHint lint warnings
Stars: ✭ 88 (+91.3%)
Mutual labels:  deprecated
ionic-3D-card-carousel
DEPRECATED Sample project that shows an experimental 3D card carousel in Ionic.
Stars: ✭ 29 (-36.96%)
Mutual labels:  deprecated
SAM-BAR
SAM Boot Assistant Reloaded - Combo USB CDC+MSD Bootloader for Atmel/Microchip SAMD21 microcontroller
Stars: ✭ 29 (-36.96%)
Mutual labels:  deprecated
aws-chaos-scripts
DEPRECATED Collection of python scripts to run failure injection on AWS infrastructure
Stars: ✭ 91 (+97.83%)
Mutual labels:  deprecated
capybara-json
No description or website provided.
Stars: ✭ 61 (+32.61%)
Mutual labels:  deprecated
atom-perfectionist
Beautify CSS and SCSS
Stars: ✭ 19 (-58.7%)
Mutual labels:  deprecated
VRTK.Tutorials.OculusIntegration
Prefabs and code for use with the Oculus Integration Unity Package
Stars: ✭ 26 (-43.48%)
Mutual labels:  deprecated
NetteAdapterForSymfonyBundles
[DEPRECATED due to only 20 downloads per 2 years] Read an article about this idea
Stars: ✭ 15 (-67.39%)
Mutual labels:  deprecated

ClassNameBuilder Build Status

A small, chainable, immutable utility for building up class name strings in application logic. Great for use with React's className property or Angular's ng-class directive. Improves code readability by avoiding large, complex sets of nested conditional statements when generating class names in templates or application code.

Installation

npm install class-name-builder

Example

import ClassNameBuilder from 'class-name-builder';

let condition = true;
let otherCondition = false;

const classNames = ClassNameBuilder
  .create()
  .always('example awesome-example')
  .if(condition, 'condition')
  .if(otherCondition, 'other-condition')
  .else(['not-other-condition', 'array'])
  .toString();

console.log(classNames);
// "example awesome-example condition not-other-condition array"

API

Static methods

  • create(): ClassNameBuilder : creates a new, empty instance of ClassNameBuilder. ClassNameBuilder has no constructor, so this is the only way to create an instance.

Instance methods

  • always(value: string | Array<string>): ClassNameBuilder: creates a new instance of ClassNameBuilder with the given values. If the value is a string, multiple class names can be included by separating them with one or more spaces, similar to the class HTML attribute. Duplicate class names will be removed in the case of both a space-separated string and an array.
  • if(condition: any, value: string | Array<string>): ClassNameBuilder: creates a new instance of ClassNameBuilder with the passed in value only included if the condition is truthy.
  • else(value: string | Array<string>): ClassNameBuilder: creates a new instance of ClassNameBuilder with the passed in value only if the condition for the preceding if() call was falsey. Will throw an error if called without an immediately preceding call to if().
  • merge(other: ClassNameBuilder): ClassNameBuilder: creates a new instance of ClassNameBuilder with class names from the passed in instance mixed in with those in the calling instance.
  • toString(): string: returns the class names represented by the instance as a space-separated string.

Development

npm install -g gulp && npm install

To bundle with browserify and babelify:

gulp build

To run the unit tests with karma:

gulp test
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].