Skip to content

Customizing

Beyond the builtin pipelines and config, taraskevizer exposes the building blocks so you can adapt it to your own orthography rules.

A pipeline is an ordered list of steps run against a shared context. Use lib.pipe to turn a step array into a callable pipeline, or lib.asyncPipe if your steps are asynchronous.

import { lib, steps, TaraskConfig, dicts } from "taraskevizer";
const myPipeline = lib.pipe([
steps.trim,
steps.resolveSpecialSyntax,
steps.prepare,
steps.convertAlphabet,
steps.finalize,
steps.untrim,
]);
myPipeline("планета", new TaraskConfig({ abc: dicts.alphabets.latin }));

A step is just a function (ctx) => void (or async) that mutates ctx.text. The full catalogue of steps is in the steps namespace. To base a pipeline on a builtin one while depending less on its internal order, map/flatMap over pipeline.steps and re-wrap with lib.pipe.

You can also write your own step:

const myStep = (ctx) => {
ctx.text = ctx.text.replace(/foo/g, "bar");
};

An Alphabet is { lower: CallableDict, upper?: CallableDict }. A CallableDict is a function (built from a list of [pattern, replacement] pairs via callableDict) that also exposes its source pairs on .value, so you can tweak it later.

import { lib } from "taraskevizer";
const myAbc = {
lower: lib.callableDict([
[/а/g, "a"],
[/б/g, "b"],
]),
};

Use copyDict to clone a dictionary before mutating it, so you don’t change the original.

The predefined alphabets — cyrillic, latin, latinJi, arabic — live in dicts.alphabets.

A Wrappers object has three transformers: fix (wraps changed parts), variable (a VariationWrappers keyed by no/first/all), and letterH (wraps the ґ/г letter). The predefined html and ansiColor wrappers are good starting points.

import { wrappers } from "taraskevizer";
/** @type {import("taraskevizer").wrappers.Wrappers} */
const markdown = {
fix: (c) => `**${c}**`,
variable: {
all: (c) => c,
first: (c) => /^[^|]*?\|([^|)]*)/.exec(c)[1],
no: (c) => /^\(([^|]*)/.exec(c)[1],
},
letterH: (c) => c,
};
// wrappers.html is a good starting point you can spread and override
const base = wrappers.html;

Pass your Wrappers object as the wrappers config option.

The conversion dictionaries exposed on dictswordlist, phonetic, softeners, noSoften, iaWords, iwords, gobj, and the alphabets — are plain CallableDict values you can reuse or extend in your own steps. For example lib.soften and lib.restoreCase are small reusable helpers built on top of them.