word-aligner
word-aligner is a small JavaScript utility (Node / browser) for vertically aligning words in an interlinear gloss (or any multi-line format).
Click here to open an issue on GitHub.
Basic Usage
Install the library using npm or yarn:
npm i @digitallinguistics/word-aligner
yarn add @digitallinguistics/word-aligner
Import the module:
import alignWords from '@digitallinguistics/word-aligner';
Run the utility on an array of the lines you’d like to vertically align:
const lines = [
`waxdungu qasi`,
`waxt-qungu qasi`,
`day-one man`,
];
const aligned = alignWords(lines);
The value of the aligned
variable will be:
[
"waxdungu qasi",
"waxt-qungu qasi",
"day-one man"
]
Note: word-aligner does not do automatic line detection. It will not know what type of line you are handing it (morphemes, glosses, translation, etc.). Only provide the lines you actually want aligned. Usually this means you will not provide a free translation line.
Options
Option | Default | Description |
---|---|---|
alignmentError |
false |
Specifies whether the library should throw an error if all lines do not have the same number of words. |
groupWith |
[] |
Specifies a pair of characters to use to group words together in a line. Any words enclosed by these characters will be treated as a single word by the library. |
separator |
spaces |
Specifies whether words should be aligned using spaces or tabs. Allowed values: spaces , tabs . |