2.0.0 • Published 4 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-query2.0.0
4 years ago
1.1.15
4 years ago
1.1.14
4 years ago
1.1.13
4 years ago
1.1.12
4 years ago
1.1.11
4 years ago
1.1.9
4 years ago
1.1.8
4 years ago
1.1.7
4 years ago
1.1.6
4 years ago
1.1.4
4 years ago
1.1.3
4 years ago
1.1.2
4 years ago
1.1.1
4 years ago
1.1.0
4 years ago
1.0.10
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.0
4 years ago