Installation
Quick Take
API — trimSpaces()
The main function trimSpaces()
is imported like this:
It’s a function which takes two input arguments:
Input argument | Type | Obligatory | Description |
---|---|---|---|
input Type: String Obligatory: yes | |||
input | String | yes | Input string you want to trim some way |
opts Type: Plain object Obligatory: no | |||
opts | Plain object | no | An Optional Options Object. |
The Optional Options Object has the following shape:
Key | Type | Default | Description |
---|---|---|---|
classicTrim Type: Boolean Default: false | |||
classicTrim | Boolean | false | If set to true , trimming becomes the same as String.trim() . |
cr Type: Boolean Default: false | |||
cr | Boolean | false | Should we trim the carriage returns (CR) |
lf Type: Boolean Default: false | |||
lf | Boolean | false | Should we trim the line breaks (LF) |
tab Type: Boolean Default: false | |||
tab | Boolean | false | Should we trim tabs |
space Type: Boolean Default: true | |||
space | Boolean | true | Should we trim spaces |
nbsp Type: Boolean Default: false | |||
nbsp | Boolean | false | Should we trim raw non-breaking spaces |
Here are all defaults in one place for copying:
The function will return a plain object:
Key | Type | Description |
---|---|---|
res Type: String or zero or more characters | ||
res | String or zero or more characters | Result string after trimming. |
ranges Type: Array of zero or more arrays | ||
ranges | Array of zero or more arrays | If we trimmed anything, each slice range will be added into this array. |
ranges
from the output can be further used in any Ranges ecosystem libraries to enable composable string operations.
API — defaults
You can import defaults
:
It's a plain object:
The main function calculates the options to be used by merging the options you passed with these defaults.
API — version
You can import version
:
opts.classicTrim
String.trim()
returns string but sometimes you need just ranges of what would be trimmed, to merge them into compiled ranges array and to process later, along everything else. In those cases, use opts.classicTrim
. If you need just string value, it’s not worth to use this function as a substitute for String.trim()
for performance reasons.