UNPKG

concatenater

Version:
124 lines (108 loc) 1.9 kB
# concatenater [![Build Status](https://travis-ci.org/sindresorhus/concatenater.svg?branch=master)](https://travis-ci.org/sindresorhus/concatenater) ## Usage ```js const concatenater = require('concatenater'); ``` ## append ```js concatenater('foo') .append('-bar') .toString(); //=> foo-bar concatenater('foo') .append('-bar', '-one', '-two') .toString(); //=> foo-bar-one-two concatenater('foo') .append('-bar', null, '-two', '-three') // null ignored .toString(); //=> foo-bar-two-three concatenater('foo') .append('-bar', undefined, '-two', '-three') // undefiend ignored .toString(); //=> foo-bar-two-three concatenater('foo') .append('-bar', false, '-two', '-three') // false ignored and breaks .toString(); //=> foo-bar concatenater('foo') .append('-bar', true, '-two', '-three') // true ignored and continue .toString(); //=> foo-bar ``` ## prepend ```js concatenater('bar') .prepend('foo,') .toString(); //=> foo,bar ``` ## surround ```js concatenater('foo,bar') .surround('{{', '}}') .toString(); //=> {{foor,bar}} ``` ## frame ```js concatenater('foo,bar') .frame('((...))') .toString(); //=> ((foor,bar)) ``` ## set ```js concatenater() .set('foo') .toString(); //=> foo ``` ## replace ```js concatenater('foo, bar') .replace('bar', '--') // 2 inputs .toString(); //=> foo, -- concatenater('foo, bar, one, anyKey') .replace({ // 1 input bar: '----', one: 1, anyKey: 'anyValue' }) .toString(); //=> foo, ----, 1, anyValue ``` ## source ```js concatenater() .source({ one: 1, two: 2 }) .set('foo, {one}, {two}') .toString(); //=> foo, 1, 2 ``` ## appendFormat ```js concatenater() .appendFormat('Hello [0] [1] [0]', 'foo', 'bar') .toString() //=> 'Hello foo bar foo' ``` ## n ```js test('newline', t => { concatenater() .append('Hello') .n() .append('foo') .n(2) .append('bar') .toString() // => `Hello foo bar` ```