Installation
Quick Take
Examples
- Pad a single decimal digit while removing thousand separators
- Leave a single decimal place unpadded
- Convert a comma decimal separator to a dot
- Remove spaced thousand separators when no decimal separator is present
- Keep thousand separators while still normalising the outer quotes
- Leave a value unchanged when it contains non-numeric text
- Preserve a number whose separators are ambiguous
- Remove spaces used as thousand separators
- Remove apostrophes used as thousand separators
API — remSep()
The main function remSep() is imported like this:
It’s a function which takes three input arguments:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
strType: String Obligatory: yes | |||
str | String | yes | Input to work upon. |
optsType: Plain object Obligatory: no | |||
opts | Plain object | no | Optional Options Object. |
None of the input arguments will be mutated by this program, we have unit tests to prove that.
The Optional Options Object has the following shape:
| Key | Type | Default | Description |
|---|---|---|---|
removeThousandSeparatorsFromNumbersType: Boolean Default: true | |||
removeThousandSeparatorsFromNumbers | Boolean | true | Should remove thousand separators? 1,000,000 → 1000000? Or Swiss-style, 1'000'000 → 1000000? Or Russian-style, 1 000 000 → 1000000? |
padSingleDecimalPlaceNumbersType: Boolean Default: true | |||
padSingleDecimalPlaceNumbers | Boolean | true | Pad one decimal place numbers with zero? 100.2 → 100.20? |
forceUKStyleType: Boolean Default: false | |||
forceUKStyle | Boolean | false | Convert the decimal separator commas into dots? 1,5 → 1.5? |
Here are all defaults in one place for copying:
The function will return a string, the input with thousand separators removed.
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: