UNPKG

@monstermann/fn

Version:

A utility library for TypeScript.

24 lines (22 loc) 465 B
import { dfdlT } from "@monstermann/dfdl"; //#region src/string/take.ts /** * `take(target, amount)` * * Takes the first `amount` characters from `target` string. * * ```ts * take("hello world", 5); // "hello" * ``` * * ```ts * pipe("hello world", take(5)); // "hello" * ``` */ const take = dfdlT((target, amount) => { if (amount === 0) return ""; if (amount >= target.length) return target; return target.slice(0, amount); }, 2); //#endregion export { take };