Converter
Defined in: src/converter.ts:333 (opens in a new tab)
An immutable conversion engine with isolated character extensions. Create
one with createConverter(): the class is exported as a type only.
Aliases resolve to built-in letters and therefore receive the complete contextual behavior of those letters. New characters are deliberately opaque: only direct format mapping and semantic case are guaranteed.
Methods
Section titled “Methods”convert()
Section titled “convert()”convert(
input,from,to,options?):string
Defined in: src/converter.ts:436 (opens in a new tab)
Converts text using this converter’s immutable character registry. The options add to the converter’s preset. Prepared options are taken when they were prepared with that preset, or with any when the converter binds none: they are then checked and resolved once.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”ConversionOptions | PreparedOptions = {}
Returns
Section titled “Returns”string
Throws
Section titled “Throws”For another preset named in the options, or for options prepared with another preset, or without one when the converter binds one.
Throws
Section titled “Throws”When the converter rejects characters outside its scope.
convertDetailed()
Section titled “convertDetailed()”convertDetailed(
input,from,to,options?):ConverterConversionResult
Defined in: src/converter.ts:490 (opens in a new tab)
Converts text and reports both information loss and repertoire scope. It takes options as Converter.convert does.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”ConversionOptions | PreparedOptions = {}
Returns
Section titled “Returns”Throws
Section titled “Throws”For another preset named in the options, or for options prepared with another preset, or without one when the converter binds one.
Throws
Section titled “Throws”When the converter rejects characters outside its scope.
convertGreekPassages()
Section titled “convertGreekPassages()”convertGreekPassages(
input,to,options?):string
Defined in: src/converter.ts:631 (opens in a new tab)
Converts the Greek passages of a text, and copies the rest as it is: convertGreekPassages with this converter’s characters and scope. The converter’s own Greek spellings, those of its aliases and the Greek forms of its characters, belong to the passages, whatever characters they are made of. It takes options as Converter.convert does.
Parameters
Section titled “Parameters”string
The format of the passages in the output.
options?
Section titled “options?”ConversionOptions | PreparedOptions = {}
Returns
Section titled “Returns”string
Example
Section titled “Example”import { createConverter } from "@humanities/greek-conversion";
const converter = createConverter({ characters: [{ id: "san", forms: { greek: { lowercase: "ϻ", uppercase: "Ϻ" }, "beta-code": { lowercase: "#9", uppercase: "*#9" }, transliteration: { lowercase: "š", uppercase: "Š" }, }, override: true, }],});
converter.convertGreekPassages("the letter ϻ;", "transliteration");// → the letter š;Throws
Section titled “Throws”For options, or prepared options, of another preset; a CharacterScopeError when the converter rejects a character.
convertGreekPassagesDetailed()
Section titled “convertGreekPassagesDetailed()”convertGreekPassagesDetailed(
input,to,options?):ConverterConversionResult
Defined in: src/converter.ts:670 (opens in a new tab)
Converter.convertGreekPassages, with the losses, the spans, and the diagnostics of Converter.convertDetailed: the text copied keeps what it has, and its spans in the output are those in the input, moved.
Parameters
Section titled “Parameters”string
The format of the passages in the output.
options?
Section titled “options?”ConversionOptions | PreparedOptions = {}
Returns
Section titled “Returns”Throws
Section titled “Throws”For options, or prepared options, of another preset; a CharacterScopeError when the converter rejects a character.
reencode()
Section titled “reencode()”reencode(
input,format,options?):string
Defined in: src/converter.ts:472 (opens in a new tab)
Parses and writes text again in the same format, with this converter’s
characters and scope: reencode for a converter. It is
convert(input, format, format, options).
Parameters
Section titled “Parameters”string
format
Section titled “format”options?
Section titled “options?”ConversionOptions | PreparedOptions = {}
Returns
Section titled “Returns”string
Example
Section titled “Example”import { createConverter } from "@humanities/greek-conversion";
const converter = createConverter({ aliases: [{ letter: "theta", format: "transliteration", spellings: ["þ"], }],});
converter.reencode("þeós", "transliteration");// → theósThrows
Section titled “Throws”For another preset named in the options, or for options prepared with another preset, or without one when the converter binds one.
Throws
Section titled “Throws”When the converter rejects characters outside its scope.