§ Quick Take
import { strict as assert } from "assert";
import crop from "ranges-crop";
assert.deepEqual(
crop(
[
[2, 3],
[9, 10, "bad grey wolf"],
[1, 2],
],
7
),
[[1, 3]] // sorted, merged and cropped
);
§ Purpose
It crops the ranges, ensuring no range from an array goes beyond a given index.
Along the way, it will also merge and sort ranges.
§ API
crop(arr, strLen)
Input argument | Type | Obligatory? | Description |
---|---|---|---|
arrOfRanges | null or ranges - array of zero or more arrays | yes | Provide an array of ranges to invert. Ranges do not have to be sorted or merged. |
strLen | Natural number or zero | yes | Algorithm needs to know the length of the reference string to calculate the inverted last slice's ending index. |
Output: array of zero or more arrays (so-called ranges) where each consists of two or more natural number (or zero) indexes.
This package does not mutate the input array. It creates and returns a new array with ranges cropped.
§ Changelog
See it in the monorepo , on Sourcehut.
§ Licence
Copyright © 2010–2020 Roy Revelt and other contributors
Related packages:
📦 ranges-invert 3.0.2
Invert string index ranges
📦 ranges-regex 3.0.3
Integrate regex operations into Ranges workflow
📦 ranges-push 4.0.2
Gather string index ranges
📦 ranges-iterate 1.2.2
Iterate a string and any changes within given string index ranges
📦 ranges-merge 6.2.0
Merge and sort string index ranges
📦 ranges-offset 1.0.3
Increment or decrement each index in every range
📦 ranges-process-outside 3.0.2
Iterate string considering ranges, as if they were already applied