UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

26 lines (24 loc) 712 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/array/slice.ts /** * `slice(target, start, end?)` * * Extracts a section of `target` array from `start` index to `end` index (exclusive). If `end` is not provided, extracts to the end of the array. * * ```ts * slice([1, 2, 3, 4, 5], 1, 4); // [2, 3, 4] * slice([1, 2, 3, 4, 5], 2); // [3, 4, 5] * slice([1, 2, 3, 4, 5], -2); // [4, 5] * ``` * * ```ts * pipe([1, 2, 3, 4, 5], slice(1, 4)); // [2, 3, 4] * pipe([1, 2, 3, 4, 5], slice(2)); // [3, 4, 5] * pipe([1, 2, 3, 4, 5], slice(-2)); // [4, 5] * ``` */ const slice = dfdlT((target, start, end) => { return target.slice(start, end); }, (args) => Array.isArray(args[0])); //#endregion export { slice };