Permalink
Browse files

Use ES6 fat arrow functions in examples #108

  • Loading branch information...
slevithan committed May 1, 2017
1 parent e445550 commit e00e56f6fe61177ac36b3b888187b11998422628
Showing with 5 additions and 12 deletions.
  1. +5 −12 src/xregexp.js
View
@@ -688,7 +688,7 @@ XRegExp._pad4 = pad4;
* // Basic usage: Add \a for the ALERT control code
* XRegExp.addToken(
* /\\a/,
- * function() {return '\\x07';},
+ * () => '\\x07',
* {scope: 'all'}
* );
* XRegExp('\\a[\\a-\\n]+').test('\x07\n\x07'); // -> true
@@ -698,7 +698,7 @@ XRegExp._pad4 = pad4;
* // character classes only)
* XRegExp.addToken(
* /([?*+]|{\d+(?:,\d*)?})(\??)/,
- * function(match) {return match[1] + (match[2] ? '' : '?');},
+ * (match) => `${match[1]}${match[2] ? '' : '?'}`,
* {flag: 'U'}
* );
* XRegExp('a+', 'U').exec('aaa')[0]; // -> 'a'
@@ -884,7 +884,7 @@ XRegExp.exec = (str, regex, pos, sticky) => {
*
* // Extracts every other digit from a string
* const evens = [];
- * XRegExp.forEach('1a2345', /\d/, function(match, i) {
+ * XRegExp.forEach('1a2345', /\d/, (match, i) => {
* if (i % 2) evens.push(+match[0]);
* });
* // evens -> [2, 4]
@@ -1131,16 +1131,11 @@ XRegExp.matchChain = (str, chain) => (function recurseChain(values, level) {
*
* // Regex search, using named backreferences in replacement string
* const name = XRegExp('(?<first>\\w+) (?<last>\\w+)');
- * XRegExp.replace('John Smith', name, '${last}, ${first}');
- * // -> 'Smith, John'
- *
* XRegExp.replace('John Smith', name, '$<last>, $<first>');
* // -> 'Smith, John'
*
* // Regex search, using named backreferences in replacement function
- * XRegExp.replace('John Smith', name, function(match) {
- * return match.last + ', ' + match.first;
- * });
+ * XRegExp.replace('John Smith', name, (match) => `${match.last}, ${match.first}`);
* // -> 'Smith, John'
*
* // String search, with replace-all
@@ -1200,9 +1195,7 @@ XRegExp.replace = (str, search, replacement, scope) => {
* [/c/g, 'x', 'one'], // scope 'one' overrides /g
* [/d/, 'w', 'all'], // scope 'all' overrides lack of /g
* ['e', 'v', 'all'], // scope 'all' allows replace-all for strings
- * [/f/g, function($0) {
- * return $0.toUpperCase();
- * }]
+ * [/f/g, ($0) => $0.toUpperCase()]
* ]);
*/
XRegExp.replaceEach = (str, replacements) => {

0 comments on commit e00e56f

Please sign in to comment.