Re: [whatwg/streams] Add an example of a transform stream that replaces template tags (#846)

ricea commented on this pull request.



> +        function replaceFunc(match, p1, offset) {
+          let replacement = substitutions[p1];
+          if (replacement === undefined) {
+            replacement = "";
+          }
+          lastIndex = offset + replacement.length;
+          return replacement;
+        }
+        chunk = chunk.replace(/\{\{([a-zA-Z0-9_-]+)\}\}/g, replaceFunc);
+        // Regular expression for an incomplete template at the end of a string.
+        const partialAtEndRegexp = /\{(\{([a-zA-Z0-9_-]+(\})?)?)?$/g;
+        // Avoid looking at any characters that have already been substituted.
+        partialAtEndRegexp.lastIndex = lastIndex;
+        const match = partialAtEndRegexp.exec(chunk);
+        if (match) {
+          partialChunk = chunk.substr(match.index);

Resolved by replacing the function with a class :-)

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/pull/846#discussion_r147398378

Received on Friday, 27 October 2017 12:32:54 UTC