Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bahai-reflib-data

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bahai-reflib-data - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

8

CHANGES.md
# CHANGES for `bahai-reflib-data`
## 0.11.0
- feat(`getSectionInfoForWork`): add new method
- feat(`getParagraphsForSectionId`): add new method
- fix(`getSectionNamesForWork`): ensure returns from `mainSections` if not
found in `subSections` (will get first lines)
- fix(`getUrlForWorkAndSection`): gets the paragraphs for a work and first line
## 0.10.0

@@ -4,0 +12,0 @@

6

package.json
{
"name": "bahai-reflib-data",
"version": "0.10.0",
"version": "0.11.0",
"author": "Brett Zamir <brettz9@yahoo.com>",

@@ -46,5 +46,5 @@ "contributors": [],

"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jsdoc": "^39.2.7",
"eslint-plugin-jsdoc": "^39.2.9",
"eslint-plugin-markdown": "^2.2.1",
"eslint-plugin-n": "^15.1.0",
"eslint-plugin-n": "^15.2.0",
"eslint-plugin-no-unsanitized": "^4.0.1",

@@ -51,0 +51,0 @@ "eslint-plugin-no-use-extend-native": "^0.5.0",

@@ -18,2 +18,6 @@ import {

/**
* @typedef {"fa"|"en"} Language
*/
/**
* @todo Should build optimized version to avoid all this processing

@@ -23,3 +27,3 @@ * @todo Might not get full info if two identical works have different

* @param {string} url
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<{work: string, section: string, paragraph: number}|false>}

@@ -114,3 +118,3 @@ */

* @param {string} id
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<{work: string, section: string, paragraph: number}>}

@@ -126,3 +130,3 @@ */

* @param {number} paragraph
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string>}

@@ -141,4 +145,4 @@ */

* @param {string} section
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @returns {Promise<string>}
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string[]>}
*/

@@ -170,2 +174,41 @@ async function getParagraphsForWorkAndSection (

/**
* @param {string} id
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string[]|undefined>}
*/
async function getParagraphsForSectionId (id, language) {
const [works, sections] = await Promise.all([
getWorks(language),
getSections(language)
]);
let parentUrl;
const section = sections.mainSections.find(({
id: mainSectionId, parentUrl: mainSectionParentUrl
}) => {
parentUrl = mainSectionParentUrl;
return mainSectionId === id;
})?.title || sections.subSections.find(({
id: subSectionId, parentUrl: subSectionParentUrl
}) => {
parentUrl = subSectionParentUrl;
return subSectionId === id;
})?.title;
if (!section) {
return undefined;
}
const work = works.find(({url}) => {
return parentUrl === url;
})?.title;
/* c8 ignore next 3 */
if (!work) {
return undefined;
}
return await getParagraphsForWorkAndSection(work, section, language);
}
/**
* @typedef {{

@@ -178,3 +221,3 @@ * parentUrl: string, url: string, title: string, id: string

* @param {string} url
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<SectionInfo|undefined>}

@@ -196,3 +239,3 @@ */

* @param {string} url
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string|undefined>}

@@ -207,3 +250,3 @@ */

* @param {string} id
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<SectionInfo|undefined>}

@@ -224,3 +267,3 @@ */

* @param {string} id
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string|undefined>}

@@ -234,3 +277,3 @@ */

/**
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string[]>}

@@ -254,3 +297,3 @@ */

* @param {string} work
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string[]>}

@@ -263,23 +306,30 @@ */

]);
return sections.subSections.filter(({parentUrl}) => {
// Due to a mismatch between the title found on the Table of Contents,
// and the one found as a heading on the page (e.g.,
// 'سراپردۀ يگانگی' and 'سراپردهٔ یگانگی', we need to match another way
// between section and work. But since the Table of Contents
// apparently doesn't store the ID, we need to check the works,
// directly, cross-referenced by parentUrl/url
// Due to a mismatch between the title found on the Table of Contents,
// and the one found as a heading on the page (e.g.,
// 'سراپردۀ يگانگی' and 'سراپردهٔ یگانگی', we need to match another way
// between section and work. But since the Table of Contents
// apparently doesn't store the ID, we need to check the works,
// directly, cross-referenced by parentUrl/url
const found = works.find(({title}) => {
return work === title;
});
/* c8 ignore next 3 */
if (!found) {
return [];
}
const subSectionMatches = sections.subSections.filter(({parentUrl}) => {
const mainSection = sections.mainSections.find(({
parentUrl: mainSectionParentUrl
}) => {
const found = works.find(({title}) => {
return work === title;
});
/* c8 ignore next 3 */
if (!found) {
return false;
}
return mainSectionParentUrl === found.url;
});
return mainSection && mainSection.parentUrl === parentUrl;
}).map(({title}) => {
});
return (
subSectionMatches.length
? subSectionMatches
: sections.mainSections.filter(({parentUrl}) => {
return parentUrl === found.url;
})
).map(({title}) => {
return title;

@@ -291,3 +341,43 @@ });

* @param {string} work
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string[]>}
*/
async function getSectionInfoForWork (work, language) {
const [works, sections] = await Promise.all([
getWorks(language),
getSections(language)
]);
// Due to a mismatch between the title found on the Table of Contents,
// and the one found as a heading on the page (e.g.,
// 'سراپردۀ يگانگی' and 'سراپردهٔ یگانگی', we need to match another way
// between section and work. But since the Table of Contents
// apparently doesn't store the ID, we need to check the works,
// directly, cross-referenced by parentUrl/url
const found = works.find(({title}) => {
return work === title;
});
/* c8 ignore next 3 */
if (!found) {
return [];
}
const subSectionMatches = sections.subSections.filter(({parentUrl}) => {
const mainSection = sections.mainSections.find(({
parentUrl: mainSectionParentUrl
}) => {
return mainSectionParentUrl === found.url;
});
return mainSection && mainSection.parentUrl === parentUrl;
});
return (
subSectionMatches.length
? subSectionMatches
: sections.mainSections.filter(({parentUrl}) => {
return parentUrl === found.url;
})
);
}
/**
* @param {string} work
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string>}

@@ -305,3 +395,3 @@ */

* @param {string} work
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string>}

@@ -334,3 +424,3 @@ */

* @param {string} section
* @param {"fa"|"en"} [language] If none is provided, will check all languages
* @param {Language} [language] If none is provided, will check all languages
* @returns {Promise<string[]>}

@@ -343,2 +433,11 @@ */

]);
const found = works.find(({title}) => {
return work === title;
});
/* c8 ignore next 3 */
if (!found) {
return [];
}
const subSectionFound = sections.subSections.find(({

@@ -351,10 +450,2 @@ parentUrl, title: sectionTitle

}) => {
const found = works.find(({title}) => {
return work === title;
});
/* c8 ignore next 3 */
if (!found) {
return false;
}
return mainSectionParentUrl === found.url;

@@ -366,3 +457,9 @@ });

return subSectionFound && subSectionFound.url;
return subSectionFound?.url ||
sections.mainSections.find(({
title: mainSectionTitle,
parentUrl: mainSectionParentUrl
}) => {
return mainSectionParentUrl === found.url && mainSectionTitle === section;
})?.url;
}

@@ -375,2 +472,3 @@

getParagraphsForWorkAndSection,
getParagraphsForSectionId,
getInfoForUrl,

@@ -382,2 +480,3 @@ getIdForUrl,

getSectionNamesForWork,
getSectionInfoForWork,
getUrlForWork,

@@ -384,0 +483,0 @@ getSubsectionUrlForWork,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc