Installation
Quick Take
Examples
- Collapse boundary whitespace containing line breaks
- Preserve CRLF line endings
- Keep a chosen number of leading and trailing line breaks
- Preserve non-breaking-space boundaries
- Pass through non-string input
- Leave whitespace inside a multiline string unchanged
- Preserve a string that has no boundary whitespace
- Collapse strings containing only whitespace
Purpose
This program is aimed to process strings before concatenating them. It collapses the leading and trailing whitespace, if any, so that later the result looks reasonable.
For example, ranges-push uses it to merge to-be-inserted chunks of string.
It does not touch the “inner” whitespace, gaps between chunks of text present between the first and last non-whitespace characters. See string-collapse-white-space which processes those gaps.
API — collWhitespace()
The main function collWhitespace() is imported like this:
It’s a function which takes two input arguments:
| Input argument | Type | Obligatory | Default | Description |
|---|---|---|---|---|
strType: String Obligatory: yes Default: undefined | ||||
str | String | yes | undefined | Source string to work on |
lineBreakLimitType: Natural number or zero Obligatory: no Default: 1 | ||||
lineBreakLimit | Natural number or zero | no | 1 | If whitespace contains linebreaks, it will be replaced by those linebreaks, count limited to this value |
If first input argument is not a string, it will be just returned back, untouched.
If second input argument is zero or falsy or not a number, it will be set to 1 and application will continue as normal.
The function will return a string of zero or more characters. If input was not a string, same input will be returned back, without an error.
API — version
You can import version: