Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.74 KB

README.md

File metadata and controls

67 lines (46 loc) · 1.74 KB

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`