@monstermann/fn
Version:
A utility library for TypeScript.
24 lines (22 loc) • 661 B
JavaScript
import { dfdlT } from "@monstermann/dfdl";
//#region src/string/match.ts
/**
* `match(target, source)`
*
* Returns the result of matching `target` string against `source` string or regular expression, or null if no match is found.
*
* ```ts
* match("hello world", "world"); // ["world", index: 6, input: "hello world", groups: undefined]
* match("hello world", /\d+/); // null
* ```
*
* ```ts
* pipe("hello world", match("world")); // ["world", index: 6, input: "hello world", groups: undefined]
* pipe("hello world", match(/\d+/)); // null
* ```
*/
const match = dfdlT((target, source) => {
return target.match(source);
}, 2);
//#endregion
export { match };