https://github.com/srph/js-str-concat
[DEPRECATED] Conditionally concatenate strings
https://github.com/srph/js-str-concat
Last synced: 2 months ago
JSON representation
[DEPRECATED] Conditionally concatenate strings
- Host: GitHub
- URL: https://github.com/srph/js-str-concat
- Owner: srph
- License: mit
- Created: 2015-02-28T13:24:20.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2015-03-23T11:31:43.000Z (over 11 years ago)
- Last Synced: 2026-03-12T03:27:16.647Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 313 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing.md
- License: LICENSE
Awesome Lists containing this project
README

# js-str-concat [](https://travis-ci.org/srph/js-str-concat?branch=master) [](https://npmjs.org/package/srph-str-concat) [](http://opensource.org/licenses/MIT)
Conditionally concatenate strings.
## Why?
Because concatenating strings this way is hard to read and tedious to write:
```js
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
```
Compared to how simple and clean this is:
```js
concat({
'className1': true,
'className2': false,
'className3': true
}); // => true
```
This is helpful for adding `class`es to an `element` conditionally (like in adding classes in *vanilla* or in *ReactJS*, for example).
- [Getting Started](https://github.com/srph/js-str-concat/blob/master/docs/getting-started.md)
- [Installation](https://github.com/srph/js-str-concat/blob/master/docs/getting-started.md#installation)
- [Usage](https://github.com/srph/js-str-concat/blob/master/docs/getting-started.md#usage)
- [Non-node usage](https://github.com/srph/js-str-concat/blob/master/docs/getting-started.md#non-node-usage)
- [Browser usage](https://github.com/srph/js-str-concat/blob/master/docs/getting-started.md#browser-usage)
- [Contribution](https://github.com/srph/js-str-concat/blob/master/docs/faq.md)
- [Building](https://github.com/srph/js-str-concat/blob/master/docs/contributing.md#building)
- [Changelog](https://github.com/srph/js-str-concat/blob/master/docs/changelog.md)
## Important Note
This is an experimental pet project; and technically a dead project. Although It Just Works™, it is not recommended for production. If you'd like to continue this project, feel free to (friendly) fork, or contact me for project continuation or collaboration.
This was written for practice, and, also, because I found [`JedWatson/classnames`](https://github.com/JedWatson/classnames)'s project name to be unlikable for its specific project name, and that it did not provide inline code documentation.
### Alternatives
[**classnames** (`JedWatson/classnames`)](https://github.com/JedWatson/classnames)
## Acknowledgement
**js-str-concat** © 2015+, Kier Borromeo (srph). **js-str-concat** is released under the [MIT](mit-license.org) license.
> [srph.github.io](http://srph.github.io) ·
> GitHub [@srph](https://github.com/srph) ·
> Twitter [@_srph](https://twitter.com/_srph)