Skip to content
中文

NormalizationOptions ​

KIT · interface · Type contract

Pipeline options.

Import ​

ts
import type { NormalizationOptions } from '@jangts/agent-core/kits/normalization';
js
/** @typedef {import('@jangts/agent-core/kits/normalization').NormalizationOptions} NormalizationOptions */

Other public entry points:@jangts/agent-core/types, @jangts/agent-core/kits/normalization, @jangts/agent-core/kits.

Definition ​

ts
interface NormalizationOptions<Value, Context>

Type parameters ​

Type parameterConstraintDefault type
Value——
Context——

Field structure ​

FieldTypeRequiredDescription
isComplete((value: Value, context: Context) => boolean) | undefinedOptionalRead-only. Stops the walk after the step that first returns true; later steps then do not run.

Examples ​

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));

API reference, usage examples and developer guides.