@zilliqa-js/util
Advanced tools
Comparing version 0.2.1-next.20181109 to 0.2.1-next.20181112
@@ -18,3 +18,3 @@ import BN from 'bn.js'; | ||
export declare const required: <T extends Function>(fn: T) => Validator; | ||
export declare const matchesObject: <T extends Object>(x: unknown, test: { | ||
export declare const matchesObject: <T extends object>(x: unknown, test: { | ||
[key: string]: Validator[]; | ||
@@ -21,0 +21,0 @@ }) => x is T; |
@@ -46,16 +46,31 @@ "use strict"; | ||
exports.matchesObject = function (x, test) { | ||
var e_1, _a; | ||
if (exports.isPlainObject(x)) { | ||
for (var key in test) { | ||
for (var i = 0; i < test[key].length; i++) { | ||
var value = x[key]; | ||
if (typeof value === 'undefined') { | ||
if (test[key][i].required) { | ||
throw new Error('Key not found: ' + key); | ||
if (test.hasOwnProperty(key)) { | ||
try { | ||
for (var _b = tslib_1.__values(test[key]), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var tester = _c.value; | ||
var value = x[key]; | ||
if (typeof value === 'undefined' && tester.required) { | ||
throw new Error('Key not found: ' + key); | ||
} | ||
else { | ||
continue; | ||
} | ||
if (typeof tester !== 'function') { | ||
throw new Error('Validator is not a function'); | ||
} | ||
if (!tester(value)) { | ||
throw new Error('Validation failed for ' + key); | ||
} | ||
} | ||
continue; | ||
} | ||
if (typeof test[key][i] !== 'function') | ||
throw new Error('Validator is not a function'); | ||
if (!test[key][i](x[key])) | ||
throw new Error('Validation failed for ' + key); | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b.return)) _a.call(_b); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
@@ -62,0 +77,0 @@ } |
{ | ||
"name": "@zilliqa-js/util", | ||
"version": "0.2.1-next.20181109", | ||
"version": "0.2.1-next.20181112", | ||
"description": "Utilities for working with Zillia.", | ||
@@ -23,3 +23,3 @@ "main": "dist/index.umd.js", | ||
}, | ||
"gitHead": "f2d8ea7d5bc9fccde5975defd69a230eeadf092d" | ||
"gitHead": "51b5325fbe7a8a986931ce089058fb4619cf85d1" | ||
} |
@@ -60,3 +60,3 @@ import BN from 'bn.js'; | ||
export const matchesObject = <T extends Object>( | ||
export const matchesObject = <T extends object>( | ||
x: unknown, | ||
@@ -66,19 +66,21 @@ test: { [key: string]: Validator[] }, | ||
if (isPlainObject(x)) { | ||
for (var key in test) { | ||
for (var i = 0; i < test[key].length; i++) { | ||
const value = x[key]; | ||
for (const key in test) { | ||
if (test.hasOwnProperty(key)) { | ||
for (const tester of test[key]) { | ||
const value = x[key]; | ||
if (typeof value === 'undefined') { | ||
if (test[key][i].required) { | ||
if (typeof value === 'undefined' && tester.required) { | ||
throw new Error('Key not found: ' + key); | ||
} else { | ||
continue; | ||
} | ||
continue; | ||
if (typeof tester !== 'function') { | ||
throw new Error('Validator is not a function'); | ||
} | ||
if (!tester(value)) { | ||
throw new Error('Validation failed for ' + key); | ||
} | ||
} | ||
if (typeof test[key][i] !== 'function') | ||
throw new Error('Validator is not a function'); | ||
if (!test[key][i](x[key])) | ||
throw new Error('Validation failed for ' + key); | ||
} | ||
@@ -85,0 +87,0 @@ } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
708093
6871