monty5811/elm-bible/2.1.0

Bible

A library for working with Bible references.

Parsing

fromString : String -> Result String Reference

Attempt to convert a String into a Reference.

The following formats should work:

  • Genesis 1
  • Genesis 1:1
  • Genesis 1:1-20
  • Genesis 1:20-2:24
  • Genesis 1-5
  • Genesis 1 - Exodus 5
  • Genesis 1:1 - Exodus 5:20
  • Genesis 1:1 - Exodus 5
  • Genesis 1 - Exodus 5:20

Book names can be written in full or abbreviated, in any case, with or without a trailing dot: Psalm 23, Psalms 23, Ps. 23, 1 Cor 13, I Cor 13, First Corinthians 13, Jhn 3:16. Any whitespace works between the parts, and -, – and — all work as dashes.

Text after the reference is ignored, so John 3:16 (ESV) is John 3:16.

(fromString "Ps. 23" |> Result.map format)
    == Ok "Psalm 23:1-6"


(fromString "Gen 0" |> Result.map format)
    == Err "Chapter numbers start at 1"

Formatting

format : Reference -> String

Get a formatted String from a Reference.

Some example outputs:

  • Genesis 1:1
  • Genesis 1:1-11
  • Genesis 1:1 - 12:2
  • Genesis 1:1 - Exodus 2:4

Encoding

It may be useful to have a unique, compact representation of a reference for storage, searching, sorting, etc.

An easy way to achieve this is to convert the start and end of the reference to an Int. These integers can then be stored in a database, sorted, checked for intersections to do searches, etc.

The encoding process is as follows:

(1000000 * Book.toInt book) + (1000 * chapter) + verse

This results in an Int with the following structure

16001001
--===___
 | |  |
 | |  |
 | |  |--- Zero padded verse number
 | |------ Zero padded chapter number
 |-------- Book number
-> { start : Int
, end : Int
}

Convert a reference to an encoded representation.

(fromString "Gen 1:1 - Rev 5") |> Result.map encode)
    == Ok {start = 1001001, end = 66005014}
{ start : Int
, end : Int
}
-> Result String Reference

Attempt to convert an encoded value to a reference.

Fails if either value is outside Genesis 1:1 to Revelation 22:21, or the reference isn't valid.

Lower Level Parts

These functions may be useful if you want to build your own formatter, or something else. Bible.Book has the names, numbers and sizes of the books.

Get the book the reference starts with.

Get the book the reference ends with.

Get the name of the book the reference starts with.

Get the name of the book the reference ends with.

Get the chapter the reference starts with.

Get the chapter the reference ends with.

Get the verse the reference starts with.

Get the verse the reference ends with.

Types

An opaque type to represent a Bible reference.