Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

append-if

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

append-if

Append a string, conditionally

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 10 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc