Sha256: 5717342b928e6ee1a2f2dffb7d5f5bc3be9924334d2f834d6eea5c8808888069

Contents?: true

Size: 1.64 KB

Versions: 120

Compression:

Stored size: 1.64 KB

Contents

/*!
	strip-json-comments
	Strip comments from JSON. Lets you use comments in your JSON files!
	https://github.com/sindresorhus/strip-json-comments
	by Sindre Sorhus
	MIT License
*/
(function () {
	'use strict';

	var singleComment = 1;
	var multiComment = 2;

	function stripJsonComments(str) {
		var currentChar;
		var nextChar;
		var insideString = false;
		var insideComment = false;
		var ret = '';

		for (var i = 0; i < str.length; i++) {
			currentChar = str[i];
			nextChar = str[i + 1];

			if (!insideComment && currentChar === '"') {
				var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
				if (!insideComment && !escaped && currentChar === '"') {
					insideString = !insideString;
				}
			}

			if (insideString) {
				ret += currentChar;
				continue;
			}

			if (!insideComment && currentChar + nextChar === '//') {
				insideComment = singleComment;
				i++;
			} else if (insideComment === singleComment && currentChar + nextChar === '\r\n') {
				insideComment = false;
				i++;
				ret += currentChar;
				ret += nextChar;
				continue;
			} else if (insideComment === singleComment && currentChar === '\n') {
				insideComment = false;
			} else if (!insideComment && currentChar + nextChar === '/*') {
				insideComment = multiComment;
				i++;
				continue;
			} else if (insideComment === multiComment && currentChar + nextChar === '*/') {
				insideComment = false;
				i++;
				continue;
			}

			if (insideComment) {
				continue;
			}

			ret += currentChar;
		}

		return ret;
	}

	if (typeof module !== 'undefined' && module.exports) {
		module.exports = stripJsonComments;
	} else {
		window.stripJsonComments = stripJsonComments;
	}
})();

Version data entries

120 entries across 120 versions & 7 rubygems

Version Path
govuk_publishing_components-18.0.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.21.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.20.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.19.1 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.19.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.18.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.17.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.16.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.15.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.14.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.13.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.12.2 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.12.1 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.12.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.11.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.10.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.9.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.8.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.7.0 node_modules/strip-json-comments/strip-json-comments.js
govuk_publishing_components-17.6.1 node_modules/strip-json-comments/strip-json-comments.js