import {response, IResponse} from './tools'; export interface IAddress { address1?: string; address2?: string; city?: string; state?: string; country?: string; zip?: string; } interface IValidatorItem { key: string; format: string; value: any; } export class Validator { private validator:any; constructor() { this.validator = require('validator'); } private createResponse(value: any, type: string): IResponse { if(value === true) { return response(true, null, true); } else { return response(false, `is not a valid "${type}"`, value); } } validateArray(items: Array): IResponse { try { let success = true; const answer = {}; for (let i = 0; i < items.length; i++) { const item:IValidatorItem = items[i]; // if there is "pipe |" as parameter if(item.format.indexOf('|') > 0) { const ex = item.format.split('|'); // if it's an array so 'value' has to be an array as well if(ex[0].toLowerCase() === 'array') { if (Array.isArray(item.value)) { for (let k=0; k