feature(util) json -> jonny

This commit is contained in:
coderaiser 2016-07-28 21:06:03 +03:00
parent ee1c264aac
commit 40f1eb46cc
10 changed files with 190 additions and 34 deletions

View file

@ -40,6 +40,7 @@
"philip": "^1.3.3",
"jquery": "3.1.0",
"promise-polyfill": "6.0.0",
"smalltalk": "2.1.1"
"smalltalk": "2.1.1",
"jonny": "1.0.1"
}
}

View file

@ -35,7 +35,8 @@ var CloudCmd;
libDir('format', 'format-io'),
libDir('rendy'),
libDir('emitify', '', 'dist'),
libDir('exec', 'execon')
libDir('exec', 'execon'),
libDir('jonny')
].filter(function(name) {
return name;
}).map(function(name) {

View file

@ -3,15 +3,18 @@
var exec,
rendy,
jonny,
Scope = scope.window ? window : global;
if (typeof module === 'object' && module.exports) {
exec = require('execon');
rendy = require('rendy');
jonny = require('jonny');
module.exports = new UtilProto(exec);
} else if (!Scope.Util) {
exec = window.exec;
rendy = window.rendy;
jonny = window.jonny;
Scope.Util = new UtilProto(exec);
}
@ -148,35 +151,7 @@
return ret;
};
this.json = new JsonProto();
function JsonProto() {
/**
* @param str
*/
this.parse = function(str) {
var obj;
Util.exec.try(function() {
obj = JSON.parse(str);
});
return obj;
},
/**
* @param obj
*/
this.stringify = function(obj) {
var str;
Util.exec.try(function() {
str = JSON.stringify(obj, null, 4);
});
return str;
};
}
this.json = jonny;
this.escapeRegExp = function(str) {
var isStr = Util.type.string(str);

35
modules/jonny/.bower.json Normal file
View file

@ -0,0 +1,35 @@
{
"name": "jonny",
"version": "1.0.1",
"homepage": "https://github.com/coderaiser/jonny",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "work with json without exaptions",
"main": "lib/jonny.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"json",
"try"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"modules"
],
"dependencies": {},
"_release": "1.0.1",
"_resolution": {
"type": "version",
"tag": "v1.0.1",
"commit": "b8909d33db868af9797c95881891c5d432209f1a"
},
"_source": "https://github.com/coderaiser/jonny.git",
"_target": "^1.0.1",
"_originalSource": "jonny",
"_direct": true
}

21
modules/jonny/LICENSE Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2015 coderaiser
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.

26
modules/jonny/README.md Normal file
View file

@ -0,0 +1,26 @@
# Jonny
Work with json without exeptions.
## Install
```
npm i jonny --save
```
## How to use?
```js
var jonny = require('jonny'),
obj = jonny.parse('{ "hello": "world" }');
console.log(jonny.stringify(obj, 0, 4));
// results
// "{
// "hello": "world"
// }"
```
## License
MIT

26
modules/jonny/bower.json Normal file
View file

@ -0,0 +1,26 @@
{
"name": "jonny",
"version": "1.0.0",
"homepage": "https://github.com/coderaiser/jonny",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "work with json without exaptions",
"main": "lib/jonny.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"json",
"try"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"modules"
],
"dependencies": {
}
}

View file

@ -0,0 +1,45 @@
(function(global) {
'use strict';
if (typeof module !== 'undefined' && module.exports)
module.exports = new Jonny();
else
global.jonny = new Jonny();
function Jonny() {
this.parse = function() {
var ret,
args = arguments;
tryCatch(function() {
ret = JSON.parse.apply(JSON, args);
});
return ret;
};
this.stringify = function() {
var ret,
args = arguments;
tryCatch(function() {
ret = JSON.stringify.apply(JSON, args);
});
return ret;
};
function tryCatch(fn) {
var error;
try {
fn();
} catch(e) {
error = e;
}
return error;
}
}
})(this);

View file

@ -0,0 +1,27 @@
{
"name": "jonny",
"version": "1.0.0",
"description": "work with json without exaptions",
"main": "lib/jonny.js",
"dependencies": {
"diff-match-patch": "~1.0.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git://github.com/coderaiser/jonny.git"
},
"keywords": [
"json",
"try"
],
"author": "coderaiser <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/coderaiser/jonny/issues"
},
"homepage": "https://github.com/coderaiser/jonny"
}

View file

@ -32,7 +32,6 @@
"commit": "d5fbf701270e46919e63d287be0834c6b718ae51"
},
"_source": "https://github.com/coderaiser/smalltalk.git",
"_target": "^2.1.1",
"_originalSource": "smalltalk",
"_direct": true
"_target": "2.1.1",
"_originalSource": "smalltalk"
}