append-if
Append a string, conditionally
Install
npm install --save append-if
Usage
ES2015
import appendIf from 'append-if';
appendIf('hello', ' world');
appendIf('hello', 'lo');
appendIf('hello', ' world', true);
appendIf('hello', ' world', false);
function customCondition(string, appendString) {
return string.length > appendString.length;
}
appendIf('longer', 'short', customCondition);
appendIf('short', 'longer', customCondition);
ES5
import appendIf from 'append-if';
appendIf('hello', ' world');
appendIf('hello', 'lo');
appendIf('hello', ' world', true);
appendIf('hello', ' world', false);
function customCondition(string, appendString) {
return string.length > appendString.length;
}
appendIf('longer', 'short', customCondition);
appendIf('short', 'longer', customCondition);
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.
Related
LICENSE
MIT © Dustin Specker