Skip to content

Instantly share code, notes, and snippets.

@ViBiOh
Last active April 29, 2016 15:21
Show Gist options
  • Save ViBiOh/6e228557532f8b46b9a8 to your computer and use it in GitHub Desktop.
Save ViBiOh/6e228557532f8b46b9a8 to your computer and use it in GitHub Desktop.
Extract strings from a javascript source file
function isFunction(potentialFunction) {
return potentialFunction && Object.prototype.toString.call(potentialFunction) === '[object Function]';
}
function stringsReplace(str, callback) {
if (isFunction(callback)) {
str.replace(/(["'`])((?:(?=(\\?))\3.)*?)\1/gmi, (all, quote, value) => callback(value));
}
return str.replace(mustacheRegex, callback);
}
@ViBiOh
Copy link
Author

ViBiOh commented Apr 29, 2016

stringsReplace('simple quote value with an \' escape inside', value => console.log(value));
<- simple quote value with an \' escape inside

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment