Skip to content

Btime/query-string-adapter

Repository files navigation

query-string-adapter

Format schema object to a string in JSON format and viceversa

Setup

Installing

npm i

Build

npm run build

Usage

Installing

npm i @btime/query-string-adapter -S

Examples

Parsing Object into String

  • Input:
const QueryStringAdapter = require('@btime/query-string-adapter')

const data = {
  filters:
  {
    active: true,
    deleted: false,
    service_status_id: [1, 2]
  },
  fields:
  {
    service: ['name'],
    service_type_id: 'bank'
  },
  paginate:
  {
    page: 2,
    limit: 25
  },
  ordination:
  {
    field: 'name',
    type: 'DESC'
  }
}

const parsed = QueryStringAdapter.parse(data)
  • Output:
{
    "filters":
    {
        "active": true,
        "deleted": false,
        "service_status_id": [1, 2]
    },
    "fields":
    {
        "service": ["name"],
        "service_type_id": "bank"
    },
    "paginate":
    {
        "page": 2,
        "limit": 25
    },
    "ordination":
    {
        "field": "name",
        "type": "DESC"
    }
}

Parsing String into Object

  • Input:
const QueryStringAdapter = require('@btime/query-string-adapter')

const data = '{"filters":{"active":true,"deleted":false,"service_status_id":[1,2]},"fields":{"service":["name"],"service_type_id":"bank"},"paginate":{"page":2,"limit":25},"ordination":{"field":"name","type":"DESC"}}'

const parsed = QueryStringAdapter.parse(data)
  • Output:
{
  filters:
  {
    active: true,
    deleted: false,
    service_status_id: [1, 2]
  },
  fields:
  {
    service: ['name'],
    service_type_id: 'bank'
  },
  paginate:
  {
    page: 2,
    limit: 25
  },
  ordination:
  {
    field: 'name',
    type: 'DESC'
  }
}