NormalizationStep
KIT · interface · Type contract
One ordered transformation.
Import
ts
import type { NormalizationStep } from '@jangts/agent-core/kits/normalization';js
/** @typedef {import('@jangts/agent-core/kits/normalization').NormalizationStep} NormalizationStep */Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/normalization, @jangts/agent-core/kits.
Definition
ts
interface NormalizationStep<Value, Context>Type parameters
| Type parameter | Constraint | Default type |
|---|---|---|
Value | — | — |
Context | — | — |
Field structure
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Required | Read-only. Unique, non-blank step id used in errors. |
when | ((value: Value, context: Context) => boolean) | undefined | Optional | Read-only. Skips the step when it returns false; must be synchronous boolean. |
normalize | (value: Value, context: Context) => Value | Required | Read-only. Returns the next value; receives the output of the previous step. Must be synchronous. |
Member index
| Member | Purpose |
|---|---|
normalize | Returns the next value; receives the output of the previous step. Must be synchronous. |
Member details
normalize
Returns the next value; receives the output of the previous step. Must be synchronous.
ts
NormalizationStep.normalize(value: Value, context: Context): Value| Parameter | Type | Passing | Description |
|---|---|---|---|
value | Value | Required | — |
context | Context | Required | — |
Returns: Value.
Awaited value: Awaited<Value>.
Examples
- Normalization: ordered value transformation: Collect cleaning, replacement, and stop conditions into one transformation list that actually drives execution.
Start by cleaning one query
Beginner · 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));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));Continue by adding steps and a stop condition
Configuration · 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));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));