From d43d9e5933b1bc92e362321b054c951a4a4b000f Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Thu, 17 Feb 2022 21:43:14 +0530 Subject: docs: adds replaceAll example --- README.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index f6e4054..eb2c9ee 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ Whitespaces are ignored (except within literals) ### Examples + +#### matchAll + ```js // | Match for any number or any non-empty string or any object with `prop` is true matchAll(/ \n | \s\T /, [null, 23, '', 'wow', false ] @@ -81,3 +84,14 @@ matchAll(/ [seperator true], [id \s\T]+ /, [ // } ``` + +#### replaceAll + +```js +// | Match for any number or any non-empty string or any object with `prop` is true +const replacer = (_, matches) => matches.value.reduce((a, b) => a + b, 0) +replaceAll(/ \n+ /, replacer, [ 'start', 3, 5, 'mid', 2, 0, 4, 'end' ]) + +// > [ 'start', 8, 'mid', 6, 'end' ] +``` + -- cgit v1.3.1