This repository was archived by the owner on Aug 30, 2025. It is now read-only.
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 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
Original file line number Diff line number Diff line change 6767 },
6868 "nyc" : {
6969 "include" : [
70- " index.js" ,
71- " src/**/*.js"
70+ " index.js"
7271 ]
7372 }
7473}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11import test from 'ava'
22import 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
116test ( 'flexibleStringReplace is defined' , t => {
127 t . not ( flexibleStringReplace , undefined )
You can’t perform that action at this time.
0 commit comments