Provides methods to add or subtract verses from a given reference and to get a distance between one or two references.
Include bible.math.min.js
in your project found in the /dist
.
Use bible.parseReference
to get a reference object.
You can, however, manually create a reference object as defined below and use it.
var ref = bible.parseReference('Romans 1:2');
ref.add(10); // changes reference object to Romans 1:12
ref.toString(); // Romans 1:12
For those with Bower: bower install bible.math --save
All references use the bible.Reference object format.
bible.add(reference, verses) // changes reference to new value
Example: Add 10 verses to 1 John 5:20
var ref1 = {bookIndex: 61, chapter: 5, verse: 20, chapter1: 5, verse1: 20, chapter2: -1, verse2: -1};
ref1.add(10);
ref1.toString(); // returns "2 John 1:9"
Keys chapter and verse of the returned object remain unchanged. Chapter1 and verse1 are the correct chapter and verse.
bible.subtract(reference, verses) // changes reference to new value
Exmple: Subtract 10 verses from 2 John 7
var ref1 = {bookIndex: 62, chapter: 1, verse: 7, chapter1: 1, verse1: 7, chapter2: -1, verse2: -1};
var result = ref1.subtract(10);
ref.toString(); // returns "1 John 5:19"
Keys chapter and verse of the returned object remain unchanged. Chapter1 and verse1 are the correct chapter and verse.
If subtracting a number of verses from the reference equals zero, then the last verse of the preceding chapter is returned.
For example, if seven verses are subtracted from 2 John 1:7, then a reference to 1 John 5:21 is returned.
bible.distance(reference1, *reference2) // returns javascript object with chapters and verses
Example: Calculate distance between Genesis 2:5 and Leviticus 4:5.
var ref1 = {bookIndex: 0, chapter: 2, verse: 5, chapter1: 2, verse1: 5, chapter2: -1, verse2: -1};
var ref2 = {bookIndex: 2, chapter: 4, verse: 5, chapter1: 4, verse1: 5, chapter2: -1, verse2: -1};
bible.distance(ref1, ref2); // returns {'chapters': 92, 'verses': 2766}
The distance calculation includes the referenced verses. The distance between Gen 1:1 and Gen 1:3 is three.
Why? If one is reading verses Gen 1:1-3, one has read three verses.
The distance between Gen 1 and Gen 3 is {chapters: 2, verses: 80}
. There are two chapters between Gen 1:1 and Gen 3:1 and 80 verses from Gen 1:1 to Gen 3:24 (i.e. beginning of Gen 1 to the end of Gen 3).
- The bible order of the references does not matter.
- If more than two references are passed, only the first two will be used.
- Only one reference is necessary if chapter2 and verse2 of the object contain values.
- The
distance
method can calculate the distance (chapters and verses) of an entire book, however the reference must be created manually. This is becauseparseReference('Gen')
returns the same object asparseReference('Gen 1')
. The reference must setchapter
andchapter1
to-1
.
bookIndex: _bookIndex,
chapter: _chapter1,
verse: _verse1,
chapter1: _chapter1,
verse1: _verse1,
chapter2: _chapter2,
verse2: _verse2
-1 as a value of any key represents that the key is unused.
Tests are found in the tests
directory.
Tests can be run either mannually by opening tests/tests.html
in a browser or on the command line via grunt test
.
- Add type checking and validation of inputs
- Add
add()
andsubtract()
functions to reference.
- Fix single chapter and verse distance calculations
- Fix whole chapter distance calculations
- Fix book names in bible.js
- Fix whole chapter references in bible.reference.js
- Update tests for whole chapter fix
- Distribute as single file
- Added Grunt for tests, concat, and minify
- Fixed whole chapter references
- Whole book distances are not assumed any more
- Handle whole chapter references
- Stops when adding or subtracting past the ends of the bible
- Changed meaning of normalize function
- Added denormalize function
Apache v2
Kyle Hornberg
Extends John Dyer's bible.js and bible.reference.js in bib.ly which is copyrighted by him and licensed under Creative Commons 3.0