File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -60,5 +60,4 @@ typings/
60
60
# next.js build output
61
61
.next
62
62
63
- src /
64
63
* .tmp
Original file line number Diff line number Diff line change
1
+ 'use strict'
2
+
3
+ // flexibleStringReplace :: (Pattern, Replacement, String) -> [ * ]
4
+ // Pattern = RegExp | String
5
+ // Replacement = String | (* -> *)
6
+ function flexibleStringReplace ( pattern , replacement , str ) {
7
+ var result = [ ]
8
+ var position = 0
9
+
10
+ str . replace ( pattern , function ( ) {
11
+ var args = Array . prototype . slice . call ( arguments )
12
+ var argsN = args . length
13
+ var match = args [ 0 ]
14
+ var originalStr = args [ argsN - 1 ]
15
+ var charOffset = args [ argsN - 2 ]
16
+ var prevChars = originalStr . slice ( position , charOffset )
17
+ var replaced = typeof replacement === 'function'
18
+ ? replacement . apply ( null , args )
19
+ : replacement
20
+
21
+ result . push ( prevChars , replaced )
22
+ position = charOffset + match . length
23
+ } )
24
+
25
+ result . push ( str . slice ( position ) )
26
+
27
+ return result
28
+ }
29
+
30
+ module . exports = flexibleStringReplace
You can’t perform that action at this time.
0 commit comments