5 <title>JSDoc: Source: minify.json.js
</title>
7 <script src=
"scripts/prettify/prettify.js"> </script>
8 <script src=
"scripts/prettify/lang-css.js"> </script>
10 <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
12 <link type=
"text/css" rel=
"stylesheet" href=
"styles/prettify-tomorrow.css">
13 <link type=
"text/css" rel=
"stylesheet" href=
"styles/jsdoc-default.css">
20 <h1 class=
"page-title">Source: minify.json.js
</h1>
28 <pre class=
"prettyprint source"><code>/*! JSON.minify()
33 * @name minify.json.js
34 * @author Kei Funagayama
<kei.topaz@gmail.com
35 * @overview JSON.minify
47 * @param {Object} Transformed data. format) json-like
51 * var json = { // hoge
52 * "foo": "bar",// this is cool
54 * "baz", "bum", "zam" // this is cool
59 var minify = function (json) {
61 var tokenizer = /"|(\/\*)|(\*\/)|(\/\/)|\n|\r/g,
63 in_multiline_comment = false,
64 in_singleline_comment = false,
65 tmp, tmp2, new_str = [], ns =
0, from =
0, lc, rc
68 tokenizer.lastIndex =
0;
70 while ( tmp = tokenizer.exec(json) ) {
71 lc = RegExp.leftContext;
72 rc = RegExp.rightContext;
73 if (!in_multiline_comment && !in_singleline_comment) {
74 tmp2 = lc.substring(from);
76 tmp2 = tmp2.replace(/(\n|\r|\s)*/g,"");
80 from = tokenizer.lastIndex;
82 if (tmp[
0] === "\"" && !in_multiline_comment && !in_singleline_comment) {
83 tmp2 = lc.match(/(\\)*$/);
84 if (!in_string || !tmp2 || (tmp2[
0].length %
2) ===
0) { // start of string with ", or unescaped " character found to end string
85 in_string = !in_string;
87 from--; // include " character in next catch
88 rc = json.substring(from);
90 else if (tmp[
0] === "/*" && !in_string && !in_multiline_comment && !in_singleline_comment) {
91 in_multiline_comment = true;
93 else if (tmp[
0] === "*/" && !in_string && in_multiline_comment && !in_singleline_comment) {
94 in_multiline_comment = false;
96 else if (tmp[
0] === "//" && !in_string && !in_multiline_comment && !in_singleline_comment) {
97 in_singleline_comment = true;
99 else if ((tmp[
0] === "\n" || tmp[
0] === "\r") && !in_string && !in_multiline_comment && in_singleline_comment) {
100 in_singleline_comment = false;
102 else if (!in_multiline_comment && !in_singleline_comment && !(/\n|\r|\s/.test(tmp[
0]))) {
103 new_str[ns++] = tmp[
0];
107 return new_str.join("");
110 if (typeof module !== 'undefined' && module.exports) {
112 module.exports = minify;
113 JSON.minify = minify;
115 // others, export global
116 if (typeof global.JSON === "undefined" || !global.JSON) {
119 global.JSON.minify = minify;
132 <h2><a href=
"index.html">Index
</a></h2><h3>Namespaces
</h3><ul><li><a href=
"JSON.html">JSON
</a></li></ul>
138 Documentation generated by
<a href=
"https://github.com/jsdoc3/jsdoc">JSDoc
3.3.0-dev
</a> on Mon Sep
30 2013 14:
37:
29 GMT+
0900 (JST)
141 <script> prettyPrint();
</script>
142 <script src=
"scripts/linenumber.js"> </script>