initial commit.

This commit is contained in:
2022-06-06 02:04:50 -04:00
commit 62de970149
1557 changed files with 256441 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
module.exports = [
require('./parser_array.js'),
require('./parser_json.js'),
require('./parser_omit.js'),
require('./parser_jsonarray.js'),
require("./parser_flat.js")
];

View File

@@ -0,0 +1,12 @@
module.exports = {
"name": "array",
"processSafe":true,
"regExp": /^\*array\*/,
"parserFunc": function parser_array(params) {
var fieldName = params.head.replace(this.regExp, '');
if (params.resultRow[fieldName] === undefined) {
params.resultRow[fieldName] = [];
}
params.resultRow[fieldName].push(params.item);
}
};

View File

@@ -0,0 +1,10 @@
module.exports = {
"name": "flat",
"processSafe": true,
"regExp": /^\*flat\*/,
"parserFunc": function parser_flat (params) {
var key = this.getHeadStr();
var val = params.item;
params.resultRow[key] = val;
}
};

View File

@@ -0,0 +1,70 @@
var arrReg = /\[([0-9]*)\]/;
function processHead(pointer, headArr, arrReg, flatKeys) {
var headStr, match, index;
while (headArr.length > 1) {
headStr = headArr.shift();
// match = headStr.match(arrReg);
match = flatKeys ? false : headStr.match(arrReg);
if (match) { //if its array, we need add an empty json object into specified index.
if (pointer[headStr.replace(match[0], '')] === undefined) {
pointer[headStr.replace(match[0], '')] = [];
}
index = match[1]; //get index where json object should stay
pointer = pointer[headStr.replace(match[0], '')];
if (index === '') { //if its dynamic array index, push to the end
index = pointer.length;
}
if (!pointer[index]) { //current index in the array is empty. we need create a new json object.
pointer[index] = {};
}
pointer = pointer[index];
} else { //not array, just normal JSON object. we get the reference of it
if (pointer[headStr] === undefined) {
pointer[headStr] = {};
}
pointer = pointer[headStr];
}
}
return pointer;
}
module.exports = {
"name": "json",
"processSafe": true,
"regExp": /^\*json\*/,
"parserFunc": function parser_json(params) {
var fieldStr = this.getHeadStr();
var headArr = (params.config && params.config.flatKeys) ? [fieldStr] : fieldStr.split('.');
var match, index, key;
//now the pointer is pointing the position to add a key/value pair.
var pointer = processHead(params.resultRow, headArr, arrReg, params.config && params.config.flatKeys);
key = headArr.shift();
match = (params.config && params.config.flatKeys) ? false : key.match(arrReg);
if (match) { // the last element is an array, we need check and treat it as an array.
try {
key = key.replace(match[0], '');
if (!pointer[key] || !(pointer[key] instanceof Array)) {
pointer[key] = [];
}
if (pointer[key]) {
index = match[1];
if (index === '') {
index = pointer[key].length;
}
pointer[key][index] = params.item;
} else {
params.resultRow[fieldStr] = params.item;
}
} catch (e) {
params.resultRow[fieldStr] = params.item;
}
} else {
if (typeof pointer === "string"){
params.resultRow[fieldStr] = params.item;
}else{
pointer[key] = params.item;
}
}
}
};

View File

@@ -0,0 +1,22 @@
module.exports = {
"name": "jsonarray",
"processSafe":true,
"regExp": /^\*jsonarray\*/,
"parserFunc": function parser_jsonarray (params) {
var fieldStr = params.head.replace(this.regExp, "");
var headArr = fieldStr.split('.');
var pointer = params.resultRow;
while (headArr.length > 1) {
var headStr = headArr.shift();
if (pointer[headStr] === undefined) {
pointer[headStr] = {};
}
pointer = pointer[headStr];
}
var arrFieldName = headArr.shift();
if (pointer[arrFieldName] === undefined) {
pointer[arrFieldName] = [];
}
pointer[arrFieldName].push(params.item);
}
};

View File

@@ -0,0 +1,6 @@
module.exports = {
"name": "omit",
"regExp": /^\*omit\*/,
"processSafe":true,
"parserFunc": function parser_omit() {}
};