Skip to content

Commit

Permalink
Replace ignoring the case
Browse files Browse the repository at this point in the history
  • Loading branch information
FagnerMartinsBrack committed Mar 27, 2016
1 parent 176a69d commit 1f22582
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/str-replace.js
Expand Up @@ -47,7 +47,9 @@ var replaceAll = CreateReplaceDefinition(function( occurrences, replacement, tar
});

var replace = CreateReplaceDefinition(function( occurrences, replacement, target ) {
// TODO Replace the firs occurrence ignoring the case
if ( this.ignoringCase ) {
return target.replace( new RegExp(occurrences, "i"), replacement );
}
return target.replace( occurrences, replacement );
});

Expand Down
9 changes: 9 additions & 0 deletions test/replace.js
Expand Up @@ -8,5 +8,14 @@ module.exports = {
var expected = "ea";
assert.strictEqual( actual, expected );
assert.done();
},
replace_first_occurrence_ignoring_the_case: function( assert ) {
var actual = replace( "a" )
.ignoringCase()
.from( "AA" )
.with( "e" );
var expected = "eA";
assert.strictEqual( actual, expected );
assert.done();
}
};

0 comments on commit 1f22582

Please sign in to comment.