jsonqr
v0.1.2
Published
```sh yarn install ```
Downloads
3
Readme
Install
yarn install
Usage
import JsonQr from 'jsonqr';
const myParser = JsonQr(); // create a new instance
const node = {
eyeColor: 'brown',
name: 'Vega Cruz',
gender: 'male',
company: 'EYERIS',
email: '[email protected]',
phone: '+1 (811) 559-3552',
address: '942 Vanderbilt Avenue, Babb, Federated States Of Micronesia, 3522',
latitude: -7.494446,
longitude: -95.514343,
tags: ['laboris', 'ullamco', 'non', 'exercitation', 'et', 'anim', 'ex'],
schools: [
{ name: 'Karacaoglan', id: '234556' },
{ name: 'Kurtoglu', id: '9638588' },
{ name: 'Yilangolu', id: '9638583538' },
],
};
const schema = `
ShoolType{
id;
}
@{
eyeColor;
name;
phone;
shools: SchoolType;
}
`;
console.log(myParser.parse(node, schema));
result
{
"eyeColor": "brown",
"name": "Vega Cruz",
"phone": "+1 (811) 559-3552",
"schools": [{ "id": "234556" }, { "id": "9638588" }, { "id": "9638583538" }]
}
Register Helper
import JsonQr from 'jsonqr';
const myParser = JsonQr(); // create a new instance
myParser.registerHelper('slice', ({ node, args, next }) => {
try {
if (Array.isArray(node)) {
return next(node.slice(parseInt(args[0]), parseInt(args[1])));
}
} catch (error) {}
return next(node);
});
const node = {
eyeColor: 'brown',
name: 'Vega Cruz',
gender: 'male',
company: 'EYERIS',
email: '[email protected]',
phone: '+1 (811) 559-3552',
address: '942 Vanderbilt Avenue, Babb, Federated States Of Micronesia, 3522',
latitude: -7.494446,
longitude: -95.514343,
tags: ['laboris', 'ullamco', 'non', 'exercitation', 'et', 'anim', 'ex'],
schools: [
{ name: 'Karacaoglan', id: '234556' },
{ name: 'Kurtoglu', id: '9638588' },
{ name: 'Yilangolu', id: '9638583538' },
],
};
const schema = `
@{
name;
tags: @slice(2,4);
}
`;
console.log(myParser.parse(node, schema));
result
{
"name": "Vega Cruz",
"tags": ["non", "exercitation"];
}
Run tests
yarn run test
Author
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator