jameskmonger / courtroom Goto Github PK
View Code? Open in Web Editor NEWJavaScript validation engine
Home Page: http://courtroom.github.io/courtroom/
License: MIT License
JavaScript validation engine
Home Page: http://courtroom.github.io/courtroom/
License: MIT License
You should be able to pass in a function as a law for a property.
For example,
c.trial("name").laws.must(function(value) {
return (name.length >= 8);
});
Looks like the name courtroom
is not taken yet!
https://registry.npmjs.org/courtroom
Might be worth dropping the version number down to < 1.0.0 to indicate that the package is still under heavy development and has not stabilised yet.
It would be nice to be able to add laws to multiple properties at the same time.
If we wanted both name
and display_name
to both be between 4 and 24 characters long, we could be able to do a syntax like this:
c.trial(['name', 'display_name']).laws.minLength(4).maxLength(24);
Not too sure about the logistics behind how we'd do this, though.
Something like:
c.trial('email').laws.matches(/[A-Za-z_\.]+\@[A-Za-z_\.]+\.\w+/g);
It would be good to be able to trial child properties, such as to be able to say that the "length" of property "bla" must be between 5 and 10, it could be trialled like this:
c.trial("bla").trial("length").laws.between(5, 10);
Or potentially with a slightly different syntax:
c.trial(["bla", "length"]).laws.between(5, 10);
I think that the first syntax would be easier to use
Add a law to check that the property is not null, and a law to check that the property is null
It would be really good to eliminate the RequireJS dependency, so users aren't forced down the AMD route.
Could potentially use one of the UMD templates
This might sound a bit pedantic, but why are validation rules called Juries and not Laws? I'm no law student, but to me it doesn't make sense that a Lawbook contains a collection of Juries, when it seems more natural that it should have a collection of Laws. When I was first reading the code, I struggled a bit with the Jury concept, wondering where it fitted.
Also the documentation makes no mention of Jury. Is this something that you are looking to refactor anyway?
Add a law to check the minimum length of a string, and the law to check the maximum length of a string
I think that testing with Karma is unnecessary at the moment, we should instead be using a Node testing framework as we don't need to run a browser testing framework.
I think Mocha would be a good fit, but I'm not sure about its compatibility with Jasmine.
Required provides a lot more clarity and makes more sense to use than "expected".
Replace usage of "accusation" with "law", apart from in branch names
In the last publish, the Typescript has been compiled down to AMD modules. This is not great for Node, which only supports the CommonJS module strategy. I do like the change to the directory structure, though!
Can we publish CommonJS modules to NPM?
$ tsc --module commonjs
Current syntax for assigning laws is not very readable:
c.trial('name').laws.is('Simon');
c.trial('name').laws.not('Simon');
Might be nicer to have a syntax that reads like this:
c.trial('name').should.equal('Simon');
c.trial('name').should.not.equal('Alex');
Above, we've implemented the not
negation property . This could be used for negating any laws, not just equal
.
Some other laws:
c.trial('name').should.have.length.above(3);
c.trial('name').should.have.length.below(20);
c.trial('age').should.be.above(18);
c.trial('email').should.not.match(/[A-Za-z_\.]+\@[A-Za-z_\.]+\.\w+/g)
Any thoughts on this @Jameskmonger?
Set up a grunt development environment which watches for changes, builds the projects to test-build and then runs the tests. This will help reduce the reliance on Atom for our building.
npm WARN peerDependencies The peer dependency karma@>=0.9 included from karma-phantomjs-launcher will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
npm WARN peerDependencies The peer dependency phantomjs@>=1.9 included from karma-phantomjs-launcher will no
npm WARN peerDependencies longer be automatically installed to fulfill the peerDependency
npm WARN peerDependencies in npm 3+. Your application will need to depend on it explicitly.
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.