surround-string
Adds a prefix and a suffix to a string — but only if the string isn’t empty.
Installation
Requires Node.js 4.0.0 or above.
npm i surround-string
API
The module exports a single function.
Parameters
before
(string): The prefix to add.str
(string)after
(string): The suffix to add.
Return Value
- If
str
is empty, returns an empty string. - Otherwise, returns
before + str + after
.
Example
const surround = { thistitle = title thisname = name } { return + thisname } 'Mr.' 'Darcy' // 'Mr. Darcy''' 'Jane' // 'Jane'