0.1.2 • Published 4 years ago

jsonqr v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

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: 'vegacruz@eyeris.com',
  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: 'vegacruz@eyeris.com',
  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

👤 yasintz

Show your support

Give a ⭐️ if this project helped you!


This README was generated with ❤️ by readme-md-generator