json-source-map icon indicating copy to clipboard operation
json-source-map copied to clipboard

support arbitrary keys

Open milahu opened this issue 4 years ago • 1 comments

now users must append jsonMap.leaf_node to their keyList like

const jsonMap = require('json-source-map');
const result = jsonMap.parse('{"z":1,"a":{"z":1,"a":1}}');
const keyList = ['z', 'a']; // before this was ptr = '/z/a'
let pointer = result.pointers;
for (let key of keyList.concat([jsonMap.leaf_key])) {
  pointer = pointer[key];
}
const [a, b] = [pointer.value.pos, pointer.valueEnd.pos];

edit: forgot keyList = .... in commit message

edit: the constant should not be called leaf_key, rather loc_key

todo: tests ....

milahu avatar Aug 24 '20 12:08 milahu

Coverage Status

Coverage decreased (-18.5%) to 81.495% when pulling 37dd775462a34046a9f3437665973b96f5b48c6c on milahu:patch-1 into 3e5886187624d662370a52a7e5e5e0d8d4aa4c05 on epoberezkin:master.

coveralls avatar Aug 24 '20 12:08 coveralls