Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@36node/query-normalizr

Package Overview
Dependencies
Maintainers
4
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@36node/query-normalizr

A module boilerplate for nodejs and web.

  • 0.4.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
139
decreased by-37.1%
Maintainers
4
Weekly downloads
 
Created
Source

@36node/query-normalizr

version downloads

query-normalizr 的作用: 将 url 中的 query 规则化成方便 sdk 和 service 层调用的数据格式。

Install

yarn add @36node/query-normalizr

Usage

import { queryNormalizr } from "@36node/query-normalizr";

// koa app
app.use(normalizr(queryNormalizr));

API

middleware

normalizr(options);

// return koa middleware

normalize

import { normalize } from "@36node/query-normalizr";
import qs from "query-string";

const queryStr =
  " _expand=department&_group=type&_limit=10&_offset=0&_populate=user&_select=name&_select=age&_sort=updatedAt&_sort=-createdAt&age_gt=10&age_lt=20&level_gte=10&level_lte=20&plate_like=沪A&plate_like=沪B&tag_ne=pretty&title_like=hello&type=test1&type=test2";

normalize(qs.parse(queryStr));

/*
return {
  limit: 10,
  offset: 0,
  sort: ["updatedAt", "-createdAt"],
  populate: "user",
  select: ["name", "age"],
  group: "type",
  filter: {
    age: {
      $gt: "10",
      $lt: "20",
    },
    level: {
      $gte: "10",
      $lte: "20",
    },
    plate: {
      $regex: [/沪A/i, /沪B/i],
    },
    tag: {
      $ne: "pretty",
    },
    title: {
      $regex: /hello/i,
    },
    type: ["test1", "test2"]
  },
  _expand: "department",
};
*/

denormalize

import { denormalize } from "@36node/query-normalizr";
import qs from "query-string";

const queryObj = {
  limit: 10,
  offset: 0,
  sort: ["updatedAt", "-createdAt"],
  populate: "user",
  select: ["name", "age"],
  group: "type",
  filter: {
    age: {
      $gt: "10",
      $lt: "20",
    },
    level: {
      $gte: "10",
      $lte: "20",
    },
    plate: {
      $regex: [/沪A/i, /沪B/i],
    },
    tag: {
      $ne: "pretty",
    },
    title: {
      $regex: /hello/i,
    },
    type: ["test1", "test2"],
  },
  _expand: "department",
};

qs.stringfy(denormalize(queryObj));

// return " _expand=department&_group=type&_limit=10&_offset=0&_populate=user&_select=name&_select=age&_sort=updatedAt&_sort=-createdAt&age_gt=10&age_lt=20&assignees=%2A&followers=none&level_gte=10&level_lte=20&plate_like=%E6%B2%AAA&plate_like=%E6%B2%AAB&q=hello&tag_ne=pretty&title_like=hello&type=test1&type=test2"

What is query normalizr

image

Query in route (QIR)

reference in url.md

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

query-normalizr © 36node, Released under the MIT License.

Authored and maintained by 36node with help from contributors (list).

github.com/zzswang · GitHub @36node · Twitter @y

FAQs

Package last updated on 20 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc