Giter VIP home page Giter VIP logo

aduana.js's Introduction

Aduana

It allows generating sanitation or filtering structures in a simple way, being able to scale from a synchronous to asynchronous process without the need to modify its behavior.

Api

the customs api is simple, you can build functions to clean or filter objects simply with 2 functions:

  • filter : allows to create functions of sanitation or filtering, this returns a new function.

  • schema : it allows to iterate on an object, returning a new function, it is in turn builds a process that waits for each element of the tree to be completed, in this way you can generate synchronous and asynchronous waits.

Input

When executing the function filter as schema, you must deliver an object with the following properties.

  • value: is the value to be filtered by the function generated by filter or schema.

  • valid : function to execute by filter or schema at the end without rejecting any value.

  • invalid : function to execute by filter or schema at the end rejecting some value.

Create filter

filter allows to generate a sequence of middleware that can validate or alter the initial value

import {filter} from 'aduana';

let isPepe = filter(
   (next,{valid,invalid,value})=>{
       if( value === 'Pepe' ){
           next({valid,invalid,value})
       }else{
           invalid({value:"It's not Pepe!"})
       }
   }
)

isPepe({
   value : 'Pepe',
   valid(value){
       console.log(value)
   },
   invalid(value){
       console.log(value)
   }
})

Create Schema

schema allows to create an iteration structure of functions, we will return to the pepe filter example.

import {schema} from 'aduana';
import isPepe from './isPepe';

let user = schema({
   name : isPepe
})

user({
   value : {
       name : 'Pepe'
   },
   valid(){
       console.log('user is valid')
   },
   invalid(){
       console.log('user is invalid')
   }
})

aduana.js's People

Contributors

uppercod avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.