npm.io
1.0.0 • Published 10 years ago

append-if

Licence
MIT
Version
1.0.0
Deps
1
Vulns
0
Weekly
0
Stars
1

append-if

NPM version Build Status Coverage Status

Code Climate Dependencies DevDependencies

Append a string, conditionally

Install

npm install --save append-if

Usage

ES2015
import appendIf from 'append-if';

appendIf('hello', ' world');
// => 'hello world'

appendIf('hello', 'lo');
// => 'hello'

appendIf('hello', ' world', true);
// => 'hello world'

appendIf('hello', ' world', false);
// => 'hello'

function customCondition(string, appendString) {
  return string.length > appendString.length;
}

appendIf('longer', 'short', customCondition);
// => 'longershort'

appendIf('short', 'longer', customCondition);
// => 'short'
ES5
import appendIf from 'append-if';

appendIf('hello', ' world');
// => 'hello world'

appendIf('hello', 'lo');
// => 'hello'

appendIf('hello', ' world', true);
// => 'hello world'

appendIf('hello', ' world', false);
// => 'hello'

function customCondition(string, appendString) {
  return string.length > appendString.length;
}

appendIf('longer', 'short', customCondition);
// => 'longershort'

appendIf('short', 'longer', customCondition);
// => 'short'

API

appendIf(string, appendString[, condition])
string

Type: string

String to append if condition is true.

appendString

Type: string

String to append to string if condition is true.

condition

Type: function || boolean

Function to evaluate to determine if string should be appended with appendString. condition is given string and appendString as parameters. Default condition checks if string ends with appendString. If not, appendString is appended to string.

Condition may also be a boolean. If true, string is appended with appendString, otherwise it is not.

LICENSE

MIT Dustin Specker

Keywords