next-char
This is a utility for finding the next character in a string. No, not indexOf
. It's to help you parse code.
Imagine you have some JS like this.
var { if bar ; else ; };
As a string, it would be.
'var foo = function () {\nif (bar) {\nbaz();\n} else {\nquux();\n}\n}'
You know the index of the first {
, but how do you find its pair (and ignore all the other braces)?
var str = 'var foo = function () {\nif (bar) {\nbaz();\n} else {\nquux();\n}\n}'; var openingIndex = str;// 22 var scopeString = str;// '{\nif (bar) {\nbaz();\n} else {\nquux();\n}\n}' var closingIndex = nextChar;// 39 scopeString = scopeString;// '{\nif (bar) {\nbaz();\n} else {\nquux();\n}\n}'