diff --git a/.eslintrc b/.eslintrc index fa9296a..12affd2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,7 +18,7 @@ rules: eqeqeq: 2 use-isnan: 2 no-eq-null: 2 - brace-style: 2 + // brace-style: 2 spaced-line-comment: 2 valid-jsdoc: 2 space-infix-ops: 2 @@ -37,7 +37,9 @@ rules: camelcase: 2 new-cap: 2 consistent-this: [1, "_this"] - func-names: 2 + //func-names: 2 key-spacing: 2 no-dupe-keys: 2 strict: 2 + no-process-exit: 0 + no-underscore-dangle: 0 diff --git a/Makefile b/Makefile index d8817f3..f4539e9 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ NPM = npm PEGJS = node_modules/.bin/pegjs BROWSERIFY = node_modules/.bin/browserify UGLIFY = node_modules/.bin/uglifyjs -LINTER = node_modules/.bin/jshint +LINTER = node_modules/.bin/eslint MOCHA = node_modules/.bin/mocha all: build browser @@ -30,7 +30,7 @@ bench: benchmark/benchmark.js $(NODE) $< lint: - $(LINTER) index.js bin/cli.js test/index.js test/cli.js + $(LINTER) index.js bin/cli.js test: test/* $(MOCHA) diff --git a/bin/cli.js b/bin/cli.js index d2e6f5b..13114e9 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -25,8 +25,8 @@ program .option(' --hex', 'Output in hex encoding') .option(' --base64', 'Output in base64 encoding'); -function Runtime(program) { - this.program = program; +function Runtime(cli) { + this.program = cli; this.availablePlugins = { yaml: 'js-yaml', msgpack: 'msgpack', @@ -42,15 +42,15 @@ Runtime.prototype.error = function(str) { }; Runtime.prototype.loadPlugins = function() { - var rt = this; + var _this = this; var plugins = {}; var config = this.availablePlugins; Object.keys(config).forEach(function(k) { - if(rt.program[k]) { + if(_this.program[k]) { try { plugins[k] = require(config[k]); } catch (e) { - rt.error('Cannot load package: '+config[k]+' ('+k+' mode)\n'+ - 'Installation instruction: npm install -g '+config[k]); + _this.error('Cannot load package: ' + config[k] + ' (' + k + ' mode)\n' + + 'Installation instruction: npm install -g ' + config[k]); } } }); @@ -67,7 +67,7 @@ Runtime.prototype.loadRc = function() { if(fs.existsSync(fn)) { return require(fn); } - return this.error('rc file not exists: '+this.program.usonrc); + return this.error('rc file not exists: ' + this.program.usonrc); } fn = path.resolve(home, RCFILE); if(fs.existsSync(fn)) { @@ -91,18 +91,18 @@ Runtime.prototype.parse = function(input) { if(this.program.form) { return this.plugins.form.stringify(output); } - return JSON.stringify(output, null, space)+'\n'; + return JSON.stringify(output, null, space) + '\n'; }; Runtime.prototype.listenStdin = function() { - var rt = this; - process.stdin.on('data', function (buf) { + var _this = this; + process.stdin.on('data', function(buf) { var str = buf.toString().trim(); if(!str) { return; } - rt.process(str); + _this.process(str); }); - process.stdin.on('end', function () { + process.stdin.on('end', function() { process.exit(); }); }; @@ -110,16 +110,16 @@ Runtime.prototype.listenStdin = function() { Runtime.prototype.writeData = function(data) { if(this.program.output) { if(fs.existsSync(this.program.output)) { - return this.error('File exists: '+this.program.output+', exiting ..'); + return this.error('File exists: ' + this.program.output + ', exiting ..'); } fs.writeFileSync(this.program.output, data); - console.log('File saved: '+this.program.output); - return; + console.log('File saved: ' + this.program.output); + return true; } if(this.program.hex) { - data = new Buffer(data).toString('hex')+'\n'; + data = new Buffer(data).toString('hex') + '\n'; } else if(this.program.base64) { - data = new Buffer(data).toString('base64')+'\n'; + data = new Buffer(data).toString('base64') + '\n'; } process.stdout.write(data); }; @@ -128,15 +128,15 @@ Runtime.prototype.process = function(data) { this.writeData(this.parse(data)); }; -(function runProgram(program) { - - var runtime = new Runtime(program); +(function runProgram(cli) { + var runtime = new Runtime(cli); + var data; if(program.input) { if(!fs.existsSync(program.input)) { runtime.error('File not exists: ' + program.input); } - var data = fs.readFileSync(program.input).toString(); + data = fs.readFileSync(program.input).toString(); runtime.process(data); } diff --git a/dist/uson.min.js b/dist/uson.min.js index 9973456..be293a7 100644 --- a/dist/uson.min.js +++ b/dist/uson.min.js @@ -1 +1 @@ -(function(e){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=e()}else if(typeof define==="function"&&define.amd){define([],e)}else{var t;if(typeof window!=="undefined"){t=window}else if(typeof global!=="undefined"){t=global}else if(typeof self!=="undefined"){t=self}else{t=this}t.USON=e()}})(function(){var e,t,r;return function i(e,t,r){function n(u,l){if(!t[u]){if(!e[u]){var s=typeof require=="function"&&require;if(!l&&s)return s(u,!0);if(f)return f(u,!0);var o=new Error("Cannot find module '"+u+"'");throw o.code="MODULE_NOT_FOUND",o}var a=t[u]={exports:{}};e[u][0].call(a.exports,function(t){var r=e[u][1][t];return n(r?r:t)},a,a.exports,i,e,t,r)}return t[u].exports}var f=typeof require=="function"&&require;for(var u=0;u1?arguments[1]:{},i={},n={uson_text:vt},f=vt,u=i,l=null,s=[],o=function(e,t){if(e==null&&ft()!=="null"){return[]}return[e].concat(t)},a=function(e){return e},c="[",p={type:"literal",value:"[",description:'"["'},h="{",v={type:"literal",value:"{",description:'"{"'},d="]",y={type:"literal",value:"]",description:'"]"'},A="}",F={type:"literal",value:"}",description:'"}"'},g=":",C={type:"literal",value:":",description:'":"'},w=/^[ ,]/,b={type:"class",value:"[ ,]",description:"[ ,]"},m="#",x={type:"literal",value:"#",description:'"#"'},j="!",O={type:"literal",value:"!",description:'"!"'},E=/^[ \t\n\r]/,S={type:"class",value:"[ \\t\\n\\r]",description:"[ \\t\\n\\r]"},R={type:"other",description:"whitespace"},z="false",Z={type:"literal",value:"false",description:'"false"'},_=function(){return false},N="null",q={type:"literal",value:"null",description:'"null"'},U=function(){return null},D="true",$={type:"literal",value:"true",description:'"true"'},I=function(){return true},J=function(e){return e},T=function(e,t){var r={},i;r[e.name]=e.value;for(i=0;it){Ye=0;et={line:1,column:1,seenCR:false}}r(et,Ye,t);Ye=t}return et}function pt(e){if(Wett){tt=We;rt=[]}rt.push(e)}function ht(r,i,n){function f(e){var t=1;e.sort(function(e,t){if(e.descriptiont.description){return 1}else{return 0}});while(t1?i.slice(0,-1).join(", ")+" or "+i[e.length-1]:i[0];f=t?'"'+r(t)+'"':"end of input";return"Expected "+n+" but "+f+" found."}var l=ct(n),s=n1?arguments[1]:{},i={},n={uson_text:vt},f=vt,u=i,l=null,s=[],o=function(e,t){if(e==null&&ft()!=="null"){return[]}return[e].concat(t)},a=function(e){return e},c="[",p={type:"literal",value:"[",description:'"["'},h="{",v={type:"literal",value:"{",description:'"{"'},d="]",y={type:"literal",value:"]",description:'"]"'},A="}",F={type:"literal",value:"}",description:'"}"'},g=":",C={type:"literal",value:":",description:'":"'},w=/^[ ,]/,b={type:"class",value:"[ ,]",description:"[ ,]"},m="#",x={type:"literal",value:"#",description:'"#"'},j="!",O={type:"literal",value:"!",description:'"!"'},E=/^[ \t\n\r]/,S={type:"class",value:"[ \\t\\n\\r]",description:"[ \\t\\n\\r]"},R={type:"other",description:"whitespace"},z="false",Z={type:"literal",value:"false",description:'"false"'},_=function(){return false},N="null",q={type:"literal",value:"null",description:'"null"'},U=function(){return null},D="true",$={type:"literal",value:"true",description:'"true"'},I=function(){return true},J=function(e){return e},T=function(e,t){var r={},i;r[e.name]=e.value;for(i=0;it){Ye=0;et={line:1,column:1,seenCR:false}}r(et,Ye,t);Ye=t}return et}function pt(e){if(Wett){tt=We;rt=[]}rt.push(e)}function ht(r,i,n){function f(e){var t=1;e.sort(function(e,t){if(e.descriptiont.description){return 1}else{return 0}});while(t1?i.slice(0,-1).join(", ")+" or "+i[e.length-1]:i[0];f=t?'"'+r(t)+'"':"end of input";return"Expected "+n+" but "+f+" found."}var l=ct(n),s=n