Add jjve typings

This commit is contained in:
Wim Looman
2014-12-15 19:25:19 +13:00
parent dccd7d8691
commit d32d444932
2 changed files with 60 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
/// <reference path="../jjv/jjv.d.ts" />
/// <reference path="jjve.d.ts" />
import jjv = require('jjv');
import jjve = require('jjve');
var env: jjv.Env = jjv();
var je: jjve.Env = jjve(env);
var schema = {
type: 'object',
properties: {
ok: {
type: 'boolean',
},
},
};
var data = { ok: 1 };
var result = env.validate(schema, data);
if (result) {
var errors = je(schema, data, result);
console.log(JSON.stringify(errors, null, 4));
}
errors.forEach(error =>
console.log(
'code: %s, message: %s, data: %s, path: %s',
error.code,
error.message,
error.data,
error.path));
+26
View File
@@ -0,0 +1,26 @@
// Type definitions for JJVE v0.4.0
// Project: https://github.com/silas/jjve
// Definitions by: Wim Looman <https://github.com/Nemo157>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jjv/jjv.d.ts" />
declare module 'jjve' {
import jjv = require('jjv');
function jjve(jjv: jjv.Env): jjve.Env;
module jjve {
interface Issue {
code: string;
message: string;
data: any;
path: string;
}
interface Env {
(schema: Object, data: any, errors: jjv.Errors): Issue[];
}
}
export = jjve;
}