Last active
August 29, 2015 14:00
-
-
Save rixtox/11519348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var result = ~ function(str) { | |
// Define a DSL | |
var r = function(target, replace) { | |
str = str.replace(new RegExp(target, 'gi'), replace || target); | |
}; | |
// Use the DSL | |
r('JavaScript'); | |
r('gogle', 'Google'); | |
// Or even much cooler | |
var list = [ | |
'jQuery', | |
'Mac OS', | |
['adress', 'address'] | |
]; | |
list.each(function(item) { | |
r.apply(this, [].concat(item)); | |
}); | |
return str; | |
} ($('.something').text()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment