snresteasy
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

SNParse

Permite filtrar objetos de la misma forma que se hace en las plantillas de Mongoose.

example

import {Parse, VType, PModelAttributes} from "snparse";

const getActivos = async (activoName: string, args:{
    page?: number,
    size?: number,
    q?: string,
    test1?: string,
    test2?: string,
    test3?: string,
  } = {})=>{
    activoName = Parse.Alone(activoName, { type: VType.String });
    const { 
        page, size, q, test1, test2, test3 
    } = Parse.Validate(args, {
      page: {type: VType.Number, default: 0, min: 0},
      size: {type: VType.Number, default: 25, min: 5, max: 9999 },
      q: {type: VType.Number, min: 0},
      test1: {type: VType.String, required: true, regex: /abc/},
      test2: {type: VType.Boolean, default: true, one: "required_one"},
      test3: {type: VType.String, enum: ["m","f"], one: "required_one"},
    } as PModelAttributes<typeof args>)
    console.log("Variables OK", activoName, page, size, q, test1, test2, test3);
}

install

With npm do:

npm install snparse

license

MIT

Package Sidebar

Install

npm i snresteasy

Weekly Downloads

1

Version

2.0.0

License

ISC

Unpacked Size

47.9 kB

Total Files

18

Last publish

Collaborators

  • jan997