3 Strip comments from JSON. Lets you use comments in your JSON files!
4 https://github.com/sindresorhus/strip-json-comments
11 function stripJsonComments(str) {
14 var insideString = false;
15 var insideComment = false;
18 for (var i = 0; i < str.length; i++) {
20 nextChar = str[i + 1];
22 if (!insideComment && str[i - 1] !== '\\' && currentChar === '"') {
23 insideString = !insideString;
31 if (!insideComment && currentChar + nextChar === '//') {
32 insideComment = 'single';
34 } else if (insideComment === 'single' && currentChar + nextChar === '\r\n') {
35 insideComment = false;
37 } else if (insideComment === 'single' && currentChar === '\n') {
38 insideComment = false;
39 } else if (!insideComment && currentChar + nextChar === '/*') {
40 insideComment = 'multi';
43 } else if (insideComment === 'multi' && currentChar + nextChar === '*/') {
44 insideComment = false;
59 if (typeof module !== 'undefined' && module.exports) {
60 module.exports = stripJsonComments;
62 window.stripJsonComments = stripJsonComments;