@monstermann/fn
Version:
A utility library for TypeScript.
24 lines (22 loc) • 491 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/string/dropLast.ts
/**
* `dropLast(target, amount)`
*
* Removes the last `amount` characters from `target` string.
*
* ```ts
* dropLast("hello world", 6); // "hello"
* ```
*
* ```ts
* pipe("hello world", dropLast(6)); // "hello"
* ```
*/
const dropLast = dfdlT((target, amount) => {
if (amount === 0) return target;
if (amount >= target.length) return "";
return target.slice(0, -amount);
}, 2);
//#endregion
export { dropLast };