awoken-bible-reference
Version:
Bible verse reference parser, generator and manipulator
65 lines (64 loc) • 2.14 kB
TypeScript
/**
* Allows for validation (and fixing) of BibleRefs
*/
import { BibleRef, BibleVerse, BibleRange } from './BibleRef';
import { Versification } from './Versification';
/**
* Enumeration of the different sorts of validation error
*/
export declare enum ErrKind {
/** The specified book does not exist */
BadBook = "BADBOOK",
/** Verse number is higher than number of verses in chapter */
BadVerse = "BADVERSE",
/** Chapter number is higher than number of chapters in book */
BadChapter = "BADCHPT",
/** A range goes from later in the bible to earlier in the bible */
BackwardsRange = "BACKWARDSRANGE",
/** A range contains just a single verse */
RangeOfOne = "RANGEOFONE"
}
/**
* Represents an error which was detected during validation
*/
export declare type ValidationError = {
kind: ErrKind.BadBook;
is_warning: false;
message: string;
got: string;
ref: BibleVerse;
} | {
kind: ErrKind.BadVerse | ErrKind.BadChapter;
is_warning: false;
message: string;
max_value: number;
got: number;
ref: BibleVerse;
} | {
kind: ErrKind.BackwardsRange;
is_warning: false;
message: string;
/** The most significant part of the range which is reversed */
component: "book" | "chapter" | "verse";
ref: BibleRange;
} | {
kind: ErrKind.RangeOfOne;
is_warning: true;
message: string;
ref: BibleRange;
};
/**
* Validates a BibleRef, returning an array of errors, or empty array if no
* issues
* Note that the .ref field of each error produced will be a reference to the
* BibleRef passed in rather than a copy
* @param include_warnings - if true then warning messages will be included
*/
export declare function validate(v: Versification, ref: BibleRef, include_warnings?: boolean): ValidationError[];
/**
* Attempts to fix errors identified by "validate". Will modify the specified
* ref in place rather than making a copy
* Will throw if the error is unfixable
* @return reference to the passed in BibleRef
*/
export declare function repair(v: Versification, ref: BibleRef, include_warnings?: boolean): BibleRef;