BreakCheck
CORE · interface · Type contract
Each rule owns a semantic/readability group and its tags, independently of shared errors.
Import
ts
import type { BreakCheck } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').BreakCheck} BreakCheck */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support.
Definition
ts
interface BreakCheckField structure
| Field | Type | Required | Description |
|---|---|---|---|
occur | unknown | Required | Read-only. A truthy failure, lazy predicate, or ordered OR-list of lazy predicates. |
error | BreakReason | undefined | Optional | Read-only. Rejection reason; omitted means the helper creates a default Error. |
tags | readonly string[] | undefined | Optional | Read-only. Tags attributed to the rejection, merged with the enclosing group's tags. |
Examples
- Rejection checks, first match, and sequential processing: Use real lists to express multiple checks and enumerated dispatch; a single ordinary condition can still use if.
One explicit rejection
Beginner · 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);Checks with dependencies evaluated in order
Configuration · 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);