2.0.1 • Published 3 years ago

girgir v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 years ago

GIRGIR Express Plugin

girgir is a express.js middleware that checks input types.

Installation

Install it using npm

npm install --save girgir

Install it using yarn

yarn add girgir

Guide

girgir will uses rest api backend systems

Using

const express = require("express");
const app = express();

app.use(express.json());
app.use(girgir({}));

Espacing

Input

const nickName = {
  type: "string",
  maxLen: 14,
  minLen: 2,
},

Route

const routes = {
  get: {
    ":user": {
      isPoint: true,
      user: INPUT,
      id: INPUT,
    },
  },
};

Deep Checking

If isObject is used, girgir will check deep params.

const routes = {
  adres: {
    isObject: true,
    il: {
      isObject: true,
      slug: { type: "string" },
    },
    ilce: {
      isObject: true,
      slug: { type: "string" },
    },
    mahalle: {
      isObject: true,
      slug: { type: "string" },
    },
  },
};

Collection Checking

If isCollection is used, girgir will check object list (a.k.a collection).

const routes = {
  adres: {
    isObject: true,
     names:{
      isCollection:true,
      slug:{
        type:'string'
      }
    },
  },
};

Array Checking

If isArray is used, girgir will check array.

const routes = {
  adres: {
    isObject: true,
    arr:{
      isArray:true,
      type:"string"
    },
  },
};

Disable Deep Check Or Route

If isDisabled is used, girgir will ignore results for these section.

const routes = {
  adres: {
    isObject: true,
    il: {
      isObject: true,
      slug: { type: "string" },
    },
    ilce: {
      isObject: true,
      slug: { type: "string" },
    },
    mahalle: {
      isDisabled: true,
      slug: { type: "string" },
    },
  },
};

Config

Girgir using .girgirrc.js from project root path

├── /
├── post
└─┬ user
  └── login
module.exports = {
  users: {
    public: {
      get: {
        ":user": {
          isPoint: true,
          user: {
            type: "string",
            maxLen: 14,
            minLen: 2,
          },
        },
        id: {
          isPoint: true,
          id: {
            type: "number",
            min: 0,
            max: 99,
          },
        },
      },
    },
    del: {
      ":id": {
        isPoint: true,
        id: {
          type: "number",
          min: 0,
          max: 99,
        },
      },
    },
  },
  posts: {
    get: {
      ":id": {
        isPoint: true,
        id: {
          type: "string",
        },
      },
    },
  },
};
2.0.1

3 years ago

2.0.0

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago