@monstermann/fn
Version:
A utility library for TypeScript.
24 lines (22 loc) • 618 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/string/split.ts
/**
* `split(target, source)`
*
* Splits `target` string into an array of substrings using `source` string or regular expression as the separator.
*
* ```ts
* split("hello,world,test", ","); // ["hello", "world", "test"]
* split("hello world", /\s+/); // ["hello", "world"]
* ```
*
* ```ts
* pipe("hello,world,test", split(",")); // ["hello", "world", "test"]
* pipe("hello world", split(/\s+/)); // ["hello", "world"]
* ```
*/
const split = dfdlT((target, delimiter) => {
return target.split(delimiter);
}, 2);
//#endregion
export { split };