Skip to content

Latest commit

 

History

History
134 lines (111 loc) · 2.6 KB

README.md

File metadata and controls

134 lines (111 loc) · 2.6 KB

Welcome to jsonqr 👋

Version License: MIT

Install

yarn install

Usage

// const JsonQr = require('jsonqr').default;
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;
    }
`;

myParser.parse(node, schema).then(result=>{
  console.log(result);
})

result

{
  "eyeColor": "brown",
  "name": "Vega Cruz",
  "phone": "+1 (811) 559-3552",
  "schools": [{ "id": "234556" }, { "id": "9638588" }, { "id": "9638583538" }]
}

Register Helper

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);
    }
`;

myParser.parse(node, schema).then(result=>{
  console.log(result);
})

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