File tree Expand file tree Collapse file tree 4 files changed +30
-39
lines changed Expand file tree Collapse file tree 4 files changed +30
-39
lines changed Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
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
Original file line number Diff line number Diff line change 67
67
},
68
68
"nyc" : {
69
69
"include" : [
70
- " index.js" ,
71
- " src/**/*.js"
70
+ " index.js"
72
71
]
73
72
}
74
73
}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import test from 'ava'
2
2
import React from 'react'
3
3
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 './'
10
5
11
6
test ( 'flexibleStringReplace is defined' , t => {
12
7
t . not ( flexibleStringReplace , undefined )
You can’t perform that action at this time.
0 commit comments