2.0.0 • Published 3 years ago
json-light-query v2.0.0
json-light-query
Get the total/average value from json array(object/string).
Usage
1 - How to get total by id
const { VernQueryFactory } = require("json-light-query");
const reqAttrId = "nameOfUniqueId";
const reqAttrVal = "nameOfAttributeToGetTotal";
const reqAttrIdVal = "111111113";
const jsonArraySample = [{
"nameOfUniqueId": "111111113",
"anyAdditonalAttributeIsFine": "1001",
"nameOfAttributeToGetTotal": 10.98
},
{
"nameOfUniqueId": "111111113",
"anyAdditonalAttributeIsFine": "1002",
"nameOfAttributeToGetTotal": 7.21
}];
const resp = VernQueryFactory.getTotalById({jsonObjArray:jsonArraySample, idAttrNm: reqAttrId, numericAttrNm: reqAttrVal}, reqAttrIdVal);
The above resp will be:
{
id: '111111113',
total: 18.19
}
2 - How to get total by group
const { VernQueryFactory } = require("json-light-query");
const reqAttrId = "uniqueId";
const reqAttrVal = "price";
const reqAttrGrpNm = "attrSeq";
const jsonArraySample ='[{"uniqueId":"111111113","attrSeq":"1001","price":10},{"uniqueId":"111111114","attrSeq":"1001","price":10},{"uniqueId":"111111113","attrSeq":"1002","price":10}]';
const resp = VernQueryFactory.getTotalByGroup({jsonObjArray:jsonArraySample, idAttrNm: reqAttrId, numericAttrNm: reqAttrVal}, reqAttrGrpNm);
The above resp will be:
[{
uniqueId: '111111113',
attrSeq: '1001'
price: 20
},
{
uniqueId: '111111113',
attrSeq: '1002'
price: 10
}]
3 - How to get total for all
const { VernQueryFactory } = require("json-light-query");
const reqAttrId = "uniqueId";
const reqAttrVal = "price";
const reqAttrGrpNm = "attrSeq";
const jsonArraySample ='[{"uniqueId":"111111113","attrSeq":"1001","price":10},{"uniqueId":"111111114","attrSeq":"1001","price":10},{"uniqueId":"111111113","attrSeq":"1002","price":10}]';
const resp = VernQueryFactory.getTotal({jsonObjArray:jsonArraySample, idAttrNm: reqAttrId, numericAttrNm: reqAttrVal});
The above resp will be:
{
id: 'all',
total: 30
}
Installation
$ npm i json-light-query
2.0.0
3 years ago
1.1.15
3 years ago
1.1.14
3 years ago
1.1.13
3 years ago
1.1.12
3 years ago
1.1.11
3 years ago
1.1.9
3 years ago
1.1.8
3 years ago
1.1.7
3 years ago
1.1.6
3 years ago
1.1.4
3 years ago
1.1.3
3 years ago
1.1.2
3 years ago
1.1.1
3 years ago
1.1.0
3 years ago
1.0.10
3 years ago
1.0.9
3 years ago
1.0.8
3 years ago
1.0.7
3 years ago
1.0.6
3 years ago
1.0.5
3 years ago
1.0.4
3 years ago
1.0.3
3 years ago
1.0.0
3 years ago