runtime-type-checks
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -12,1 +12,3 @@ export interface CheckConfig { | ||
export declare function CustomCheck(fn: Function): (type: any) => void; | ||
export declare function objectWith(...props: any[]): (obj: any) => string; | ||
export declare function arrayOf(check: Function): (array: any[]) => string; |
23
index.js
@@ -50,2 +50,25 @@ var rm = require('reflect-metadata'); | ||
exports.CustomCheck = CustomCheck; | ||
function objectWith() { | ||
var props = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
props[_i - 0] = arguments[_i]; | ||
} | ||
return function (obj) { | ||
var missing = props.filter(function (prop) { return !obj[prop]; }); | ||
return missing.length > 0 ? "Required properties are missing: " + missing.join(", ") : null; | ||
}; | ||
} | ||
exports.objectWith = objectWith; | ||
function arrayOf(check) { | ||
return function (array) { | ||
for (var i = 0; i < array.length; ++i) { | ||
var error = check(array[i]); | ||
if (error) { | ||
return "Error at index " + i + ". " + error; | ||
} | ||
} | ||
return null; | ||
}; | ||
} | ||
exports.arrayOf = arrayOf; | ||
function wrapMethod(descriptor, checks) { | ||
@@ -52,0 +75,0 @@ return wrapValue(descriptor, function () { |
{ | ||
"name": "runtime-type-checks", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Runtime type checks for JavaScript and TypeScript", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
25745
248