Skip to content

arnab333/merge-string-conditionally

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

merge-string-conditionally

npm downloads

Simple package for merging multiple strings where some of the strings are conditionally applied. It can be used to merge multiple class names. A fixed string can be used as well as conditional strings through object(s)

It can be used in the React projects (to merge class names) as well as in Node.js projects.

No dependencies.

Install

$ npm install merge-string-conditionally

OR

$ yarn add merge-string-conditionally

Usage

import mergeString from 'merge-string-conditionally';

OR

const mergeString = require('merge-string-conditionally');

Examples

mergeString('fixed-class', { 'any-className': true }); // as long as the object values are true they will be merged

--- output ---
'fixed-class any-className`
mergeString(
  'fixed-class',
  { 'any-className': true },
  { 'any-className-2': true }
); // multiple objects can be passed

--- output ---
'fixed-class any-className any-className-2`
mergeString('fixed-class', { 'any-className': true, 'any-className-2': true }); // single objects with multiple properties can also be passed

--- output ---
'fixed-class any-className any-className-2`
mergeString('fixed-class', { 'false-className': false, 'any-className': true }); // single objects with multiple properties can also be passed

--- output ---
'fixed-class any-className`

About

Merge Multiple Strings Conditionally

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published