START | USAGE | API | EXAMPLES | AUTHOR | CONTRIBUTE | LICENSE | SUPPORT
Declarative JavaScript and TypeScript js object schema validation tool.
try {
new Rules({
name : [String, min(4)]
, password : [String, min(6)]
, email : [String, (string) => /@/g.test(string) || '@ is missing!']
, biography: ['optional', String, min(32), max(512)]
, birthDate: ['optional', Date]
, code : ['optional', Number]
}).validate({
name : 'Ragnarok'
, password: '12345qwerty'
, email : 'what?'
}, true);
} catch (e) {
// throws Rule.INVALID_VALUE error with '@ is missing!' message
}
Q: Why don't to use joi or any other schema-validation library instead?
A: Well the reason of this is that some of these libraries
are too complicated and time-expensive to learn for me.
The Stigma was created as ad-hoc solution and isn't intended
to be replacement for any of these useful librariess.
You are free to choose any.
Before you start make sure you have NodeJS installed and available in your global PATH
variable.
$ cd your/project/path
$ npm i -S hinell/stigma
import {Rules} from 'stigma';
let schema = {description: String }
let dataStructure = {description: 'Description of most powerful library ever....'};
try { new Rules(schema).validate(dataStructure,true); }
catch (){/* do something with error */}
or
new Rules(...).validate(dataStructure)
.then(dataStructure => ...)
.catch(error => /* do something with error * )
Full API description can be found here.
You can follow me on twitter or just email me.
Check out (if any) contribution guide or license for more details.
You should be aware that the library is not supported by anyone except me.
None gurantees bugless behaviour (though currenlty it is fully covered by tests).
If you want to become a patron of this project or offer me a support please follow here.
Go back to the project description