UNPKG

remeda

Version:

A utility library for JavaScript and Typescript.

40 lines (39 loc) 2.44 kB
import { IterableContainer } from "./IterableContainer-JENOIFLG.cjs"; import { PartialArray } from "./PartialArray-D2gnIwit.cjs"; import { TupleParts } from "./TupleParts-BV9kUr1M.cjs"; import { ClampedIntegerSubtract } from "./ClampedIntegerSubtract-Ca6NWX6v.cjs"; import { CoercedArray } from "./CoercedArray-DlyU2XyU.cjs"; import { IsInteger, IsNegative, Writable } from "type-fest"; //#region src/drop.d.ts type Drop<T extends IterableContainer, N extends number> = IsNegative<N> extends true ? Writable<T> : IsInteger<N> extends false ? Array<T[number]> : ClampedIntegerSubtract<N, TupleParts<T>["required"]["length"]> extends infer RemainingPrefix extends number ? RemainingPrefix extends 0 ? [...DropFixedTuple<TupleParts<T>["required"], N>, ...PartialArray<TupleParts<T>["optional"]>, ...CoercedArray<TupleParts<T>["item"]>, ...TupleParts<T>["suffix"]] : ClampedIntegerSubtract<RemainingPrefix, TupleParts<T>["optional"]["length"]> extends infer RemainingOptional extends number ? RemainingOptional extends 0 ? [...PartialArray<DropFixedTuple<TupleParts<T>["optional"], RemainingPrefix>>, ...CoercedArray<TupleParts<T>["item"]>, ...TupleParts<T>["suffix"]] : [...CoercedArray<TupleParts<T>["item"]>, ...TupleParts<T>["suffix"]] | Exclude<DropFixedTuple<TupleParts<T>["suffix"], RemainingOptional, true>, TupleParts<T>["suffix"]> : never : never; type DropFixedTuple<T, N, IncludePrefixes = false, Dropped extends Array<unknown> = []> = Dropped["length"] extends N ? T : T extends readonly [unknown, ...infer Rest] ? DropFixedTuple<Rest, N, IncludePrefixes, [...Dropped, unknown]> | (true extends IncludePrefixes ? T : never) : []; /** * Removes first `n` elements from the `array`. * * @param array - The target array. * @param n - The number of elements to skip. * @signature * R.drop(array, n) * @example * R.drop([1, 2, 3, 4, 5], 2) // => [3, 4, 5] * @dataFirst * @lazy * @category Array */ declare function drop<T extends IterableContainer, N extends number>(array: T, n: N): Drop<T, N>; /** * Removes first `n` elements from the `array`. * * @param n - The number of elements to skip. * @signature * R.drop(n)(array) * @example * R.drop(2)([1, 2, 3, 4, 5]) // => [3, 4, 5] * @dataLast * @lazy * @category Array */ declare function drop<N extends number>(n: N): <T extends IterableContainer>(array: T) => Drop<T, N>; //#endregion export { drop }; //# sourceMappingURL=drop-Cj-r1xf2.d.cts.map