WalkRule
CORE · interface · Type contract
Synchronous traversal; local rules may omit catalog metadata.
Import
ts
import type { WalkRule } from '@jangts/agent-core/support';js
/** @typedef {import('@jangts/agent-core/support').WalkRule} WalkRule */Other public entry points:@jangts/agent-core, @jangts/agent-core/types, @jangts/agent-core/structs, @jangts/agent-core/support.
Definition
ts
interface WalkRule<Input>Extends or implements: Partial<MatchRule<Input, unknown>>.
Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Input | — | void |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
handle | (input: Input) => unknown | Required | Read-only. Runs when the rule matches; must return synchronously. |
before | ((input: Input) => void) | undefined | Optional | Read-only. Runs before matching, including when the rule does not match. |
id | string | undefined | Optional | Read-only. Unique rule id used in diagnostics. |
description | string | undefined | Optional | Read-only. See the type definition and usage context. |
pattern | ((input: Readonly<Input>) => boolean) | undefined | Optional | Read-only. Omission is an unconditional match at this position, normally the final fallback. |
Member index
| Member | Purpose |
|---|---|
handle | Runs when the rule matches; must return synchronously. |
Member details
handle
Runs when the rule matches; must return synchronously.
ts
WalkRule.handle(input: Input): unknown| Parameter | Type | Passing | Description |
|---|---|---|---|
input | Input | Required | — |
Returns: unknown.
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);