Skip to content

Commit

Permalink
fixes for verse spans
Browse files Browse the repository at this point in the history
  • Loading branch information
PhotoNomad0 committed Sep 30, 2021
1 parent 69c258c commit 9a4342f
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 24 deletions.
63 changes: 45 additions & 18 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "checking-tool-wrapper",
"description": "Checking tool wrapper for translationCore App",
"version": "6.0.1",
"version": "6.0.2-alpha",
"main": "lib/index.js",
"scripts": {
"lint": "eslint ./src",
Expand Down
4 changes: 2 additions & 2 deletions src/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ export default class Api extends ToolApi {
const contextId = {
reference: {
bookId,
chapter: parseInt(chapter),
verse: parseInt(verse),
chapter: chapter,
verse: verse,
},
};
const groupsDataForVerse = getGroupDataForVerse(groupsData, contextId);
Expand Down
52 changes: 49 additions & 3 deletions src/helpers/groupDataHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,61 @@ export const findGroupDataItem = (contextId, groupData) => {
return index;
};

/**
* get verse range from span
* @param {string} verseSpan
* @return {{high: number, low: number}}
*/
export function getVerseSpanRange(verseSpan) {
let [low, high] = verseSpan.split('-');
low = parseInt(low);
high = parseInt(high);
return { low, high };
}

/**
* test if verse is valid verse number or verse span string
* @param {string|number} verse
* @return {boolean}
*/
export function isVerseSpan(verse) {
const isSpan = (typeof verse === 'string') && verse.includes('-');
return isSpan;
}

/**
* make sure context IDs are for same verse. Optimized over isEqual()
* @param {Object} contextId1
* @param {Object} contextId2
* @param {string|number} verseSpan
* @param {number} verse
* @return {boolean} returns true if verse within verse span
*/
export function isVerseWithinVerseSpan(verseSpan, verse) {
const { low, high } = getVerseSpanRange(verseSpan);

if ((low > 0) && (high > 0)) {
return ((verse >= low) && (verse <= high));
}
return false;
}

/**
* make sure context IDs are for same verse. Optimized over isEqual()
* @param {Object} contextId1 - context we are checking
* @param {Object} contextId2 - context that we are trying to match, could have verse span
* @return {boolean} returns true if context IDs are for same verse
*/
export function isSameVerse(contextId1, contextId2) {
return (contextId1.reference.chapter === contextId2.reference.chapter) &&
const match = (contextId1.reference.chapter === contextId2.reference.chapter) &&
(contextId1.reference.verse === contextId2.reference.verse);

if (!match) { // if not exact match, check for verseSpan
if ((contextId1.reference.chapter === contextId2.reference.chapter)) {
if (isVerseSpan(contextId2.reference.verse)) {
return isVerseWithinVerseSpan(contextId2.reference.verse, contextId1.reference.verse);
}
}
}
return match;
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { default as Api } from './Api';
export { default as Container } from './Container';
export { default as reducers } from './state/reducers';
export { getQuoteAsString } from './helpers/checkAreaHelpers';
export { getAlignedTextFromBible } from './helpers/gatewayLanguageHelpers';

0 comments on commit 9a4342f

Please sign in to comment.