Comments (3)
I don't particularly see the need for the not
api.
I propose two additional functions though:
ensureFn
:: Takes a function, calls it with the value
ensureYield
:: Takes a generator, calls it with the value and yields it.
Simple example:
this.checkBody('username').trim().ensureYield(db.userExists) // yields db.userExists function with username
this.checkBody('address').trim().ensureFn(isValidBitcoinAddress) // calls sync function with the address value
from koa-validate.
I don't think ensureYield is general enough at first glance, but I like the idea of piping the value through a function. I'll play with it.
Also, ensureNot
is useful because negating a yield is annoying. You have to wrap the whole expression in parens.
this.checkBody('uname').ensure(!(yield db.findUserByUname(this.request.body.uname)))
this.checkBody('uname').ensureNot(yield db.findUserByUname(this.request.body.uname)) // nicer
Sure, not a big deal, but this library already has a precedent for not
in its API.
from koa-validate.
yeah, very powerful! happy Chinese new year!
from koa-validate.
Related Issues (20)
- feature request: validate an array of object HOT 2
- Validate sub-elements HOT 6
- Exporting validator module
- TypeError Problem: this.checkFile(...).notEmpty(...).size is not a function HOT 2
- this.checkBody('value').notEmpty('value is empty').toBoolean() HOT 1
- If using jsonpath, properties aren't properly marked as existing HOT 2
- calling toFloat with a number results in TypeError HOT 3
- Can't use optional with sanitizers. HOT 1
- Support Koa 2? HOT 5
- Check is string HOT 3
- how are you guys unit testing this?
- Is this project still actively maintained? HOT 3
- optional doesn't work
- [DEPRECATED] This project is not maintained anymore. HOT 1
- Sanitizer naming convention: .toLowercase() should be consistent with its Js version .toLowerCase()
- Body of the request has unnecessary keys
- Does this still maintains ?
- this.validateBody is not validating the keys even keys are in body of request. HOT 2
- A type confusion vulnerability can lead in json-ptr
- it would be better accept option to set error type and structure
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from koa-validate.