You've already forked setup-dotnet
mirror of
https://github.com/actions/setup-dotnet.git
synced 2025-08-23 05:54:05 +07:00
GPR authentication support
This commit is contained in:

committed by
Alex Mullans

parent
6c0e2a2a6b
commit
6bd4969ec6
16
node_modules/nimnjs/.vscode/launch.json
generated
vendored
Normal file
16
node_modules/nimnjs/.vscode/launch.json
generated
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"name": "Jasmine Tests",
|
||||
"program": "${workspaceFolder}/node_modules/jasmine/bin/jasmine.js",
|
||||
"args": [
|
||||
"${workspaceFolder}/test/encode_test.js"
|
||||
],
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
|
||||
}
|
26
node_modules/nimnjs/CONTRIBUTING.md
generated
vendored
Normal file
26
node_modules/nimnjs/CONTRIBUTING.md
generated
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
## Thanks
|
||||
I would like to thank you for your valuable time and effort and applogies if this PR is rejected due to any reason.
|
||||
|
||||
Aim: Implementing Nimn specification so that Js object can be converted to nimn format.
|
||||
|
||||
### DoD
|
||||
Here is the check list to publish any change
|
||||
|
||||
* Changes are not half implemented due to the library limitation or any other reason.
|
||||
* Changes are well discussed by raising github issue. So they are well known by other contributers and users
|
||||
* Echoing the above point. The purpose / goal for the PR should be mentioned in the description.
|
||||
* Multiple unrelated changes should not be clubbed in single PR.
|
||||
* If you are adding any dependency (specially if it is not the dev dependency) please check that
|
||||
* it is not dependent on other language packages like c/c++
|
||||
* the package is not very old or very new, discontinued, has any vulnerability etc.
|
||||
* please check the performance and size of package
|
||||
* please check alternate available options
|
||||
* Please write tests for the new changes
|
||||
* Don't forget to write tests for negative cases
|
||||
* Don't comment existing test case.
|
||||
|
||||
Note that publishing changes or accepting any PR may take time. So please keep patience.
|
||||
|
||||
### Guidelines for first time contributors
|
||||
|
||||
* https://github.com/Roshanjossey/first-contributions
|
21
node_modules/nimnjs/LICENSE
generated
vendored
Normal file
21
node_modules/nimnjs/LICENSE
generated
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2018 nimndata
|
||||
|
||||
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.
|
109
node_modules/nimnjs/README.md
generated
vendored
Normal file
109
node_modules/nimnjs/README.md
generated
vendored
Normal file
@ -0,0 +1,109 @@
|
||||
# nimnjs-node
|
||||
JS implementation of nimn specification. Highly Compressed JS object/JSON. 60% or more compressed than JSON, 40% or more compressed than msgpack
|
||||
|
||||
[](https://snyk.io/test/github/nimndata/nimnjs-node/)
|
||||
[](https://travis-ci.org/nimndata/nimnjs-node/)
|
||||
[](https://coveralls.io/github/nimndata/nimnjs-node/?branch=master)
|
||||
[<img src="https://img.shields.io/badge/Try-me-blue.svg?colorA=FFA500&colorB=0000FF" alt="Try me"/>](https://nimndata.github.io/nimnjs-node/)
|
||||
|
||||
<a href="https://www.patreon.com/bePatron?u=9531404" data-patreon-widget-type="become-patron-button"><img src="https://c5.patreon.com/external/logo/become_a_patron_button.png" alt="Become a Patron!" width="200" /></a>
|
||||
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=KQJAX48SPUKNC"> <img src="https://www.paypalobjects.com/webstatic/en_US/btn/btn_donate_92x26.png" alt="Stubmatic donate button"/></a>
|
||||
|
||||
<img align="right" src="static/img/nimnjs-logo.png" />
|
||||
|
||||
## Introduction
|
||||
NIMN JS can parse JS object to nimn data and vice versa. See Nimn [specification](https://github.com/nimndata/spec) for more detail.
|
||||
|
||||
## Usages
|
||||
First install or add to your npm package
|
||||
```
|
||||
$npm install nimnjs
|
||||
```
|
||||
|
||||
```js
|
||||
var nimn = require("nimnjs");
|
||||
|
||||
var schema = {
|
||||
"name": "string",
|
||||
"age": "number",
|
||||
"human": "boolean",
|
||||
"projects": [{
|
||||
"name": "string",
|
||||
"decription": "string"
|
||||
}]
|
||||
}
|
||||
|
||||
var nimnInstance = new nimn();
|
||||
nimnInstance.addSchema(schema);
|
||||
|
||||
var data = {
|
||||
"name" : "amit",
|
||||
"age" : 32,
|
||||
"human" : true,
|
||||
"projects" : [
|
||||
{
|
||||
"name": "some",
|
||||
"decription" : "some long description"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
var result = nimnInstance.encode(data);//Æamitº32ÙÇÆsomeºsome long description
|
||||
result = nimnInstance.decode(result);
|
||||
expect(result).toEqual(data);
|
||||
```
|
||||
|
||||
For date compression
|
||||
```js
|
||||
var nimnDateparser = require("nimn-date-parser");
|
||||
//generate schema and data
|
||||
var nimnInstance = new nimn();
|
||||
nimnInstance.addDataHandler("date",function(val){
|
||||
return nimnDateparser.parse(val,true,true,true)
|
||||
},function(val){
|
||||
return nimnDateparser.parseBack(val,true,true,true)
|
||||
});
|
||||
nimnInstance.addSchema(schema); //add after adding all data handlers
|
||||
|
||||
var nimndata = nimnInstance.encode(data);
|
||||
```
|
||||
|
||||
|
||||
Encode enum type
|
||||
```js
|
||||
var nimnInstance = new nimn();
|
||||
nimnInstance.addDataHandler("status",null,null,{
|
||||
"M" : "Married",
|
||||
"S" : "Single"
|
||||
});
|
||||
nimnInstance.addSchema(schema); //add after adding all data handlers
|
||||
```
|
||||
|
||||
Just mark a data type
|
||||
```js
|
||||
var nimnInstance = new nimn();
|
||||
nimnInstance.addDataHandler("image");
|
||||
nimnInstance.addSchema(schema); //add after adding all data handlers
|
||||
```
|
||||
|
||||
|
||||
Include [dist](dist/nimn.js) in your HTML to use it in browser.
|
||||
|
||||
|
||||
Check the [demo](https://nimndata.github.io/nimnjs-node/) for instant use. It generates schema automatically with the help of [schema builder](https://github.com/nimndata/nimnjs-schema-builder) when sample json is provided.
|
||||
|
||||
|
||||
## Support
|
||||
I need your expert advice, and contribution to grow nimn (निम्न) so that it can support all mazor languages. Please join the [official organization](https://github.com/nimndata) on github to support it. And ask your friends, and colleagues to give it a try. It can not only save bandwidth but speed up communication, search and much more.
|
||||
|
||||
|
||||
### Worth to mention
|
||||
|
||||
- **[imglab](https://github.com/NaturalIntelligence/imglab)** : Web based tool to label images for object. So that they can be used to train dlib or other object detectors. You can integrate 3rd party libraries for fast labeling.
|
||||
- **[अनुमार्गक (anumargak)](https://github.com/NaturalIntelligence/anumargak)** : The fastest router for node web servers.
|
||||
|
||||
- [Stubmatic](https://github.com/NaturalIntelligence/Stubmatic) : A stub server to mock behaviour of HTTP(s) / REST / SOAP services.
|
||||
- **[fastify-xml-body-parser](https://github.com/NaturalIntelligence/fastify-xml-body-parser/)** : Fastify plugin / module to parse XML payload / body into JS object using fast-xml-parser.
|
||||
- [fast-lorem-ipsum](https://github.com/amitguptagwl/fast-lorem-ipsum) : Generate lorem ipsum words, sentences, paragraph very quickly.
|
||||
- [Grapes](https://github.com/amitguptagwl/grapes) : Flexible Regular expression engine which can be applied on char stream. (under development)
|
||||
- [fast XML Parser](https://github.com/amitguptagwl/fast-xml-parser) : Fastest pure js XML parser for xml to js/json and vice versa. And XML validation.
|
76
node_modules/nimnjs/package.json
generated
vendored
Normal file
76
node_modules/nimnjs/package.json
generated
vendored
Normal file
@ -0,0 +1,76 @@
|
||||
{
|
||||
"_args": [
|
||||
[
|
||||
"nimnjs@1.3.2",
|
||||
"C:\\dev\\repos\\actions\\setup-dotnet"
|
||||
]
|
||||
],
|
||||
"_from": "nimnjs@1.3.2",
|
||||
"_id": "nimnjs@1.3.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha512-TIOtI4iqkQrUM1tiM76AtTQem0c7e56SkDZ7sj1d1MfUsqRcq2ZWQvej/O+HBTZV7u/VKnwlKTDugK/75IRPPw==",
|
||||
"_location": "/nimnjs",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "version",
|
||||
"registry": true,
|
||||
"raw": "nimnjs@1.3.2",
|
||||
"name": "nimnjs",
|
||||
"escapedName": "nimnjs",
|
||||
"rawSpec": "1.3.2",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "1.3.2"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/fast-xml-parser"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/nimnjs/-/nimnjs-1.3.2.tgz",
|
||||
"_spec": "1.3.2",
|
||||
"_where": "C:\\dev\\repos\\actions\\setup-dotnet",
|
||||
"author": {
|
||||
"name": "Amit Gupta",
|
||||
"url": "https://github.com/amitguptagwl"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/nimndata/nimnjs-node/issues"
|
||||
},
|
||||
"dependencies": {
|
||||
"nimn-date-parser": "^1.0.0",
|
||||
"nimn_schema_builder": "^1.0.0"
|
||||
},
|
||||
"description": "Schema aware compression of JS object/JSON data. 60% more compressed than json",
|
||||
"devDependencies": {
|
||||
"benchmark": "^2.1.4",
|
||||
"browserify": "^15.1.0",
|
||||
"cbor": "^4.0.0",
|
||||
"istanbul": "^0.4.5",
|
||||
"jasmine": "^3.0.0",
|
||||
"jasmine-core": "^2.99.1",
|
||||
"msgpack": "^1.0.2",
|
||||
"notepack.io": "^2.1.2"
|
||||
},
|
||||
"homepage": "https://github.com/nimndata/nimnjs-node",
|
||||
"keywords": [
|
||||
"nimn",
|
||||
"nimnjs",
|
||||
"json",
|
||||
"compress",
|
||||
"parse",
|
||||
"format",
|
||||
"msgpack"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "src/nimn.js",
|
||||
"name": "nimnjs",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/nimndata/nimnjs-node.git"
|
||||
},
|
||||
"scripts": {
|
||||
"bundle": "browserify src/nimn.js -s nimn -o dist/nimn.js",
|
||||
"coverage": "istanbul cover -x \"tests/*test.js\" jasmine tests/*test.js;",
|
||||
"coverage:check": "istanbul check-coverage --branch 90 --statement 90",
|
||||
"test": "jasmine tests/*test.js"
|
||||
},
|
||||
"version": "1.3.2"
|
||||
}
|
63
node_modules/nimnjs/src/DataHandler.js
generated
vendored
Normal file
63
node_modules/nimnjs/src/DataHandler.js
generated
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/**
|
||||
*
|
||||
* @param {string} dataType
|
||||
* @param {function} parse
|
||||
* @param {function} parseBack
|
||||
* @param {object} charset
|
||||
* @param {boolean} treatAsUnique
|
||||
*/
|
||||
function DataHandler(dataType, /* parse, parseBack, */ charset,treatAsUnique){
|
||||
this.dataType = dataType;
|
||||
//parse || (this.parse = parse);
|
||||
//parseBack || (this.parseBack = parseBack);
|
||||
if(charset){
|
||||
//this.hasFixedInstances = true;
|
||||
this.char2val = charset;
|
||||
this.val2char = {};
|
||||
var keys = Object.keys(charset);
|
||||
for(var i in keys){
|
||||
var val = charset[keys[i]];
|
||||
this.val2char[val] = keys[i];
|
||||
}
|
||||
|
||||
this.charcodes = Object.keys(charset);
|
||||
}
|
||||
if(treatAsUnique){
|
||||
this.hasFixedInstances = true;
|
||||
}
|
||||
|
||||
//this.treatAsUnique = treatAsUnique;
|
||||
}
|
||||
|
||||
DataHandler.prototype.parse = function(a){
|
||||
if(this.char2val){
|
||||
return this.getCharCodeFor(a);
|
||||
}else{
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
DataHandler.prototype.parseBack = function(a){
|
||||
if(this.char2val){
|
||||
return this.getValueOf(a);
|
||||
}else{
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns an array of supported characters or empty array when it supportes dynamic data
|
||||
*/
|
||||
DataHandler.prototype.getCharCodes =function(){
|
||||
return this.charcodes;
|
||||
}
|
||||
|
||||
DataHandler.prototype.getValueOf =function(chCode){
|
||||
return this.char2val[chCode];
|
||||
}
|
||||
|
||||
DataHandler.prototype.getCharCodeFor =function(value){
|
||||
return this.val2char[value];
|
||||
}
|
||||
|
||||
module.exports = DataHandler;
|
40
node_modules/nimnjs/src/chars.js
generated
vendored
Normal file
40
node_modules/nimnjs/src/chars.js
generated
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
var char = require("./util").char;
|
||||
|
||||
|
||||
/* 176-178
|
||||
180-190
|
||||
198-208
|
||||
219-223
|
||||
*/
|
||||
|
||||
const chars= {
|
||||
nilChar : char(176),
|
||||
missingChar : char(201),
|
||||
nilPremitive : char(175),
|
||||
missingPremitive : char(200),
|
||||
|
||||
emptyChar : char(178),
|
||||
emptyValue: char(177),//empty Premitive
|
||||
|
||||
boundryChar : char(179),
|
||||
|
||||
objStart: char(198),
|
||||
arrStart: char(204),
|
||||
arrayEnd: char(185),
|
||||
}
|
||||
|
||||
const charsArr = [
|
||||
chars.nilChar ,
|
||||
chars.nilPremitive,
|
||||
chars.missingChar,
|
||||
chars.missingPremitive,
|
||||
chars.boundryChar ,
|
||||
chars.emptyChar,
|
||||
chars.emptyValue,
|
||||
chars.arrayEnd,
|
||||
chars.objStart,
|
||||
chars.arrStart
|
||||
]
|
||||
|
||||
exports.chars = chars;
|
||||
exports.charsArr = charsArr;
|
108
node_modules/nimnjs/src/decoder.js
generated
vendored
Normal file
108
node_modules/nimnjs/src/decoder.js
generated
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
var chars = require("./chars").chars;
|
||||
|
||||
decoder.prototype._d = function(schema){
|
||||
if(ifNil(this.currentChar())){
|
||||
this.index++;
|
||||
return null;
|
||||
}else if(ifMissing(this.currentChar())){
|
||||
this.index++;
|
||||
return undefined;
|
||||
}else if(typeof schema.type === "string"){//premitive
|
||||
return this.readPremitiveValue(schema);
|
||||
}else if(Array.isArray(schema)){
|
||||
if(this.currentChar() === chars.emptyChar){
|
||||
this.index++;
|
||||
return [];
|
||||
}else if(this.currentChar() !== chars.arrStart){
|
||||
throw Error("Parsing error: Array start char was expected");
|
||||
}else{
|
||||
this.index++;//skip array start char
|
||||
var item = schema[0];
|
||||
var obj = []
|
||||
do{
|
||||
var r = this._d(item) ;
|
||||
if(r !== undefined){
|
||||
obj.push(r);
|
||||
}
|
||||
}while(this.dataToDecode[this.index] !== chars.arrayEnd);
|
||||
++this.index;
|
||||
return obj;
|
||||
}
|
||||
}else{//object
|
||||
if(this.currentChar() === chars.emptyChar){
|
||||
this.index++;
|
||||
return {};
|
||||
}else if(this.currentChar() !== chars.objStart){
|
||||
throw Error("Parsing error: Object start char was expected : " + this.currentChar());
|
||||
}else{
|
||||
this.index++;//skip object start char
|
||||
var keys = Object.keys(schema);
|
||||
var len = keys.length;
|
||||
var obj = {};
|
||||
for(var i=0; i< len; i++){
|
||||
|
||||
var r = this._d(schema[keys[i]]) ;
|
||||
if(r !== undefined){
|
||||
obj[keys[i]] = r;
|
||||
}
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ifNil(ch){
|
||||
return ch === chars.nilChar || ch === chars.nilPremitive;
|
||||
}
|
||||
|
||||
function ifMissing(ch){
|
||||
return ch === chars.missingChar || ch === chars.missingPremitive;
|
||||
}
|
||||
/**
|
||||
* returns character index pointing to
|
||||
*/
|
||||
decoder.prototype.currentChar = function(){
|
||||
return this.dataToDecode[this.index];
|
||||
}
|
||||
|
||||
decoder.prototype.readPremitiveValue = function(schemaOfCurrentKey){
|
||||
var val = this.readFieldValue(schemaOfCurrentKey);
|
||||
if(this.currentChar() === chars.boundryChar) this.index++;
|
||||
var dh = this.dataHandlers[schemaOfCurrentKey.type];
|
||||
return dh.parseBack(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read characters until app supported char is found
|
||||
*/
|
||||
decoder.prototype.readFieldValue = function(schemaOfCurrentKey){
|
||||
if(schemaOfCurrentKey.readUntil){
|
||||
if(this.currentChar() === chars.emptyValue){
|
||||
this.index++;
|
||||
return "";
|
||||
}else{
|
||||
var until = schemaOfCurrentKey.readUntil;
|
||||
var len = this.dataToDecode.length;
|
||||
var start = this.index;
|
||||
|
||||
for(;this.index < len && until.indexOf(this.currentChar()) === -1;this.index++);
|
||||
return this.dataToDecode.substr(start, this.index-start);
|
||||
}
|
||||
}else{
|
||||
return this.dataToDecode[this.index++];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
decoder.prototype.decode = function(objStr){
|
||||
this.index= 0;
|
||||
if(!objStr || typeof objStr !== "string" || objStr.length === 0) throw Error("input should be a valid string");
|
||||
this.dataToDecode = objStr;
|
||||
return this._d(this.schema);
|
||||
}
|
||||
|
||||
function decoder(schema,dataHandlers){
|
||||
this.schema = schema;
|
||||
this.dataHandlers = dataHandlers;
|
||||
}
|
||||
module.exports = decoder;
|
89
node_modules/nimnjs/src/encoder.js
generated
vendored
Normal file
89
node_modules/nimnjs/src/encoder.js
generated
vendored
Normal file
@ -0,0 +1,89 @@
|
||||
var chars = require("./chars").chars;
|
||||
var appCharsArr = require("./chars").charsArr;
|
||||
|
||||
Encoder.prototype._e = function(jObj,e_schema){
|
||||
if(typeof e_schema.type === "string"){//premitive
|
||||
return this.getValue(jObj,e_schema.type);
|
||||
}else{
|
||||
var hasValidData = hasData(jObj);
|
||||
if(hasValidData === true){
|
||||
var str = "";
|
||||
if(Array.isArray(e_schema)){
|
||||
str += chars.arrStart;
|
||||
var itemSchema = e_schema[0];
|
||||
//var itemSchemaType = itemSchema;
|
||||
var arr_len = jObj.length;
|
||||
for(var arr_i=0;arr_i < arr_len;arr_i++){
|
||||
var r = this._e(jObj[arr_i],itemSchema) ;
|
||||
str = this.processValue(str,r);
|
||||
}
|
||||
str += chars.arrayEnd;//indicates that next item is not array item
|
||||
}else{//object
|
||||
str += chars.objStart;
|
||||
var keys = Object.keys(e_schema);
|
||||
for(var i in keys){
|
||||
var key = keys[i];
|
||||
var r = this._e(jObj[key],e_schema[key]) ;
|
||||
str = this.processValue(str,r);
|
||||
}
|
||||
}
|
||||
return str;
|
||||
}else{
|
||||
return hasValidData;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Encoder.prototype.processValue= function(str,r){
|
||||
if(!this.isAppChar(r[0]) && !this.isAppChar(str[str.length -1])){
|
||||
str += chars.boundryChar;
|
||||
}
|
||||
return str + r;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {*} a
|
||||
* @param {*} type
|
||||
* @return {string} return either the parsed value or a special char representing the value
|
||||
*/
|
||||
Encoder.prototype.getValue= function(a,type){
|
||||
switch(a){
|
||||
case undefined: return chars.missingPremitive;
|
||||
case null: return chars.nilPremitive;
|
||||
case "": return chars.emptyValue;
|
||||
default: return this.dataHandlers[type].parse(a);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given object is empty, null, or undefined. Returns true otherwise.
|
||||
* @param {*} jObj
|
||||
*/
|
||||
function hasData(jObj){
|
||||
if(jObj === undefined) return chars.missingChar;
|
||||
else if(jObj === null) return chars.nilChar;
|
||||
else if( jObj.length === 0 || Object.keys(jObj).length === 0){
|
||||
return chars.emptyChar;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Encoder.prototype.isAppChar = function(ch){
|
||||
return this.handledChars.indexOf(ch) !== -1;
|
||||
}
|
||||
|
||||
Encoder.prototype.encode = function(jObj){
|
||||
return this._e(jObj,this.schema);
|
||||
}
|
||||
|
||||
function Encoder(schema,dHandlers, charArr){
|
||||
this.dataHandlers = dHandlers;
|
||||
this.handledChars = appCharsArr.slice();
|
||||
this.handledChars = this.handledChars.concat(charArr);
|
||||
|
||||
this.schema = schema;
|
||||
}
|
||||
|
||||
module.exports = Encoder;
|
27
node_modules/nimnjs/src/helper.js
generated
vendored
Normal file
27
node_modules/nimnjs/src/helper.js
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
/**
|
||||
* Verify if all the datahandlers are added given in schema.
|
||||
* @param {*} schema
|
||||
* @param {*} datahandlers
|
||||
*/
|
||||
var validateSchema = function(schema,datahandlers){
|
||||
if(Array.isArray(schema)){
|
||||
validateSchema(schema[0],datahandlers);
|
||||
}else if(typeof schema === "object"){
|
||||
var keys = Object.keys(schema);
|
||||
var len = keys.length;
|
||||
|
||||
for(var i=0; i< len; i++){
|
||||
var key = keys[i];
|
||||
var nextKey = keys[i+1];
|
||||
|
||||
validateSchema(schema[key],datahandlers);
|
||||
}
|
||||
}else{
|
||||
if(!datahandlers[schema]){
|
||||
throw Error("You've forgot to add data handler for " + schema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.validateSchema = validateSchema;
|
95
node_modules/nimnjs/src/nimn.js
generated
vendored
Normal file
95
node_modules/nimnjs/src/nimn.js
generated
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
var boolean = require("./parsers/boolean");
|
||||
var numParser = require("./parsers/number");
|
||||
var chars = require("./chars").chars;
|
||||
var appCharsArr = require("./chars").charsArr;
|
||||
var helper = require("./helper");
|
||||
var schemaMarker = require("./schemaMarker");
|
||||
var Decoder = require("./decoder");
|
||||
var Encoder = require("./encoder");
|
||||
var DataHandler = require("./DataHandler");
|
||||
|
||||
function nimn() {
|
||||
this.handledChars = [];//appCharsArr.slice();
|
||||
this.dataHandlers = {};
|
||||
this.addDataHandler("boolean",null,null,boolean.charset,true);
|
||||
//this.addDataHandler("boolean",boolean.parse,boolean.parseBack,boolean.charset,true);
|
||||
this.addDataHandler("string");
|
||||
this.addDataHandler("number",numParser.parse, numParser.parseBack);
|
||||
this.addDataHandler("date");
|
||||
}
|
||||
|
||||
/**
|
||||
* This method should be called once all the data handlers are registered.
|
||||
* It updates internal schema based on given schema.
|
||||
*
|
||||
* @example
|
||||
* {
|
||||
* "field1" : "string",
|
||||
* "field2" : "date",
|
||||
* "field3" : {
|
||||
* "field4" : "number"
|
||||
* },
|
||||
* "field5" : [ "image"],
|
||||
* "field6" : [{ "field7" : "boolean"}]
|
||||
* }
|
||||
* @param {*} schema
|
||||
* @returns {void}
|
||||
*/
|
||||
nimn.prototype.addSchema= function(schema){
|
||||
this.schema = JSON.parse(JSON.stringify(schema));
|
||||
new schemaMarker(this.dataHandlers).markNextPossibleChars(this.schema);
|
||||
//helper.validateSchema(schema,this.dataHandlers);
|
||||
this.encoder = new Encoder(this.schema,this.dataHandlers,this.handledChars);
|
||||
}
|
||||
|
||||
/**
|
||||
* You can update existnig handler od add new using this method.
|
||||
* "string", "number", "boolean", and "date" are handled by default.
|
||||
*
|
||||
* charset should be set when given type should be treated as enum or fixed set of values
|
||||
* @example
|
||||
* //to map
|
||||
* nimnInstance.addDataHandler("status",null,null,{ "R": "running", "S" : "stop", "I", "ready to run"},false)
|
||||
* @example
|
||||
* //just for identification
|
||||
* nimnInstance.addDataHandler("image");
|
||||
* @example
|
||||
* //to compress more
|
||||
* nimnInstance.addDataHandler("date", datecompressor.parse, datecompressor.parseBack);
|
||||
* @param {string} type
|
||||
* @param {function} parseWith - will be used by encoder to encode given type's value
|
||||
* @param {function} parseBackWith - will be used by decoder to decode given type's value
|
||||
* @param {Object} charset - map of charset and fixed values
|
||||
* @param {boolean} [noBoundaryChar=false] - if true encoder will not separate given type's value with boundary char
|
||||
*/
|
||||
nimn.prototype.addDataHandler = function(type,parseWith,parseBackWith,charset,noBoundaryChar){
|
||||
var dataHandler = new DataHandler(type,/* parseWith,parseBackWith, */charset,noBoundaryChar);
|
||||
if(parseWith) dataHandler.parse = parseWith;
|
||||
if(parseBackWith) dataHandler.parseBack = parseBackWith;
|
||||
|
||||
//unque charset don't require boundary char. Hence check them is they are already added
|
||||
if(noBoundaryChar && charset){
|
||||
var keys = Object.keys(charset);
|
||||
|
||||
for(var k in keys){
|
||||
var ch = keys[k];
|
||||
if(this.handledChars.indexOf(ch) !== -1 || appCharsArr.indexOf(ch) !== -1){
|
||||
throw Error("DataHandler Error: "+ ch +" is not allowed. Either it is reserved or being used by another data handler");
|
||||
}else{
|
||||
this.handledChars.push(ch);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.dataHandlers[type] = dataHandler;
|
||||
}
|
||||
|
||||
nimn.prototype.encode = function(jObj){
|
||||
return this.encoder.encode(jObj);
|
||||
}
|
||||
|
||||
nimn.prototype.decode= function(encodedVal){
|
||||
var decoder = new Decoder(this.schema,this.dataHandlers);
|
||||
return decoder.decode(encodedVal);
|
||||
}
|
||||
module.exports = nimn;
|
11
node_modules/nimnjs/src/parsers/boolean.js
generated
vendored
Normal file
11
node_modules/nimnjs/src/parsers/boolean.js
generated
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
var chars = require("../chars").chars;
|
||||
var char = require("../util").char;
|
||||
|
||||
var yes = char(181);
|
||||
var no = char(183);
|
||||
|
||||
booleanCharset = {};
|
||||
booleanCharset[yes] = true;
|
||||
booleanCharset[no] = false;
|
||||
|
||||
exports.charset = booleanCharset;
|
18
node_modules/nimnjs/src/parsers/number.js
generated
vendored
Normal file
18
node_modules/nimnjs/src/parsers/number.js
generated
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
var chars = require("../chars").chars;
|
||||
|
||||
function parse(val){
|
||||
return val;
|
||||
}
|
||||
|
||||
function parseBack(val){
|
||||
if(val.indexOf(".") !== -1){
|
||||
val = Number.parseFloat(val);
|
||||
}else{
|
||||
val = Number.parseInt(val,10);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
|
||||
exports.parse = parse;
|
||||
exports.parseBack = parseBack;
|
125
node_modules/nimnjs/src/schemaMarker.js
generated
vendored
Normal file
125
node_modules/nimnjs/src/schemaMarker.js
generated
vendored
Normal file
@ -0,0 +1,125 @@
|
||||
var chars = require("./chars").chars;
|
||||
var appCharsArr = require("./chars").charsArr;
|
||||
|
||||
schemaMarker.prototype._m = function(schema){
|
||||
if(Array.isArray(schema)){
|
||||
if(typeof schema[0] === "string"){
|
||||
var itemSchema = {
|
||||
type : schema[0]
|
||||
}
|
||||
this.setReadUntil(itemSchema, schema[0]);
|
||||
schema[0] = itemSchema;//make it object so a function cant set it's value
|
||||
if(schema[0].readUntil)
|
||||
schema[0].readUntil.push(chars.arrayEnd);
|
||||
}else{
|
||||
this._m(schema[0]);//let's object portion handle it
|
||||
var lastMostKey = getLastMostKey(schema[0]);
|
||||
if(lastMostKey){
|
||||
this.setReadUntil(lastMostKey, schema[0]);
|
||||
if(lastMostKey.readUntil)
|
||||
lastMostKey.readUntil.push(chars.arrayEnd);
|
||||
}else{
|
||||
//lastmostkey was set as it was under an array
|
||||
}
|
||||
}
|
||||
}else if(typeof schema === "object"){
|
||||
var keys = Object.keys(schema);
|
||||
var len = keys.length;
|
||||
|
||||
for(var i=0; i< len; i++){
|
||||
var key = keys[i];
|
||||
var nextKey = keys[i+1];
|
||||
|
||||
this._m(schema[key]);
|
||||
if(Array.isArray(schema[key])) continue;
|
||||
else if(nextKey){
|
||||
if(typeof schema[key] !== "string"){//not an object
|
||||
var lastMostKey = getLastMostKey(schema[key]);
|
||||
if(lastMostKey){
|
||||
this.setReadUntil(lastMostKey,schema[nextKey]);
|
||||
}else{
|
||||
//lastmostkey was set as it was under an array
|
||||
}
|
||||
}else{
|
||||
var itemSchema = {
|
||||
type : schema[key]
|
||||
}
|
||||
this.setReadUntil(itemSchema,schema[nextKey]);
|
||||
schema[key] = itemSchema ;
|
||||
}
|
||||
}else{
|
||||
if(typeof schema[key] === "object") continue;
|
||||
schema[key] = {
|
||||
type : schema[key]
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(!this.dataHandlers[schema]){//handled
|
||||
throw Error("You've forgot to add data handler for " + schema)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
schemaMarker.prototype.setReadUntil = function(current,next){
|
||||
//status: R,S
|
||||
if(this.dataHandlers[current.type].hasFixedInstances){
|
||||
//if current char is set by user and need to be separated by boundary char
|
||||
//then don't set readUntil, read current char
|
||||
return ;
|
||||
}else{
|
||||
|
||||
//return [chars.boundryChar, chars.missingPremitive, chars.nilPremitive];
|
||||
if(Array.isArray(next)){
|
||||
current.readUntil = [ chars.arrStart, chars.missingChar, chars.emptyChar, chars.nilChar];
|
||||
}else if(typeof next === "object"){
|
||||
current.readUntil = [ chars.objStart, chars.missingChar, chars.emptyChar, chars.nilChar];
|
||||
}else{
|
||||
if(this.dataHandlers[next] && this.dataHandlers[next].hasFixedInstances){//but need to be separated by boundary char
|
||||
//status,boolean
|
||||
current.readUntil = [chars.missingPremitive, chars.nilPremitive];
|
||||
current.readUntil = current.readUntil.concat(this.dataHandlers[next].getCharCodes());
|
||||
}else{
|
||||
///status,age
|
||||
current.readUntil = [chars.boundryChar, chars.emptyValue, chars.missingPremitive, chars.nilPremitive];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* obj can't be an array
|
||||
* @param {*} obj
|
||||
*/
|
||||
function getLastMostKey(obj){
|
||||
var lastProperty;
|
||||
if(Array.isArray(obj)){
|
||||
return;
|
||||
}else{
|
||||
var keys = Object.keys(obj);
|
||||
lastProperty = obj[keys[keys.length-1]];
|
||||
}
|
||||
|
||||
if(typeof lastProperty === "object" && !(lastProperty.type && typeof lastProperty.type === "string")){
|
||||
return getLastMostKey(lastProperty);
|
||||
}else{
|
||||
return lastProperty;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
schemaMarker.prototype.markNextPossibleChars = function(schema){
|
||||
this._m(schema);
|
||||
if(!Array.isArray(schema)){
|
||||
var lastMostKey = getLastMostKey(schema);
|
||||
if(lastMostKey){
|
||||
lastMostKey.readUntil = [chars.nilChar]
|
||||
}
|
||||
}
|
||||
}
|
||||
function schemaMarker(dataHandlers){
|
||||
this.dataHandlers = dataHandlers;
|
||||
}
|
||||
|
||||
module.exports = schemaMarker;
|
30
node_modules/nimnjs/src/util.js
generated
vendored
Normal file
30
node_modules/nimnjs/src/util.js
generated
vendored
Normal file
@ -0,0 +1,30 @@
|
||||
/**
|
||||
* converts a ASCII number into equivalant ASCII char
|
||||
* @param {number} a
|
||||
* @returns ASCII char
|
||||
*/
|
||||
var char = function (a){
|
||||
return String.fromCharCode(a);
|
||||
}
|
||||
|
||||
/**
|
||||
* return key of an object
|
||||
* @param {*} obj
|
||||
* @param {number} i
|
||||
*/
|
||||
/* function getKey(obj,i){
|
||||
return obj[Object.keys(obj)[i]];
|
||||
}
|
||||
*/
|
||||
|
||||
/* function indexOf(arr,searchedID) {
|
||||
var arrayLen = arr.length;
|
||||
var c = 0;
|
||||
while (c < arrayLen) {
|
||||
if (arr[c] === searchedID) return c;
|
||||
c++;
|
||||
}
|
||||
return -1;
|
||||
} */
|
||||
exports.char = char;
|
||||
//exports.indexOf = indexOf;
|
Reference in New Issue
Block a user