{"version":3,"file":"isRuleOrGroupValid-CIMZNkt4.mjs","names":[],"sources":["../src/utils/isRuleOrGroupValid.ts"],"sourcesContent":["import type { RuleGroupTypeAny, RuleType, RuleValidator, ValidationResult } from '../types';\nimport { isRuleGroup } from './isRuleGroup';\nimport { isPojo } from './misc';\n\n/**\n * Determines if an object is useful as a validation result.\n */\nexport const isValidationResult = (vr?: ValidationResult): vr is ValidationResult =>\n  isPojo(vr) && typeof vr.valid === 'boolean';\n\n/**\n * Determines if a rule or group is valid based on a validation result (if defined)\n * or a validator function. Returns `true` if neither are defined and the `muted`\n * property is not `true`.\n */\nexport const isRuleOrGroupValid = (\n  rg: RuleType | RuleGroupTypeAny,\n  validationResult?: boolean | ValidationResult,\n  validator?: RuleValidator\n): boolean => {\n  if (rg.muted) {\n    return false;\n  }\n  if (typeof validationResult === 'boolean') {\n    return validationResult;\n  }\n  if (isValidationResult(validationResult)) {\n    return validationResult.valid;\n  }\n  if (typeof validator === 'function' && !isRuleGroup(rg)) {\n    const vr = validator(rg);\n    if (typeof vr === 'boolean') {\n      return vr;\n    }\n    // v8 ignore else\n    if (isValidationResult(vr)) {\n      return vr.valid;\n    }\n  }\n  return true;\n};\n"],"mappings":";;;;;AAOA,MAAa,sBAAsB,OACjC,OAAO,EAAE,KAAK,OAAO,GAAG,UAAU;;;;;;AAOpC,MAAa,sBACX,IACA,kBACA,cACY;CACZ,IAAI,GAAG,OACL,OAAO;CAET,IAAI,OAAO,qBAAqB,WAC9B,OAAO;CAET,IAAI,mBAAmB,gBAAgB,GACrC,OAAO,iBAAiB;CAE1B,IAAI,OAAO,cAAc,cAAc,CAAC,YAAY,EAAE,GAAG;EACvD,MAAM,KAAK,UAAU,EAAE;EACvB,IAAI,OAAO,OAAO,WAChB,OAAO;;EAGT,IAAI,mBAAmB,EAAE,GACvB,OAAO,GAAG;CAEd;CACA,OAAO;AACT"}