Skip to content

Commit d75280d

Browse files
committed
No need for folders for this little thing
1 parent 7d26e47 commit d75280d

File tree

4 files changed

+30
-39
lines changed

4 files changed

+30
-39
lines changed

index.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,30 @@
11
'use strict'
22

3-
module.exports = require('./src')
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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
},
6868
"nyc": {
6969
"include": [
70-
"index.js",
71-
"src/**/*.js"
70+
"index.js"
7271
]
7372
}
7473
}

src/index.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

__tests__/index.js renamed to test.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
import test from 'ava'
22
import React from 'react'
33

4-
import entry from '../'
5-
import flexibleStringReplace from '../src'
6-
7-
test('entry exports', t => {
8-
t.not(entry, undefined)
9-
})
4+
import flexibleStringReplace from './'
105

116
test('flexibleStringReplace is defined', t => {
127
t.not(flexibleStringReplace, undefined)

0 commit comments

Comments
 (0)