aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAkshay Nair <phenax5@gmail.com>2022-02-17 21:43:14 +0530
committerAkshay Nair <phenax5@gmail.com>2022-02-17 21:43:14 +0530
commitd43d9e5933b1bc92e362321b054c951a4a4b000f (patch)
tree9ae9898e38da8647d3fefa71f213083862f3b6e3 /tests
parent8de4bd6d732c3490a7d7a3d7433d8974b8592895 (diff)
downloadelxr-d43d9e5933b1bc92e362321b054c951a4a4b000f.tar.gz
elxr-d43d9e5933b1bc92e362321b054c951a4a4b000f.zip
docs: adds replaceAll example
Diffstat (limited to 'tests')
-rw-r--r--tests/replace.spec.ts9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/replace.spec.ts b/tests/replace.spec.ts
index dd82eaa..98f1540 100644
--- a/tests/replace.spec.ts
+++ b/tests/replace.spec.ts
@@ -3,6 +3,15 @@ import { replaceAll } from '../src'
describe('Basic tests', () => {
it('should', () => {
+ const replacer = (_, matches) => [matches.value.reduce((a, b) => a + b, 0)]
+ expect(replaceAll(/ \n+ /, replacer, ['start', 3, 5, 'mid', 2, 0, 4, 'end'])).toEqual([
+ 'start',
+ 8,
+ 'mid',
+ 6,
+ 'end',
+ ])
+
expect(
replaceAll(/"start", \s, \n/, _ => ['replaced'], [
1,