srph-str-concatdeprecated

Conditionally concatenate strings.

Usage no npm install needed!

<script type="module">
  import srphStrConcat from 'https://cdn.skypack.dev/srph-str-concat';
</script>

README

str-concat.js Build Status MIT license Author

Conditionally concatenate strings.

Why?

Because concatenating strings this way is hard to read and tedious to write:

var classNames = '';

if ( /* insert true statement */ ){
  classNames += 'className1 ';
}

if ( /* insert false statement */ ){
  classNames += 'className2 ';
}

if ( /* insert true statement */ ){
  classNames += 'className3 ';
}

console.log(classNames) // classNames => className1 className3

This is helpful for adding classes to an element conditionally (like in vanilla, or in ReactJS, for example).

Installation

$ npm install srph/str-concat.js --save

* The purpose of the --save argument is to add it your package.json's dependencies.

Usage

Our function accepts 1 argument (Object).

var concat = require('str-concat');

var isColMd6 = true;
var classNames = concat({
  'col-md-6': isColMd6,
  'form-group': true,
  'yolo-class': false
});

console.log(classNames) // => col-md-6 form-group

Contributing

For features or fixes, I would suggest to submit an issue first before submitting a pull request. This avoids closed pull-requests; useless work.

At the end of the day, just feel free.

Building

Check docs/building

Acknowledgement

str-concat © 2015+, Kier Borromeo (srph). str-concat is released under the MIT license.

srph.github.io  ·  GitHub @srph  ·  Twitter @_srph