Installation
Quick Take
Examples
- Skip characters covered by a deletion range
- Iterate text inserted at the end of a string
- Iterate the result of multiple replacements
- Iterate the original string when there are no ranges
- Start iteration at an existing output offset
API — rIterate()
The main function rIterate() is imported like this:
It’s a function which takes four input arguments:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
strType: stringObligatory: yes | |||
str | string | yes | The input string to operate on |
rangesType: null or array of zero or more arrays (ranges)Obligatory: yes | |||
ranges | null or array of zero or more arrays (ranges) | yes | The ranges gathered so far |
cbType: Something falsy or a functionObligatory: yes | |||
cb | Something falsy or a function | yes | Callback function to be able to consume the indexes and character values |
offsetType: String index, a natural number Obligatory: no | |||
offset | String index, a natural number | no | Similar to second argument of String.prototype.indexOf(), start to process the string only after this position |
It’s a callback-based API so the function returns undefined.
API — version
You can import version:
API — types
This package is written in TypeScript and exports the following types:
| Type | Description |
|---|---|
CallbackType: Callback | |
Callback | The signature of the third input argument — called once per character with an Obj. |
ObjType: Obj | |
Obj | What the callback receives — the index i and the character val at it. |
import type { Callback, Obj } from "ranges-iterate";