# add dist

This commit is contained in:
Mario Romano
2016-04-21 11:56:31 +01:00
parent 5914688467
commit 07807e7bc3
13499 changed files with 1808930 additions and 5 deletions

View File

@@ -0,0 +1,3 @@
test:
@./node_modules/.bin/mocha test.js

View File

@@ -0,0 +1,32 @@
/**
* JSON parse.
*
* @see Based on jQuery#parseJSON (MIT) and JSON2
* @api private
*/
var rvalidchars = /^[\],:{}\s]*$/;
var rvalidescape = /\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g;
var rvalidtokens = /"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g;
var rvalidbraces = /(?:^|:|,)(?:\s*\[)+/g;
var rtrimLeft = /^\s+/;
var rtrimRight = /\s+$/;
module.exports = function parsejson(data) {
if ('string' != typeof data || !data) {
return null;
}
data = data.replace(rtrimLeft, '').replace(rtrimRight, '');
// Attempt to parse using the native JSON parser first
if (global.JSON && JSON.parse) {
return JSON.parse(data);
}
if (rvalidchars.test(data.replace(rvalidescape, '@')
.replace(rvalidtokens, ']')
.replace(rvalidbraces, ''))) {
return (new Function('return ' + data))();
}
};

View File

@@ -0,0 +1,62 @@
{
"_args": [
[
"parsejson@0.0.1",
"/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/browser-sync/node_modules/engine.io-client"
]
],
"_from": "parsejson@0.0.1",
"_id": "parsejson@0.0.1",
"_inCache": true,
"_installable": true,
"_location": "/parsejson",
"_npmUser": {
"email": "koren@mit.edu",
"name": "gal"
},
"_npmVersion": "1.3.15",
"_phantomChildren": {},
"_requested": {
"name": "parsejson",
"raw": "parsejson@0.0.1",
"rawSpec": "0.0.1",
"scope": null,
"spec": "0.0.1",
"type": "version"
},
"_requiredBy": [
"/browser-sync/engine.io-client"
],
"_resolved": "https://registry.npmjs.org/parsejson/-/parsejson-0.0.1.tgz",
"_shasum": "9b10c6c0d825ab589e685153826de0a3ba278bcc",
"_shrinkwrap": null,
"_spec": "parsejson@0.0.1",
"_where": "/Users/mromano/dev/dev-platform-webcomponents/ng2-components/ng2-alfresco-documentslist/node_modules/browser-sync/node_modules/engine.io-client",
"author": "",
"dependencies": {
"better-assert": "~1.0.0"
},
"description": "Method that parses a JSON string and returns a JSON object",
"devDependencies": {
"mocha": "1.17.1"
},
"directories": {},
"dist": {
"shasum": "9b10c6c0d825ab589e685153826de0a3ba278bcc",
"tarball": "https://registry.npmjs.org/parsejson/-/parsejson-0.0.1.tgz"
},
"license": "MIT",
"maintainers": [
{
"email": "koren@mit.edu",
"name": "gal"
}
],
"name": "parsejson",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"scripts": {
"test": "make test"
},
"version": "0.0.1"
}

View File

@@ -0,0 +1,21 @@
var assert = require('better-assert');
var expect = require('expect.js');
var parsejson = require('./index.js');
describe('my suite', function(){
it('should parse a JSON string', function () {
var jsonString = '{"users" :[{"first_name":"foo", "last_name":"bar"}],' +
'"id" :40,' +
'"cities":["los angeles", "new york", "boston"]}';
var jsonObj = parsejson(jsonString);
expect(jsonObj.users[0].first_name).to.be("foo");
expect(jsonObj.users[0].last_name).to.be("bar");
expect(jsonObj.id).to.be(40);
expect(jsonObj.cities[0]).to.be('los angeles');
expect(jsonObj.cities[1]).to.be('new york');
expect(jsonObj.cities[2]).to.be('boston');
});
});