bahai-reflib-data
Advanced tools
Comparing version 0.8.0 to 0.9.0
# CHANGES for `bahai-reflib-data` | ||
## 0.9.0 | ||
- feat: add `getFullInfoForUrl` | ||
## 0.8.0 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "bahai-reflib-data", | ||
"version": "0.8.0", | ||
"version": "0.9.0", | ||
"author": "Brett Zamir <brettz9@yahoo.com>", | ||
@@ -62,3 +62,3 @@ "contributors": [], | ||
"build-data": "node tools/index.js", | ||
"eslint": "eslint --ext=js,cjs,mjs,md,html", | ||
"eslint": "eslint --ext=js,cjs,mjs,md,html .", | ||
"lint": "npm run eslint --", | ||
@@ -65,0 +65,0 @@ "mocha": "mocha --require chai/register-expect.js --delay", |
@@ -7,2 +7,87 @@ import { | ||
/** | ||
* @todo Should build optimized version to avoid all this processing | ||
* @param {string} url | ||
* @param {"fa"|"en"} [language] If none is provided, will check all languages | ||
* @returns {Promise<{work: string, section: string, paragraph: number}|false>} | ||
*/ | ||
async function getFullInfoForUrl (url, language) { | ||
const [ | ||
idsToSectionsAndParagraphs, works, sections | ||
] = await Promise.all([ | ||
getIdsToSectionsAndParagraphs(language), | ||
getWorks(language), | ||
getSections(language) | ||
]); | ||
const { | ||
groups: {id} | ||
} = url.match(/\/\d#(?<id>\d+)$/u) || {groups: {}}; | ||
if (!id) { | ||
return false; | ||
} | ||
const workSectionParagraph = idsToSectionsAndParagraphs[id]; | ||
const subSectionInfo = sections.subSections.find(({ | ||
url: subSectionUrl, parentUrl, title: sectionTitle | ||
}) => { | ||
return subSectionUrl === url; | ||
}); | ||
/* c8 ignore next 3 */ | ||
if (!subSectionInfo) { | ||
return false; | ||
} | ||
// See discussion below on another `sections.mainSections.find` | ||
const mainSectionInfo = sections.mainSections.find(({ | ||
parentUrl: mainSectionParentUrl | ||
}) => { | ||
return mainSectionParentUrl === subSectionInfo.parentUrl; | ||
}); | ||
/* c8 ignore next 3 */ | ||
if (!mainSectionInfo) { | ||
return false; | ||
} | ||
const workInfo = works.find(({url: workUrl}) => { | ||
return subSectionInfo.parentUrl === workUrl; | ||
}); | ||
/* c8 ignore next 3 */ | ||
if (!workInfo) { | ||
return false; | ||
} | ||
const { | ||
parentUrl: subSectionParentUrl, | ||
url: subSectionUrl, | ||
title: subSectionTitle, | ||
id: subSectionId | ||
} = subSectionInfo; | ||
const { | ||
parentUrl: mainSectionParentUrl, | ||
url: mainSectionUrl, | ||
title: mainSectionTitle, | ||
id: mainSectionId | ||
} = mainSectionInfo; | ||
const { | ||
parentUrl: workParentUrl, | ||
url: workUrl, | ||
title: workTitle | ||
} = workInfo; | ||
return { | ||
...workSectionParagraph, | ||
subSectionParentUrl, subSectionUrl, subSectionTitle, subSectionId, | ||
mainSectionParentUrl, mainSectionUrl, mainSectionTitle, mainSectionId, | ||
workParentUrl, workUrl, workTitle | ||
}; | ||
} | ||
/** | ||
* @param {string} id | ||
@@ -151,3 +236,3 @@ * @param {"fa"|"en"} [language] If none is provided, will check all languages | ||
}) => { | ||
const found = works.find(({url, title}) => { | ||
const found = works.find(({title}) => { | ||
return work === title; | ||
@@ -194,3 +279,3 @@ }); | ||
// See discussion above on another `sections.mainSections.find` | ||
const innerFound = works.find(({url, title}) => { | ||
const innerFound = works.find(({title}) => { | ||
return work === title; | ||
@@ -226,3 +311,3 @@ }); | ||
}) => { | ||
const found = works.find(({url, title}) => { | ||
const found = works.find(({title}) => { | ||
return work === title; | ||
@@ -245,2 +330,3 @@ }); | ||
export { | ||
getFullInfoForUrl, | ||
getWorkSectionAndParagraphForId, | ||
@@ -247,0 +333,0 @@ getIdForWorkSectionAndParagraph, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8448417
327604