import { IValidator , IRule } from '../validation' ; /**
 * Rule options.
 */ export interface IFuncRule extends IRule { fn : IValidator < any > ; } const DEFAULT_MESSAGE = 'This field is not valid' ; param rule returns { ( opts : any ) => boolean | string } export const func = ( rule , msg = DEFAULT_MESSAGE ) : IValidator < any > => { if ( ! rule ) { throw new TypeError ( 'Expected a function or a configuration object, got ' + rule ) ; } return opts => { if ( typeof rule === 'function' ) { return rule ( opts ) || msg ; } return rule . fn ( opts ) || rule . msg || msg ; } ; } ;