Skip to content
greek conversion

prepareOptions

prepareOptions(options?): PreparedOptions

Defined in: src/prepare_options.ts:64 (opens in a new tab)

Checks and resolves conversion options once, for any number of conversions: the functions of the main entry point take prepared options in place of options, and those of the ./core entry point take no other.

The options are those that the functions of the main entry point take: a preset by name, custom options that override it, and a source profile for reading the input. They are validated as strictly, with the same errors. Prepare options once, outside a loop: the result can be used for any number of conversions, and cannot be changed. The main entry point resolves the defaults and each preset once anyway; other options, it checks and resolves at each call, which a short text, such as a word, takes about twice as long to convert. Options that are prepared already are returned as they are.

A preset with no custom option is also exported as prepared options, by the ./presets entry point, which brings neither the validation nor the table of the presets into a bundle.

ConversionOptions | PreparedOptions = {}

PreparedOptions

import { convert, prepareOptions } from "@humanities/greek-conversion";
const options = prepareOptions({ transliteration: { chi: "kh" } });
const words = ["χάος", "ψυχή"];
words.map((word) => convert(word, "greek", "transliteration", options));
// → ["kháos","psykhḗ"]
import { convert, prepareOptions } from "@humanities/greek-conversion/core";
import { greekReader } from "@humanities/greek-conversion/greek";
import { transliterationWriter } from "@humanities/greek-conversion/transliteration";
const options = prepareOptions({
preset: "sbl-general",
transliteration: { chi: "kh" },
});
convert("χάος", greekReader, transliterationWriter, options); // → khaos

If a preset, an option key, or an option value is unknown, or two values are incompatible. An OptionError is a RangeError.

If options, source, or an option group has the wrong type.