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;
40 } else if (insideComment === 'single' && currentChar === '\n') {
41 insideComment = false;
42 } else if (!insideComment && currentChar + nextChar === '/*') {
43 insideComment = 'multi';
46 } else if (insideComment === 'multi' && currentChar + nextChar === '*/') {
47 insideComment = false;
62 if (typeof module !== 'undefined' && module.exports) {
63 module.exports = stripJsonComments;
65 window.stripJsonComments = stripJsonComments;