slice-all

Slice a string at multiple locations

Usage no npm install needed!

<script type="module">
  import sliceAll from 'https://cdn.skypack.dev/slice-all';
</script>

README

slice-all

NPM TypeScript Coverage Status GitHub Stars Twitter Follow

Slice a string at multiple locations.

Installation

yarn add slice-all
npm install slice-all

API

Slice at multiple locations:

import sliceAll from "slice-all";

sliceAll("20200101T123456", [4, 6, 8, 9, 11, 13]);

// => ["2020", "01", "01", "T", "12", "34", "56"]

Use negatives when index from left is unknown:

import sliceAll from "slice-all";

sliceAll("12-------------34", [2, -2]);

// => ["12", "-------------", "34"]

To specify segment lengths instead of indicies, use negatives:

import sliceAll from "slice-all";

sliceAll("20200101T123456", [-8, -1, -2, -2, -2])

// => ["20200101", "T", "12", "34", "56"]

Dev DependenciesDavid


License license

MIT