kingjs/string-ex.join-lines
@Join lines in a string with a separator.
Usage
var assert = require('assert');
var os = require('os');
var JoinLines = require('@kingjs/string-ex.join-lines');
var EndOfLine = os.EOL;
var NewLine = '\n';
var CarriageReturn = '\r';
var lines = `foo${NewLine}bar${CarriageReturn}baz${EndOfLine}moo`;
var paragraph = lines[JoinLines]();
assert(paragraph == 'foo bar baz moo');
var fullName = lines[JoinLines]('.');
assert(fullName == 'foo.bar.baz.moo');
API
joinLines(this[, separator])
Parameters
-
this
: The string of newlines to join. -
separator
: The separator to join the newlines with.
Returns
Returns the string with newlines replaced with the separator.
Remarks
Adjacent empty lines are replaced with a single separator.
Install
With npm installed, run
$ npm install @kingjs/string-ex.join-lines
Source
https://repository.kingjs.net/string-ex/join-lines
License
MIT