NormalizationOptions
KIT · interface · 类型合同
Pipeline options.
导入
ts
import type { NormalizationOptions } from '@jangts/agent-core/kits/normalization';1
js
/** @typedef {import('@jangts/agent-core/kits/normalization').NormalizationOptions} NormalizationOptions */1
其他公开入口:@jangts/agent-core/types、@jangts/agent-core/kits/normalization、@jangts/agent-core/kits。
定义
ts
interface NormalizationOptions<Value, Context>1
泛型参数
| 类型参数 | 约束 | 默认类型 |
|---|---|---|
Value | — | — |
Context | — | — |
字段结构
| 字段 | 类型 | 必需 | 说明 |
|---|---|---|---|
isComplete | ((value: Value, context: Context) => boolean) | undefined | 可省略 | 只读。Stops the walk after the step that first returns true; later steps then do not run. |
使用示例
- Normalization:有顺序的值转换:把清理、替换和停止条件集中为一份实际参与执行的转换清单。
先只清理同一段查询
入门 · Node.js
ts
import { Normalization } from '@jangts/agent-core/kits/normalization';
const query = Normalization.defineNormalization<string>([
{ id: 'trim', normalize: value => value.trim() },
]);
console.log(query.normalize(' Agent Core ', undefined));1
2
3
4
5
2
3
4
5
js
import { Normalization } from '@jangts/agent-core/kits/normalization';
const query = Normalization.defineNormalization([
{ id: 'trim', normalize: value => value.trim() },
]);
console.log(query.normalize(' Agent Core ', undefined));1
2
3
4
5
2
3
4
5
继续增加步骤和停止条件
配置 · Node.js
ts
import { Normalization } from '@jangts/agent-core/kits/normalization';
const query = Normalization.defineNormalization<string>([
{ id: 'trim', normalize: value => value.trim() },
{ id: 'collapse-space', normalize: value => value.replace(/\s+/g, ' ') },
{ id: 'lowercase', when: value => value !== '*', normalize: value => value.toLowerCase() },
], { isComplete: value => value === '*' });
const values = [' Agent Core ', 'agent core', '*'].map(value => query.normalize(value, undefined));
console.log(Normalization.uniqueBy(values, value => value));1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
js
import { Normalization } from '@jangts/agent-core/kits/normalization';
const query = Normalization.defineNormalization([
{ id: 'trim', normalize: value => value.trim() },
{ id: 'collapse-space', normalize: value => value.replace(/\s+/g, ' ') },
{ id: 'lowercase', when: value => value !== '*', normalize: value => value.toLowerCase() },
], { isComplete: value => value === '*' });
const values = [' Agent Core ', 'agent core', '*'].map(value => query.normalize(value, undefined));
console.log(Normalization.uniqueBy(values, value => value));1
2
3
4
5
6
7
8
2
3
4
5
6
7
8