From dfed1434ebc06a630cd7bde6609e3b122bf81de3 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 17 Feb 2022 21:31:29 +0530 Subject: feat(replace): adds replaceAll function --- src/index.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/index.ts') diff --git a/src/index.ts b/src/index.ts index 5bcb4f9..1a52c95 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { flow, pipe } from 'fp-ts/function' import { fst } from 'fp-ts/Tuple' import * as ev from './eval' import { parser } from './parser' -import { ListExpr } from './types' +import { index, ListExpr } from './types' const toSourceString = (r: string | RegExp): string => typeof r === 'string' ? r : r.source @@ -19,3 +19,6 @@ export const liexp: (r: string | RegExp) => ListExpr = flow( export const matchAll = (exp: string | RegExp, list: T[]) => pipe(exp, liexp, lxp => ev.matchAll(lxp, list)) + +export const replaceAll = (exp: string | RegExp, replacer: (v: T, m: ev.MatchGroupIndexed, i: index) => T[], list: T[]) => + pipe(exp, liexp, lxp => ev.replaceAll(lxp, replacer, list)) -- cgit v1.3.1