JSON.minify-0.4.1/000077500000000000000000000000001266550502700135675ustar00rootroot00000000000000JSON.minify-0.4.1/.gitignore000066400000000000000000000000611266550502700155540ustar00rootroot00000000000000.DS_Store node_modules npm-debug.log .idea *.iml JSON.minify-0.4.1/.jsdoc3.json000066400000000000000000000003171266550502700157260ustar00rootroot00000000000000{ "tags": { "allowUnknownTags": true }, "source": { "includePattern": ".+\\.js(doc)?$", "excludePattern": "(^|\\/|\\\\)_" }, "plugins": [], "jsVersion": 180 } JSON.minify-0.4.1/.jshintignore000066400000000000000000000000221266550502700162650ustar00rootroot00000000000000node_modules test JSON.minify-0.4.1/.jshintrc000066400000000000000000000076151266550502700154250ustar00rootroot00000000000000{ // Settings "passfail" : false, // Stop on first error. "maxerr" : 100, // Maximum errors before stopping. // Predefined globals whom JSHint will ignore. "browser" : true, // Standard browser globals e.g. `window`, `document`. "node" : true, "rhino" : false, "couch" : false, "wsh" : true, // Windows Scripting Host. "jquery" : true, "prototypejs" : false, "mootools" : false, "dojo" : false, "predef" : [ // Extra globals. "describe", // Used by mocha "it", // Used by mocha "before", // Used by mocha "beforeEach", // Used by mocha "after", // Used by mocha "afterEach" // Used by mocha ], // Development. "debug" : false, // Allow debugger statements e.g. browser breakpoints. "devel" : true, // Allow development statements e.g. `console.log();`. // EcmaScript 5. //"es5" : true, // Allow EcmaScript 5 syntax. "strict" : false, // Require `use strict` pragma in every file. "globalstrict" : false, // Allow global "use strict" (also enables 'strict'). // The Good Parts. "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons). "laxbreak" : true, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons. "bitwise" : false, // Prohibit bitwise operators (&, |, ^, etc.). "boss" : true, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments. "curly" : true, // Require {} for every new block or scope. "eqeqeq" : true, // Require triple equals i.e. `===`. "eqnull" : false, // Tolerate use of `== null`. "evil" : false, // Tolerate use of `eval`. "expr" : true, // Tolerate `ExpressionStatement` as Programs. "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`. "immed" : false, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );` "latedef" : true, // Prohibit variable use before definition. "loopfunc" : true, // Allow functions to be defined within loops. "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`. "proto" : true, // Tolerate the __proto__ property. "regexp" : false, // Prohibit `.` and `[^...]` in regular expressions. "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`. "scripturl" : true, // Tolerate script-targeted URLs. "smarttabs" : true, // This option suppresses warnings about mixed tabs and spaces when the latter are used for alignmnent only. "shadow" : true, // Allows re-define variables later in code e.g. `var x=1; x=2;`. "supernew" : true, // Tolerate `new function () { ... };` and `new Object;`. "undef" : true, // Require all non-global variables be declared before they are used. // Persone styling prefrences. "newcap" : true, // Require capitalization of all constructor functions e.g. `new F()`. "noempty" : false, // Prohibit use of empty blocks. "nonew" : true, // Prohibit use of constructors for side-effects. "nomen" : false, // Prohibit use of initial or trailing underbars in names. "onevar" : false, // Allow only one `var` statement per function. "plusplus" : false, // Prohibit use of `++` & `--`. "sub" : false, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`. "trailing" : true, // Prohibit trailing whitespaces. "white" : false // Check against strict whitespace and indentation rules. } JSON.minify-0.4.1/.travis.yml000066400000000000000000000000611266550502700156750ustar00rootroot00000000000000language: node_js node_js: - "0.11" - "0.10" JSON.minify-0.4.1/Makefile000066400000000000000000000011071266550502700152260ustar00rootroot00000000000000__jsdoc=node_modules/.bin/jsdoc __plato=node_modules/plato/bin/plato __mocha=node_modules/.bin/mocha __jshint=node_modules/jshint/bin/jshint __prog=minify.json.js all: jshint test release: init jshint test-doc jsdoc report init: mkdir -p report mkdir -p docs jshint: $(__jshint) --config .jshintrc $(__prog) test: $(__mocha) -r should test/test-*.js test-doc: $(__mocha) -r should test/test-*.js -R doc 2>&1 > TestDoc.html jsdoc: $(__jsdoc) -c .jsdoc3.json -d docs -p -r -l $(__prog) report: $(__plato) -d ./report -r $(__prog) .PHONY: all jshint test jsdoc report JSON.minify-0.4.1/PORTING.txt000066400000000000000000000017671266550502700154650ustar00rootroot00000000000000As you can see comparing the PHP port to the original JS code, the spirit of what I want to do is implement the code in as similar a code algorithm as possible for now, until we're more sure the algorithm is either solid (bug free) or perhaps we decide on a better universal algorithm. But the more similar the code algorithm implementations are, the easier it will be to maintain the various ports if changes must occur. In as much as possible, my preference is to use core/built-in parts of each language rather than plugins. That lets the most people have a chance to use it. If that's not practical in some situation, fine, document it. But if possible, that's preferred. The test.minify.html file shows 4 different test inputs which exercise the algorithm and show the correct outputs. Those same tests should pass on the ports, obviously. Process would just be to fork this repo and add the files, in the style of "minify.json.rb" for ruby, for instance, and then send me a pull request. JSON.minify-0.4.1/README.md000066400000000000000000000074151266550502700150550ustar00rootroot00000000000000# About ![Travis CI](https://travis-ci.org/fkei/JSON.minify.png?branch=master) # Feature /*! JSON.minify() v0.1 (c) Kyle Simpson MIT License */ JSON.minify() minifies blocks of JSON-like content into valid JSON by removing all whitespace *and* comments. JSON parsers (like JavaScript's JSON.parse() parser) generally don't consider JSON with comments to be valid and parseable. So, the intended usage is to minify development-friendly JSON (with comments) to valid JSON before parsing, such as: JSON.parse(JSON.minify(str)); Now you can maintain development-friendly JSON documents, but minify them before parsing or before transmitting them over-the-wire. Though comments are not officially part of the JSON standard, this post from Douglas Crockford back in late 2005 helps explain the motivation behind this project. http://tech.groups.yahoo.com/group/json/message/152 "A JSON encoder MUST NOT output comments. A JSON decoder MAY accept and ignore comments." Basically, comments are not in the JSON *generation* standard, but that doesn't mean that a parser can't be taught to ignore them. Which is exactly what JSON.minify() is for. The first implementation of JSON.minify() is in JavaScript, but the intent is to port the implementation to as many other environments as possible/practical. NOTE: As transmitting bloated (ie, with comments/whitespace) JSON would be wasteful and silly, this JSON.minify() is intended for use in server-side processing environments where you can strip comments/whitespace from JSON before parsing a JSON document, or before transmitting such over-the-wire from server to browser. # install ## npm repo ``` $ npm install jsonminify ``` ## npm source ``` $ npm install https://github.com/fkei/JSON.minify.git ``` # example ```javascript var jsonminify = require("jsonminify"); jsonminify('{"key":"value"/** comment **/}') >> '{"key":"value"}' JSON.minify('{"key":"value"/** comment **/}') >> '{"key":"value"}' ``` # command-line Please use here. Use JSON.minify internally. **node-mjson** [https://github.com/fkei/node-mjson](https://github.com/fkei/node-mjson) # build ``` $ make ``` # release ``` $ make release ``` # test ``` $ make test ``` # jshint ``` $ make jshint ``` # Document - [JSDoc - API Document](http://fkei.github.io/JSON.minify/docs/index.html) - [Plato - Report](http://fkei.github.io/JSON.minify/report/index.html) - [Mocha - Test result (HTML)](http://fkei.github.io/JSON.minify/TestDoc.html) # Web-Site **[Github pages - JSON.minify Home Page](http://fkei.github.io/JSON.minify/)** # LICENSE forked from [getify/JSON.minify](https://github.com/getify/JSON.minify) ``` The MIT License (MIT) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ``` [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/fkei/json.minify/trend.png)](https://bitdeli.com/free "Bitdeli Badge") JSON.minify-0.4.1/TestDoc.html000066400000000000000000000045421266550502700160270ustar00rootroot00000000000000

JSON.minify

define
JSON.minify.should.be.ok;
in-memory string
var json = '{"key":"value"}';
var res = JSON.minify(json);
JSON.parse(res).key.should.equal('value');
comment.json
var json = fs.readFileSync(__dirname + '/comment.json', 'utf8');
var res = JSON.parse(JSON.minify(json));
res.foo.should.equal('bar');
comment.json
var json = fs.readFileSync(__dirname + '/plain.json', 'utf8');
var res = JSON.parse(JSON.minify(json));
res.foo.should.equal('bar');
in-memory string json.array plain
var json = '[1,2,3]';
var res = JSON.parse(JSON.minify(json));
res.length.should.equal(3);
in-memory string json.array start line comment
var json = '//[1,2,3]\n[4,5,6,7]';
var res = JSON.parse(JSON.minify(json));
res.length.should.equal(4);
should(res[0]).be.exactly(4).and.be.a.Number();
in-memory string json.array start multi comment
var json = '/**[1,2,3]*/[8,9,10,11]';
var res = JSON.parse(JSON.minify(json));
res.length.should.equal(4);
should(res[0]).be.exactly(8).and.be.a.Number();
in-memory string json.array end line comment
var json = '[4,5,6,7]//[1,2,3]';
var res = JSON.parse(JSON.minify(json));
res.length.should.equal(4);
should(res[0]).be.exactly(4).and.be.a.Number();
in-memory string json.array end multi comment
var json = '[8,9,10,11]/**[1,2,3]*/';
var res = JSON.parse(JSON.minify(json));
res.length.should.equal(4);
should(res[0]).be.exactly(8).and.be.a.Number();
array_comment.json
var json = fs.readFileSync(__dirname + '/array_comment.json', 'utf8');
var res = JSON.parse(JSON.minify(json));
should(res.length).be.exactly(3).and.be.a.Number();
should(res[0]['somethi""ng'].length).be.exactly(4).and.be.a.Number();
should(res[0]['somethi""ng'][3]).be.exactly(23).and.be.a.Number();
JSON.minify-0.4.1/minify.json.js000066400000000000000000000057441266550502700164020ustar00rootroot00000000000000/*! JSON.minify() v0.1 (c) Kyle Simpson MIT License */ /** * @name minify.json.js * @author Kei Funagayama =0.8.0", "npm": ">=1.1.0" }, "main": "./minify.json.js" } JSON.minify-0.4.1/test.minify.html000066400000000000000000000046061266550502700167340ustar00rootroot00000000000000 Test JSON.minify()

Test JSON.minify()

console.log views.

test #1

result #1

test #2

result #2

test #3

result #3

test #4

result #4

test #5

result #5

JSON.minify-0.4.1/test/000077500000000000000000000000001266550502700145465ustar00rootroot00000000000000JSON.minify-0.4.1/test/array_comment.json000066400000000000000000000025101266550502700202770ustar00rootroot00000000000000/** * spam */ // spam [ // foo { // hoge "fo\\\\o": "ba\"r",// this is cool "ba\\r": [ "baz", "b\"\"u\"m", /** aaaa **/"zam" // this is cool ], /* the rest of this document is just fluff in case you are interested. */ "somethi\"\"ng": [10,11,12, /*aaa */23], // a /** the rest of this document is just fluff *in case you are interested. */ "else": 20 }, // hoge { // hoge "fo\\\\o": "ba\"r",// this is cool "ba\\r": [ "baz", "b\"\"u\"m", /** aaaa **/"zam" // this is cool ], /* the rest of this document is just fluff in case you are interested. */ "somethi\"\"ng": [10,11,12, /*aaa */23], // a /** the rest of this document is just fluff *in case you are interested. */ "else": 20 }, // hoge { // hoge "fo\\\\o": "ba\"r",// this is cool "ba\\r": [ "baz", "b\"\"u\"m", /** aaaa **/"zam" // this is cool ], /* the rest of this document is just fluff in case you are interested. */ "somethi\"\"ng": [10,11,12, /*aaa */23], // a /** the rest of this document is just fluff *in case you are interested. */ "else": 20 } // hoge ] // foo /** * spam */ // spam JSON.minify-0.4.1/test/comment.json000066400000000000000000000005211266550502700171010ustar00rootroot00000000000000{ // hoge "foo": "bar",// this is cool "bar": [ "baz", "bum", /** aaaa **/"zam" // this is cool ], /* the rest of this document is just fluff in case you are interested. */ "something": 10, /** the rest of this document is just fluff *in case you are interested. */ "else": 20 } // hoge JSON.minify-0.4.1/test/mocha.opts000066400000000000000000000000711266550502700165420ustar00rootroot00000000000000--ui bdd --reporter spec --timeout 5000 --require should JSON.minify-0.4.1/test/plain.json000066400000000000000000000001521266550502700165420ustar00rootroot00000000000000{ "foo": "bar", "bar": [ "baz", "bum", "zam" ], "something": 10, "else": 20 } JSON.minify-0.4.1/test/test-minify.json.js000066400000000000000000000045411266550502700203300ustar00rootroot00000000000000var fs = require('fs'); var should = require('should'); require('../minify.json.js'); describe('JSON.minify', function() { it('define', function() { JSON.minify.should.be.ok; }); it('in-memory string', function() { var json = '{"key":"value"}'; var res = JSON.minify(json); JSON.parse(res).key.should.equal('value'); }); it('comment.json', function() { var json = fs.readFileSync(__dirname + '/comment.json', 'utf8'); var res = JSON.parse(JSON.minify(json)); res.foo.should.equal('bar'); }); it('comment.json', function() { var json = fs.readFileSync(__dirname + '/plain.json', 'utf8'); var res = JSON.parse(JSON.minify(json)); res.foo.should.equal('bar'); }); it('in-memory string json.array plain', function() { var json = '[1,2,3]'; var res = JSON.parse(JSON.minify(json)); res.length.should.equal(3); }); it('in-memory string json.array start line comment', function() { var json = '//[1,2,3]\n[4,5,6,7]'; var res = JSON.parse(JSON.minify(json)); res.length.should.equal(4); should(res[0]).be.exactly(4).and.be.a.Number(); }); it('in-memory string json.array start multi comment', function() { var json = '/**[1,2,3]*/[8,9,10,11]'; var res = JSON.parse(JSON.minify(json)); res.length.should.equal(4); should(res[0]).be.exactly(8).and.be.a.Number(); }); it('in-memory string json.array end line comment', function() { var json = '[4,5,6,7]//[1,2,3]'; var res = JSON.parse(JSON.minify(json)); res.length.should.equal(4); should(res[0]).be.exactly(4).and.be.a.Number(); }); it('in-memory string json.array end multi comment', function() { var json = '[8,9,10,11]/**[1,2,3]*/'; var res = JSON.parse(JSON.minify(json)); res.length.should.equal(4); should(res[0]).be.exactly(8).and.be.a.Number(); }); it('array_comment.json', function() { var json = fs.readFileSync(__dirname + '/array_comment.json', 'utf8'); var res = JSON.parse(JSON.minify(json)); should(res.length).be.exactly(3).and.be.a.Number(); should(res[0]['somethi""ng'].length).be.exactly(4).and.be.a.Number(); should(res[0]['somethi""ng'][3]).be.exactly(23).and.be.a.Number(); }); });