dsheiko / bycontract Goto Github PK
View Code? Open in Web Editor NEWArgument validation library based on JSDOC syntax
Home Page: https://dsheiko.gitbook.io/bycontract/
Argument validation library based on JSDOC syntax
Home Page: https://dsheiko.gitbook.io/bycontract/
Testing from DevTools.
byContract.validate('foo', `('foo'|'bar')`)
Expected : 'foo'
Actual : ByContractError: expected ('foo'|'bar') but got string
byContract.validate({ 'foo': true, 'bar': 1 }, `Object.<string, boolean|number>`)
Expected : {foo: true, bar: 1}
Actual : ByContractError: expected Object.<string, boolean|number> but failed on each: invalid contract string, invalid contract "number>"
byContract.validate([true, 1], `Array.<boolean|number>`)
Expected : (2) [true, 1]
Actual : ByContractError: expected Array.<boolean|number> but failed on each: invalid contract string, invalid contract "number>"
byContract.validate({ 'foo': { 'bar': true }}, `Object.<string, Object.<string, boolean>>`)
Expected : {foo: {…}}
Actual : ByContractError: object property foo: invalid contract "boolean>"
byContract.validate([{ 'foo': true, 'bar': 1 }], `Array.<Object.<string, boolean|number>>`)
Expected : [{…}]
Actual : ByContractError: expected Array.<Object.<string, boolean|number>> but failed on each: invalid contract string, invalid contract "number>>"
byContract.validate({ foo: [true, 1] }, `Object.<string, Array.<boolean|number>>`)
Expected : {foo: Array(2)}
Actual : ByContractError: expected Object.<string, Array.<boolean|number>> but failed on each: invalid contract string, invalid contract "number>>"
Thanks
I am sorry, but documentation is super confusing.
I just want to implement simple validation for object passed.
export const requestCreateService = async (payload) => {
console.log(payload,arguments)
const payloadType = {
title: 'string',
body: 'string',
createdBy: 'string',
categoryID: 'number',
priority: 'string=',
files: 'array=',
}
validate(arguments, [payloadType])
}
that does not work, because essentially, arguments
has loads of other objects not just payload.
How can I point so it does check only payload object ? also ideally how can I check if payload was passed at all ?
"bycontract" looks really great and is a real gapfiller! Under which licence do you distribute your library? Thank you for sharing!
When importing this in typescript I get a TS2306
error. Any ideas how to fix this?
/node_modules/bycontract/index.d.ts' is not a module.
Hello,
I am receiving the following errors when running tsc
.
node_modules/bycontract/index.d.ts(1,1): error TS1046: Top-level declarations in .d.ts files must start with either a 'declare' or 'export' modifier.
node_modules/bycontract/index.d.ts(1,10): error TS7010: 'validate', which lacks return-type annotation, implicitly has an 'any' return type.
node_modules/bycontract/index.d.ts(7,10): error TS7010: 'typedef', which lacks return-type annotation, implicitly has an 'any' return type.
node_modules/bycontract/index.d.ts(9,17): error TS7010: 'validateJsdoc', which lacks return-type annotation, implicitly has an 'any' return type.
I am running typescript version 3.6.3.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.