merge-string-conditionally
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

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`

Package Sidebar

Install

npm i merge-string-conditionally

Weekly Downloads

1

Version

1.2.0

License

MIT

Unpacked Size

4.24 kB

Total Files

5

Last publish

Collaborators

  • arnab333