snparse
v1.0.22
Published
Permite filtrar objetos de la misma forma que se hace en las plantillas de Mongoose.
Downloads
7
Readme
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