Installation
Quick Take
Examples
- Include configured left-side marker characters in the range
- Include a configured right-side marker in the range
- Expand whitespace only on the left side
- Expand whitespace only on the right side
- Request one replacement space when deletion would join words
- Crop tightly when a configured marker appears on the left
- Include all adjacent whitespace on the left
- Include all adjacent whitespace on the right
The Purpose
This program is used to manage the whitespace in the string index selections. Say you want to delete a certain index range in a string, but maybe there is whitespace around? This program extends the index ranges as needed.
API — expander()
The main function expander() is imported like this:
It’s a function which takes one input argument:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
optsType: Plain object Obligatory: yes | |||
opts | Plain object | yes | An Options Object. See below for its API. |
The Options Object has the following shape:
| Key | Type | Obligatory | Default | Description |
|---|---|---|---|---|
strType: string Obligatory: yes Default: "" (empty) | ||||
str | string | yes | "" (empty) | String to reference |
fromType: number (natural number) Obligatory: yes Default: 0 | ||||
from | number (natural number) | yes | 0 | Index from which to expand backwards |
toType: number (natural number) Obligatory: yes Default: 0 | ||||
to | number (natural number) | yes | 0 | Index from which to expand backwards |
ifLeftSideIncludesThisThenCropTightlyType: string Obligatory: no Default: "" (empty) | ||||
ifLeftSideIncludesThisThenCropTightly | string | no | "" (empty) | All characters to the left side of given range you want to trigger a tight crop. All concatenated into one chunk. |
ifLeftSideIncludesThisCropItTooType: string Obligatory: no Default: "" (empty) | ||||
ifLeftSideIncludesThisCropItToo | string | no | "" (empty) | All characters to the left side of given range you want to skip as if they were whitespace |
ifRightSideIncludesThisThenCropTightlyType: string Obligatory: no Default: "" (empty) | ||||
ifRightSideIncludesThisThenCropTightly | string | no | "" (empty) | All characters to the right side of given range you want to trigger a tight crop. All concatenated into one chunk. |
ifRightSideIncludesThisCropItTooType: string Obligatory: no Default: "" (empty) | ||||
ifRightSideIncludesThisCropItToo | string | no | "" (empty) | All characters to the right side of given range you want to skip as if they were whitespace |
extendToOneSideType: Boolean false or strings “left” or “right”Obligatory: no Default: false | ||||
extendToOneSide | Boolean false or strings “left” or “right” | no | false | You can expand the range only to one side if you want using this. |
wipeAllWhitespaceOnLeftType: Boolean Obligatory: no Default: false | ||||
wipeAllWhitespaceOnLeft | Boolean | no | false | If on, range will be extended to the left until it reaches the first non-whitespace character (or EOL) |
wipeAllWhitespaceOnRightType: Boolean Obligatory: no Default: false | ||||
wipeAllWhitespaceOnRight | Boolean | no | false | If on, range will be extended to the right until it reaches the first non-whitespace character (or EOL) |
addSingleSpaceToPreventAccidentalConcatenationType: Boolean Obligatory: no Default: false | ||||
addSingleSpaceToPreventAccidentalConcatenation | Boolean | no | false | If on, it will prevent accidental concatenation of strings by inserting a single space in tight crop situations |
Here are all defaults in one place for copying:
The function will return an array of two indexes, the new “from” and new “to”. For example, [12, 14].
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:
API — types
This package is written in TypeScript and exports the following types:
| Type | Description |
|---|---|
OptsType: Opts | |
Opts | The Options Object of expander() — its only input argument, documented above. |
RangeType: Range | |
Range | A single range — what expander() returns. |
import type { Opts, Range } from "string-range-expander";