Skip to content

Commit 7d26e47

Browse files
committed
don't ignore the src/
1 parent 7ac02e3 commit 7d26e47

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,4 @@ typings/
6060
# next.js build output
6161
.next
6262

63-
src/
6463
*.tmp

src/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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

0 commit comments

Comments
 (0)