Initial commit

This commit is contained in:
Luis Fernando Molina committed 2018-02-07 21:05:26 +01:00
commit ec49fedc45
1288 files changed
+226749

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
# Logs
logs
*.log
# Debug
debug.js
# Runtime data
pids
*.pid
*.seed
# Editor configuration
.vscode/*
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# node-waf configuration
.lock-wscript
# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules
+17
View File
@@ -0,0 +1,17 @@
language: node_js
node_js:
- "4.1"
- "4.0"
- "0.12"
- "0.10"
- "0.8"
after_script:
- npm run coveralls
install:
- npm install -g npm@1.4.23
- npm --version
- npm install
sudo: false
+22
View File
@@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2016 Yang Xia
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.
+40
View File
@@ -0,0 +1,40 @@
# json-edm-parser
[![Build Status](https://travis-ci.org/yaxia/json-edm-parser.svg?branch=master)](https://travis-ci.org/yaxia/json-edm-parser)
This is a JSON streaming parser for node.js. It will handle the Entity Data Model (EDM) types to be compatitable with odata.
When you use JSON to represent an odata entity, a number without a decimal point in the JSON will have Edm.Int32 by default and
will have Edm.Double if there are non-zero digits after the decimal point. However, if the value is set to *.0,
Most JSON parsers will take it as an integer. To keep the type information, this parser will add an additional member "<property>@odata.type": "Edm.Double"
to the object.
## Install
```shell
npm install json-edm-parser
```
## Usage
```Javascript
var Parser = require('json-edm-parser');
var p = new Parser();
p.write('{ "doubleIntNumber": 12.00,');
p.write('"doubleNormalNumber": 1.2,');
p.write('"doubleLargeNumber": 12345678901234546789.0000000000000000000000000001,');
p.write('"int64LargeNumber": 12345678901234567890123456789}');
/*
* You will get
* { 'doubleIntNumber@odata.type': 'Edm.Double',
* doubleIntNumber: '12.00',
* doubleNormalNumber: 1.2,
* 'doubleLargeNumber@odata.type': 'Edm.Double',
* doubleLargeNumber: '12345678901234546789.0000000000000000000000000001',
* int64LargeNumber: '12345678901234567890123456789' }
*/
p.onValue = function (value) {
// Deal with the value
};
```
+86
View File
@@ -0,0 +1,86 @@
{
"_args": [
[
"json-edm-parser@0.1.2",
"c:\\users\\luis\\source\\repos\\AACharly\\node_modules\\azure-storage"
]
],
"_from": "json-edm-parser@0.1.2",
"_id": "json-edm-parser@0.1.2",
"_inCache": true,
"_location": "/json-edm-parser",
"_nodeVersion": "5.10.1",
"_npmOperationalInternal": {
"host": "packages-16-east.internal.npmjs.com",
"tmp": "tmp/json-edm-parser-0.1.2.tgz_1463020378810_0.7195477483328432"
},
"_npmUser": {
"email": "xycruise@msn.com",
"name": "yaxia"
},
"_npmVersion": "3.8.3",
"_phantomChildren": {},
"_requested": {
"name": "json-edm-parser",
"raw": "json-edm-parser@0.1.2",
"rawSpec": "0.1.2",
"scope": null,
"spec": "0.1.2",
"type": "version"
},
"_requiredBy": [
"/azure-storage"
],
"_resolved": "https://registry.npmjs.org/json-edm-parser/-/json-edm-parser-0.1.2.tgz",
"_shasum": "1e60b0fef1bc0af67bc0d146dfdde5486cd615b4",
"_shrinkwrap": null,
"_spec": "json-edm-parser@0.1.2",
"_where": "c:\\users\\luis\\source\\repos\\AACharly\\node_modules\\azure-storage",
"author": {
"name": "Yang Xia"
},
"bugs": {
"url": "https://github.com/yaxia/json-edm-parser/issues"
},
"dependencies": {
"jsonparse": "~1.2.0"
},
"description": "This is a JSON streaming parser for node.js. It will handle the Entity Data Model (EDM) types to be compatitable with odata.",
"devDependencies": {
"tap": "~5.0.0",
"tape": "~4.4.0"
},
"directories": {},
"dist": {
"shasum": "1e60b0fef1bc0af67bc0d146dfdde5486cd615b4",
"tarball": "https://registry.npmjs.org/json-edm-parser/-/json-edm-parser-0.1.2.tgz"
},
"gitHead": "b50508e0e2bf85f97a1ac281ed1f1425ad769816",
"homepage": "https://github.com/yaxia/json-edm-parser#readme",
"installable": true,
"keywords": [
"edm",
"json",
"odata",
"parser",
"stream"
],
"license": "MIT",
"main": "parser.js",
"maintainers": [
{
"name": "yaxia",
"email": "xycruise@msn.com"
}
],
"name": "json-edm-parser",
"optionalDependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/yaxia/json-edm-parser.git"
},
"scripts": {
"test": "tap test/*.js"
},
"version": "0.1.2"
}
+85
View File
@@ -0,0 +1,85 @@
// The MIT License (MIT)
//
// Copyright (c) 2016 Yang Xia
//
// 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.
'use strict';
var util = require('util');
var JsonParser = require('jsonparse');
exports = module.exports;
util.inherits(Parser, JsonParser);
/**
* Parser Instructor
*/
function Parser() {
this.internalParser = new JsonParser();
this.originalOnToken = this.internalParser.onToken;
this.internalParser.onToken = onToken.bind(this);
return this.internalParser;
}
/**
* Handles the EDM types in the JSON object
* 1. Number will be treated as Edm.Int32 by default
* 2. Literal value 1.0 will be treated as Edm.Double
* 3. Others will be handled according to the literal value
*/
var onToken = function (token, value) {
var self = this;
var emitString = false;
function additionalEmit(additionalKey, additionalValue) {
var oldKey = self.internalParser.key;
self.internalParser.key = additionalKey;
self.internalParser.onValue(additionalValue);
self.internalParser.key = oldKey;
}
if (token === JsonParser.C.STRING ||
token === JsonParser.C.NUMBER ||
token === JsonParser.C.TRUE ||
token === JsonParser.C.FALSE ||
token === JsonParser.C.NULL) {
// Parser will emit value in these cases
if (typeof value === 'number' &&
this.internalParser.string.indexOf('.') != -1 &&
parseInt(this.internalParser.string) === value &&
this.internalParser.mode !== JsonParser.C.ARRAY) {
var typeKey = this.internalParser.key + '@odata.type';
if (this.internalParser.value) {
this.internalParser.value[typeKey] = 'Edm.Double';
}
additionalEmit(typeKey, 'Edm.Double');
// Determine whether return raw string to avoid losing precision
emitString = this.internalParser.string !== value.toString();
}
}
if (emitString) {
this.originalOnToken.call(this.internalParser, token, this.internalParser.string);
} else {
this.originalOnToken.call(this.internalParser, token, value);
}
};
Parser.C = JsonParser.C;
module.exports = Parser;
+102
View File
@@ -0,0 +1,102 @@
var test = require('tape');
var Parser = require('../');
test('2 byte utf8 \'De\' character: д', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, 'д');
};
var de_buffer = new Buffer([0xd0, 0xb4]);
p.write('"');
p.write(de_buffer);
p.write('"');
});
test('3 byte utf8 \'Han\' character: 我', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, '我');
};
var han_buffer = new Buffer([0xe6, 0x88, 0x91]);
p.write('"');
p.write(han_buffer);
p.write('"');
});
test('4 byte utf8 character (unicode scalar U+2070E): 𠜎', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, '𠜎');
};
var Ux2070E_buffer = new Buffer([0xf0, 0xa0, 0x9c, 0x8e]);
p.write('"');
p.write(Ux2070E_buffer);
p.write('"');
});
test('3 byte utf8 \'Han\' character chunked inbetween 2nd and 3rd byte: 我', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, '我');
};
var han_buffer_first = new Buffer([0xe6, 0x88]);
var han_buffer_second = new Buffer([0x91]);
p.write('"');
p.write(han_buffer_first);
p.write(han_buffer_second);
p.write('"');
});
test('4 byte utf8 character (unicode scalar U+2070E) chunked inbetween 2nd and 3rd byte: 𠜎', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, '𠜎');
};
var Ux2070E_buffer_first = new Buffer([0xf0, 0xa0]);
var Ux2070E_buffer_second = new Buffer([0x9c, 0x8e]);
p.write('"');
p.write(Ux2070E_buffer_first);
p.write(Ux2070E_buffer_second);
p.write('"');
});
test('1-4 byte utf8 character string chunked inbetween random bytes: Aж文𠜱B', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, 'Aж文𠜱B');
};
var eclectic_buffer = new Buffer([0x41, // A
0xd0, 0xb6, // ж
0xe6, 0x96, 0x87, // 文
0xf0, 0xa0, 0x9c, 0xb1, // 𠜱
0x42]); // B
var rand_chunk = Math.floor(Math.random() * (eclectic_buffer.length));
var first_buffer = eclectic_buffer.slice(0, rand_chunk);
var second_buffer = eclectic_buffer.slice(rand_chunk);
console.log('chunked after offset ' + rand_chunk);
p.write('"');
p.write(first_buffer);
p.write(second_buffer);
p.write('"');
});
+106
View File
@@ -0,0 +1,106 @@
var test = require('tape');
var Parser = require('../');
test('type number', function (t) {
t.plan(2);
var p = new Parser();
var expected = [ 1, {number: 1} ];
expected.push(expected.slice());
p.onValue = function (value) {
t.deepEqual(value, expected.shift());
};
p.write('{ "number": 1 }');
});
test('type double', function (t) {
t.plan(3);
var p = new Parser();
var expected = [ 'Edm.Double', '1.0', {doubleNumber: '1.0', 'doubleNumber@odata.type': 'Edm.Double'} ];
expected.push(expected.slice());
p.onValue = function (value) {
t.deepEqual(value, expected.shift());
};
p.write('{ "doubleNumber": 1.0 }');
});
test('type large double', function (t) {
t.plan(3);
var p = new Parser();
var expected = [ 'Edm.Double', '1234567898765432123456.0123456789876543210', {doubleNumber: '1234567898765432123456.0123456789876543210', 'doubleNumber@odata.type': 'Edm.Double'} ];
expected.push(expected.slice());
p.onValue = function (value) {
t.deepEqual(value, expected.shift());
};
p.write('{ "doubleNumber": 1234567898765432123456.0123456789876543210 }');
});
test('full odata entity', function (t) {
t.plan(17);
var p = new Parser();
var expected = [ 'http://test.table.core.windows.net/$metadata#tty/@Element',
'test.tty',
'http://test.table.core.windows.net/tty(PartitionKey=\'AAA\',RowKey=\'0001\')',
'W/\"datetime\'2016-01-07T02%3A59%3A28.6909359Z\'\"',
'tty(PartitionKey=\'AAA\',RowKey=\'0001\')',
'AAA',
'0001',
'Edm.DateTime',
'2016-01-07T02:59:28.6909359Z',
'Edm.Double',
'1.0',
'Edm.Double',
'1234567898765432123456.0123456789876543210',
2,
'Edm.Int64',
'1234567890123456789',
{ DoubleValue: '1.0',
'DoubleValue@odata.type': 'Edm.Double',
DoubleLargeValue: '1234567898765432123456.0123456789876543210',
'DoubleLargeValue@odata.type': 'Edm.Double',
Int32Value: 2,
'Int64Value@odata.type': 'Edm.Int64',
Int64Value: "1234567890123456789",
PartitionKey: 'AAA',
RowKey: '0001',
Timestamp: '2016-01-07T02:59:28.6909359Z',
'Timestamp@odata.type': 'Edm.DateTime',
'odata.editLink': 'tty(PartitionKey=\'AAA\',RowKey=\'0001\')',
'odata.etag': 'W/\"datetime\'2016-01-07T02%3A59%3A28.6909359Z\'\"',
'odata.id': 'http://test.table.core.windows.net/tty(PartitionKey=\'AAA\',RowKey=\'0001\')',
'odata.metadata': 'http://test.table.core.windows.net/$metadata#tty/@Element',
'odata.type': 'test.tty'
}
];
expected.push(expected.slice());
p.onValue = function (value) {
t.deepEqual(value, expected.shift());
};
p.write('{');
p.write('"odata.metadata":"http://test.table.core.windows.net/$metadata#tty/@Element",');
p.write('"odata.type":"test.tty",');
p.write('"odata.id":"http://test.table.core.windows.net/tty(PartitionKey=\'AAA\',RowKey=\'0001\')",');
p.write('"odata.etag":"W/\\\"datetime\'2016-01-07T02%3A59%3A28.6909359Z\'\\\"",');
p.write('"odata.editLink":"tty(PartitionKey=\'AAA\',RowKey=\'0001\')",');
p.write('"PartitionKey":"AAA",');
p.write('"RowKey":"0001",');
p.write('"Timestamp@odata.type":"Edm.DateTime",');
p.write('"Timestamp":"2016-01-07T02:59:28.6909359Z",');
p.write('"DoubleValue":1.0,');
p.write('"DoubleLargeValue":1234567898765432123456.0123456789876543210,');
p.write('"Int32Value":2,');
p.write('"Int64Value@odata.type":"Edm.Int64",');
p.write('"Int64Value":1234567890123456789');
p.write('}');
});
+15
View File
@@ -0,0 +1,15 @@
var test = require('tape');
var Parser = require('../');
test('invalid', function (t) {
var count = 0;
var p = new Parser();
p.onError = function (value) {
count++;
t.equal(1, count);
t.end();
};
p.write('{"test": eer[');
});
+67
View File
@@ -0,0 +1,67 @@
var test = require('tape');
var Parser = require('../');
var input = '{\n "string": "value",\n "number": 3,\n "object"';
var input2 = ': {\n "key": "vд"\n },\n "array": [\n -1,\n 12\n ]\n ';
var input3 = '"null": null, "true": true, "false": false, "frac": 3.14 }';
var offsets = [
[ 0, Parser.C.LEFT_BRACE ],
[ 4, Parser.C.STRING ],
[ 12, Parser.C.COLON ],
[ 14, Parser.C.STRING ],
[ 21, Parser.C.COMMA ],
[ 25, Parser.C.STRING ],
[ 33, Parser.C.COLON ],
[ 35, Parser.C.NUMBER ],
[ 36, Parser.C.COMMA ],
[ 40, Parser.C.STRING ],
[ 48, Parser.C.COLON ],
[ 50, Parser.C.LEFT_BRACE ],
[ 54, Parser.C.STRING ],
[ 59, Parser.C.COLON ],
[ 61, Parser.C.STRING ],
[ 69, Parser.C.RIGHT_BRACE ],
[ 70, Parser.C.COMMA ],
[ 74, Parser.C.STRING ],
[ 81, Parser.C.COLON ],
[ 83, Parser.C.LEFT_BRACKET ],
[ 87, Parser.C.NUMBER ],
[ 89, Parser.C.COMMA ],
[ 93, Parser.C.NUMBER ],
[ 98, Parser.C.RIGHT_BRACKET ],
[ 102, Parser.C.STRING ],
[ 108, Parser.C.COLON ],
[ 110, Parser.C.NULL ],
[ 114, Parser.C.COMMA ],
[ 116, Parser.C.STRING ],
[ 122, Parser.C.COLON ],
[ 124, Parser.C.TRUE ],
[ 128, Parser.C.COMMA ],
[ 130, Parser.C.STRING ],
[ 137, Parser.C.COLON ],
[ 139, Parser.C.FALSE ],
[ 144, Parser.C.COMMA ],
[ 146, Parser.C.STRING ],
[ 152, Parser.C.COLON ],
[ 154, Parser.C.NUMBER ],
[ 159, Parser.C.RIGHT_BRACE ]
];
test('offset', function(t) {
t.plan(offsets.length * 2 + 1);
var p = new Parser();
var i = 0;
p.onToken = function (token) {
t.equal(p.offset, offsets[i][0]);
t.equal(token, offsets[i][1]);
i++;
};
p.write(input);
p.write(input2);
p.write(input3);
t.equal(i, offsets.length);
});
+61
View File
@@ -0,0 +1,61 @@
var test = require('tape');
var Parser = require('../');
var expected = [
[ [], '' ],
[ [], 'Hello' ],
[ [], 'This"is' ],
[ [], '\r\n\f\t\\/"' ],
[ [], 'Λάμβδα' ],
[ [], '\\' ],
[ [], '/' ],
[ [], '"' ],
[ [ 0 ], 0 ],
[ [ 1 ], 1 ],
[ [ 2 ], -1 ],
[ [], [ 0, 1, -1 ] ],
[ [ 0 ], 1 ],
[ [ 1 ], 1.1 ],
[ [ 2 ], -1.1 ],
[ [ 3 ], -1 ],
[ [], [ 1, 1.1, -1.1, -1 ] ],
[ [ 0 ], -1 ],
[ [], [ -1 ] ],
[ [ 0 ], -0.1 ],
[ [], [ -0.1 ] ],
[ [ 0 ], 6.02e+23 ],
[ [], [ 6.02e+23 ] ],
[ [ 0 ], '7161093205057351174' ],
[ [], [ '7161093205057351174'] ],
[ [ 0 ], 1.0 ],
[ [ 1 ], -2.0 ],
[ [ ], [ 1, -2 ] ]
];
test('primitives', function (t) {
t.plan(28);
var p = new Parser();
p.onValue = function (value) {
var keys = this.stack
.slice(1)
.map(function (item) { return item.key })
.concat(this.key !== undefined ? this.key : [])
;
t.deepEqual(
[ keys, value ],
expected.shift()
);
};
p.write('"""Hello""This\\"is""\\r\\n\\f\\t\\\\\\/\\""');
p.write('"\\u039b\\u03ac\\u03bc\\u03b2\\u03b4\\u03b1"');
p.write('"\\\\"');
p.write('"\\/"');
p.write('"\\""');
p.write('[0,1,-1]');
p.write('[1.0,1.1,-1.1,-1.0][-1][-0.1]');
p.write('[6.02e23]');
p.write('[7161093205057351174]');
p.write('[1.0, -2.0]');
});
+38
View File
@@ -0,0 +1,38 @@
var test = require('tape');
var Parser = require('../');
test('3 bytes of utf8', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, '├──');
};
p.write('"├──"');
});
test('utf8 snowman', function (t) {
t.plan(1);
var p = new Parser();
p.onValue = function (value) {
t.equal(value, '☃');
};
p.write('"☃"');
});
test('utf8 with regular ascii', function (t) {
t.plan(4);
var p = new Parser();
var expected = [ "snow: ☃!", "xyz", "¡que!" ];
expected.push(expected.slice());
p.onValue = function (value) {
t.deepEqual(value, expected.shift());
};
p.write('["snow: ☃!","xyz","¡que!"]');
});