Guarantees and limits
This document states what every conversion guarantees, what the library deliberately leaves to the caller, and where each behavior is specified in detail. The stability policy states how the version number protects these behaviors.
What every conversion guarantees
Section titled “What every conversion guarantees”- Every format pair converts in both directions. Greek (
"greek"), Beta Code ("beta-code"), and transliteration ("transliteration") are read into the same canonical document, letters, case, and diacritics independent of any spelling, and written from it. The same rules therefore apply to every pair, in either direction. - Output is canonical and idempotent. For fixed formats and options,
converting the output again with the same options, without
source, changes nothing, but in these cases:- the text of another format that a source may hold (below);
- a letter written as a TLG code before a digit in Beta Code (see Information loss);
- the case of a capital spelled with several Latin letters, which follows
the letters and words around it, when one of them reads back otherwise
after a loss (under
bnf-ancient, an acute on a consonant reads back as a keraia:Λ́ΘgivesĹTH, thenĹTh); - letters that a converter keeps out of its scope, in the cases that Character extensions lists, frequent between Beta Code and transliteration;
- a vowel with both a coronis and a breathing or an upsilon with an iota
subscript, which
validateDocument()rejects (underiso-843-type-2,KA᾽̔togivesKHa’to, thenKHA’to); - monotonic accentuation with a transliteration that writes eta and omega
without a length mark (
longVowels: "omit", asiso-843-type-2does), where a word read back with an iota or an omicron may be a monosyllable, whose accent goes (ήgivesí, theni); - the BnF keraia after a word with an accent, under monotonic
accentuation: its acute reads back as a second accent, which monotonic
accentuation removes (under
bnf-ancientwithaccentuation: "monotonic",λόγοιʹgiveslógoí, thenlógoi); - a coronis written as an apostrophe in a numeral, under decimal
numerals: it reads back as punctuation, after which the letters before
it are a number (under
iso-843-type-2withnumerals: "decimal",͵αἀʹgives͵aa’ʹ, then1001’ʹ); - a combining mark that no reader knows, on a vowel whose coronis
transliteration writes as an apostrophe: the mark follows the
apostrophe, and an elision after it then reads back as the start of a
word, which title case capitalizes (under
iso-843-type-1withletterCase: "title",κἀ̇’ψgivesKa’̇’ps, thenKa’̇’Ps).
- A lossless conversion is reversible. When
convertDetailed()reportslossy: false, converting the output back with the same options gives the same canonical text, a letter that a converter keeps out of its scope included (see Character extensions). After a restyle, swapsourceand the other options. The information-loss contract lists what each format pair and option loses, and the conversion-analysis contract describes the report. - Unknown characters are preserved. A character the library does not recognize, an unrecognized combining mark included, is copied through as a literal, never dropped.
- The default transliteration is the library’s own. It uses the letters
of the SBL Handbook of Style (§5.3), which the
sbl-generalpreset writes, and keeps the accents, iota subscript, diaeresis, and quantity marks that the Handbook leaves out. No preset names it, since no published convention defines it. - Options are checked. A misspelled option never falls back to a default.
An unknown option key, value, or preset, or two values that cannot be
combined, throws an
OptionError. It is aRangeErrorthat names the option (path), what it received (received), what it accepts (accepted), and, for a key or value that a release candidate knew, its current spelling (replacement), an aid that a minor release after1.0.0may stop giving (see the stability policy). An unknown format throws a plainRangeError, an option group of the wrong type or an input that is not a string aTypeError. The functions of thecoreentry point take readers, writers, and prepared options, which the presets entry point exports andprepareOptions()returns: given anything else, the name of a format or an object of options included, they throw aTypeError. The functions of the main and document entry points take prepared options in place of options. A copy made by spreading them, or prepared options given assource, as a group, or as the configuration of a converter, throw aTypeError, which names the preset to write instead. A converter’s methods take options prepared with its preset, or any when it binds none, and throw aRangeErrorfor others.FORMATSandCONVERSION_OPTION_VALUESlist everything that is accepted. Every option value is plain ASCII. The configuration ofcreateConverter()is checked the same way: an unknown key, of the configuration, of an alias, or of a custom character, throws anOptionError, as does a value outside a known set (an out-of-scope behavior, the letter of an alias, a character identifier).
The first three properties are checked for every preset and every format pair
on each change, over a corpus of difficult forms
(tests/invariants_corpus_test.ts).
Text that mixes Greek with another language
Section titled “Text that mixes Greek with another language”By default, the library converts the whole string it is given. In a text
that mixes Greek with another language, the punctuation shared by both is
converted as Greek (; becomes ? in transliteration). The letters of the
other language are kept as they are, but reported as unrepresented-literal
losses when the target format would read them as Greek, and Beta Code, whose
letters are Latin, writes them in the case of its own letters, as they read
back. A letter with marks that compose with it is written in Beta Code as
the character they make, which reads back as itself (Valéry gives valéry,
whose é stays a letter of French, where e and an acute would read back as
an epsilon and a mark):
import { convertDetailed } from "@humanities/greek-conversion";
const mixed = convertDetailed( "Voir λόγος ; cf. ψυχή.", "greek", "transliteration",);
mixed.output; // → Voir lógos ? cf. psychḗ.mixed.lossy; // → true[...new Set(mixed.losses.map((loss) => loss.code))];// → ["unrepresented-literal"]Filter the losses by code to keep those about the Greek, or convert the
Greek passages only (below). The same code reports the few literals of the Greek
itself that a target cannot keep, such as a parenthesis before a digit in
Beta Code (see
Information loss).
A letter that a reader keeps as text next to Greek letters is a letter of
their word, as is a letter that the transliteration reader does not read: a
digitized text that writes a Latin K for a Greek one keeps its word whole.
A sigma before such a letter is medial, and title case capitalizes the
first letter of the word only (Kαζάρμα): an apostrophe after such a letter
starts no word (l’ἀνήρ). Monotonic accentuation keeps the accent of a word
whose syllables it cannot count, a monosyllable included (Kαί), and a
breathing on a vowel after such a letter is a coronis (Oἰκία, with a Latin
O). A letter of another script, such as a Chinese character, is
no letter of the Greek word that it touches.
The Greek passages of a text
Section titled “The Greek passages of a text”convertGreekPassages() converts the Greek passages of a text, and copies
the rest as it is, code unit by code unit. The source is Greek: in Beta Code
and transliteration, Latin letters are the Greek text. The rules of the
conversion see the whole text, as they would in a conversion of the whole
text: before the period of Θ., the capital is an initial.
convertGreekPassagesDetailed() adds the losses and the spans of
convertDetailed().
import { convertGreekPassagesDetailed } from "@humanities/greek-conversion";
const passages = convertGreekPassagesDetailed( "Voir ϐίϐλος ; cf. ψυχή.", "transliteration",);
passages.output; // → Voir bíblos ; cf. psychḗ.passages.losses.map((loss) => loss.code);// → ["removed-glyph-variant","removed-glyph-variant"]The library does not guess what belongs to the Greek, and converts only what does without doubt:
- Greek letters and their marks, and the signs that only Greek uses, by their code points: the Greek question mark (U+037E), the ano teleia (U+0387), the koronis (U+1FBD), the spacing breathings and accents, and the keraiai (U+0374 and U+0375), with U+02B9, which normalization makes of the right keraia, after Greek letters.
- The punctuation that Greek shares with other scripts is copied, glued
to a Greek word or not:
;,?, the middle dot·(U+00B7),:,',’, and-. Insee λόγος; also,;is English; inλογο·τέχνης, the middle dot separates the elements of a word, as the Bailly writes them. A Greek passage typed with the shared signs is converted as a whole, withconvert(), by the application that knows it is Greek. Normalization turns the Greek question mark and ano teleia into the shared signs: in a text normalized before the conversion, they are copied, which leaves the output incomplete, not wrong. - The options apply to the passages only: letter case, the Unicode form
of Greek output, its Greek punctuation scalars. Whitespace is never Greek,
and is copied:
text.whitespace: "collapse"has nothing to collapse.
The passages are converted as their letters are, wherever they are: a Greek
letter in another language (β-carotène, π, a siglum) is converted too.
convertGreekPassagesDetailed() reads back the Greek passages of the
output, and reports no loss for the text copied, whose spans in the output
are those in the input, moved. Into Greek, the passages are normalized in
the style of the options. A converter (createConverter()) converts the
passages with its characters and scope; its own Greek spellings belong to
them, whatever characters they are made of.
Characters of another format
Section titled “Characters of another format”Each reader reads its own format, and keeps the rest as literals: Greek
characters in Beta Code or transliteration, Latin letters in Greek, the
Latin letters that transliteration does not read (an h on its own, or c
by default), and in Beta Code the Unicode combining marks, which are not
Beta Code. A writer copies those literals, and a reader of the target format
may then read them: ϗ in a Beta Code source is a literal, which Greek
output copies, and which Greek reads as και, as it reads a middle dot as
the ano teleia (see
Punctuation and numerals), and
Beta Code reads a Latin letter as a Greek one: under ALA-LC, whose numerals
are decimal, hʹ in transliteration gives h# in Beta Code, which reads
back as the numeral 8. Converting such output again may change it, and convertDetailed()
reports the loss of the literal (unrepresented-literal). Type #1532 in
Beta Code, and kai in transliteration, or the accent’s own code (a/)
rather than U+0301. A combining mark typed on a sign that a reader reads as
a mark goes with it: in transliteration, the acute after the koronis of
YO᾽́A is the omicron’s, as the koronis is. The breathings and accents that older editions print
before a capital, as signs of their own (U+1FBF, U+1FFE, and their compounds
with an accent), and the tonos that typewriters and ISO 8859-7 put before
one (U+0384), are the exception: every reader reads them, as the capital’s
at the start of a word (῾Ρωμαῖοι is Ῥωμαῖοι, ΄Ελληνας Έλληνας).
What the library does not do
Section titled “What the library does not do”- It does not infer what the text does not write. A missing rough breathing, an iota adscript, or anything else that requires a dictionary or knowledge of the language is not supplied. The preset behavior audit lists, for each standard, the rules that depend on such knowledge.
- It does not claim complete conformance to a standard. Each preset states
its references, its coverage (
complete,partial,adapted, orplanned), and what it does not implement, in the preset reference and at run time (getPresetMetadata()). - It does not separate languages, as described above.
- It does not lay out text. Letter shapes, uncial ones included, are a matter of font, and removing the spaces between words is left to the caller.
- It does not bound normalization. Every conversion normalizes the text
(
String.prototype.normalize()), whose time grows with the square of the number of combining marks on one letter: thousands of them, which no text has, take seconds,convertDetailed()from or into Beta Code most of all, since it pairs each mark with the output. Limit the length of untrusted input accordingly.
What the engine covers
Section titled “What the engine covers”Polytonic and monotonic accentuation, diphthongs, hiatus, breathings in context, crasis and coronis, elision, letter forms (sigma, beta, and the symbol forms), archaic letters, Greek punctuation, and marked alphabetic numerals.
Where each behavior is specified
Section titled “Where each behavior is specified”| Topic | Document |
|---|---|
| Options, functions, and types | The API documentation (TSDoc of the exported declarations) |
| Options, their values, defaults, and presets | Options |
| Presets and their exact options | Presets |
| Loss by format pair and option | Information loss |
| Detailed results, positions, and spans | Conversion analysis |
| Accentuation, letter forms, and Unicode output | Greek output |
| Punctuation and alphabetic numerals | Punctuation and numerals |
| Custom characters and repertoires | Character extensions |
| The canonical document and its validation | Document API and Validation |
| What the version number protects, and reading rules | Stability policy |