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 |
|---|---|---|---|
inputType: String Obligatory: yes | |||
input | String | yes | Input string you want to trim some way |
optsType: Plain object Obligatory: no | |||
opts | Plain object | no | An Optional Options Object. |
The Optional Options Object has the following shape:
| Key | Type | Default | Description |
|---|---|---|---|
classicTrimType: Boolean Default: false | |||
classicTrim | Boolean | false | If set to true, trimming becomes the same as String.trim(). |
crType: Boolean Default: false | |||
cr | Boolean | false | Should we trim the carriage returns (CR) |
lfType: Boolean Default: false | |||
lf | Boolean | false | Should we trim the line breaks (LF) |
tabType: Boolean Default: false | |||
tab | Boolean | false | Should we trim tabs |
spaceType: Boolean Default: true | |||
space | Boolean | true | Should we trim spaces |
nbspType: 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 |
|---|---|---|
resType: String or zero or more characters | ||
res | String or zero or more characters | Result string after trimming. |
rangesType: 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.