BreakCheck
CORE · interface · 类型合同
Each rule owns a semantic/readability group and its tags, independently of shared errors.
导入
ts
import type { BreakCheck } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').BreakCheck} BreakCheck */其他公开入口:@jangts/agent-core、@jangts/agent-core/types、@jangts/agent-core/structs、@jangts/agent-core/support。
定义
ts
interface BreakCheck字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
occur | unknown | 必需 | 只读。A truthy failure, lazy predicate, or ordered OR-list of lazy predicates. |
error | BreakReason | undefined | 可省略 | 只读。Rejection reason; omitted means the helper creates a default Error. |
tags | readonly string[] | undefined | 可省略 | 只读。Tags attributed to the rejection, merged with the enclosing group's tags. |
使用示例
- 拒绝检查、首个匹配与顺序处理:使用真实清单表达多项检查和枚举分发;单个普通判断仍可直接使用 if。
一个明确的拒绝
入门 · Node.js
ts
import { Support } from '@jangts/agent-core';
const input = '你好';
Support.breakWhile(!input.trim(), '问题不能为空');
console.log(input);js
import { Support } from '@jangts/agent-core';
const input = '你好';
Support.breakWhile(!input.trim(), '问题不能为空');
console.log(input);有依赖关系的检查按序求值
配置 · Node.js
ts
import { Support } from '@jangts/agent-core';
const input: unknown = { name: 'Ivan' };
Support.breakWhile([
{ occur: !input || typeof input !== 'object', error: '需要对象' },
{ occur: () => !('name' in (input as object)), error: '缺少 name' },
]);
console.log(input);js
import { Support } from '@jangts/agent-core';
const input = { name: 'Ivan' };
Support.breakWhile([
{ occur: !input || typeof input !== 'object', error: '需要对象' },
{ occur: () => !('name' in input), error: '缺少 name' },
]);
console.log(input);