Skip to content

Commit

Permalink
Fix bible.json formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Best-Codes committed Sep 9, 2024
1 parent 7bd9d0c commit 84f6525
Show file tree
Hide file tree
Showing 12 changed files with 80,912 additions and 47,217 deletions.
33,614 changes: 33,614 additions & 0 deletions .deprecated/bible.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/browser/best-bible.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/browser/best-bible.min.js.map

Large diffs are not rendered by default.

31,464 changes: 15,732 additions & 15,732 deletions dist/cjs/data/bible.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ isValidVerse, } = require(`./utils/validation`);
* @return {Array|String} The parsed verse based on the output type.
*/
function parseVerse(verse, outputType = "default") {
/* @deprecated: The bible.json file will resolve these errors itself. */
// Remove translation identifiers (text within square brackets)
let cleanedVerse = verse.replace(/\[(.*?)\]/g, "$1");
//let cleanedVerse = verse.replace(/\[(.*?)\]/g, "$1");
// Remove any '#' at the start of the verse
cleanedVerse = cleanedVerse.replace(/^#\s*/, "");
//cleanedVerse = cleanedVerse.replace(/^#\s*/, "");
// Trim any extra whitespace
cleanedVerse = cleanedVerse.trim();
//cleanedVerse = cleanedVerse.trim();
// Remove multiple spaces
cleanedVerse = cleanedVerse.replace(/\s+/g, " ");
//cleanedVerse = cleanedVerse.replace(/\s+/g, " ");
/* @end-deprecated */
let cleanedVerse = verse;
if (outputType === "default" || outputType === "string") {
return cleanedVerse;
}
Expand Down
31,464 changes: 15,732 additions & 15,732 deletions dist/esm/data/bible.json

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ isValidVerse, } = require(`./utils/validation`);
* @return {Array|String} The parsed verse based on the output type.
*/
function parseVerse(verse, outputType = "default") {
/* @deprecated: The bible.json file will resolve these errors itself. */
// Remove translation identifiers (text within square brackets)
let cleanedVerse = verse.replace(/\[(.*?)\]/g, "$1");
//let cleanedVerse = verse.replace(/\[(.*?)\]/g, "$1");
// Remove any '#' at the start of the verse
cleanedVerse = cleanedVerse.replace(/^#\s*/, "");
//cleanedVerse = cleanedVerse.replace(/^#\s*/, "");
// Trim any extra whitespace
cleanedVerse = cleanedVerse.trim();
//cleanedVerse = cleanedVerse.trim();
// Remove multiple spaces
cleanedVerse = cleanedVerse.replace(/\s+/g, " ");
//cleanedVerse = cleanedVerse.replace(/\s+/g, " ");
/* @end-deprecated */
let cleanedVerse = verse;
if (outputType === "default" || outputType === "string") {
return cleanedVerse;
}
Expand Down
10 changes: 5 additions & 5 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,6 +1,6 @@
{
"name": "best-bible",
"version": "1.5.7",
"version": "1.5.8",
"description": "Fetch, parse, and analyze the Bible easily with JavaScript",
"scripts": {
"build:cjs": "tsc --project tsconfig.cjs.json || true && mkdir -p dist/cjs/data && cp src/data/bible.json dist/cjs/data/",
Expand Down
71 changes: 71 additions & 0 deletions scripts/processBible.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const fs = require('fs').promises;
const path = require('path');

function cleanVerse(verse) {
return verse
.replace(/\[(.*?)\]/g, '$1') // Remove translation identifiers
.replace(/^#\s*/, '') // Remove '#' at the start
.trim() // Trim whitespace
.replace(/\s+/g, ' '); // Remove multiple spaces
}

function parseVerse(verse) {
const parts = [];
let currentText = '';
const words = verse.split(' ');

words.forEach(word => {
if (word.startsWith('[') && word.endsWith(']')) {
if (currentText) {
parts.push({ text: currentText.trim(), type: 'normal' });
currentText = '';
}
parts.push({ text: word.slice(1, -1), type: 'added' });
} else {
currentText += ' ' + word;
}
});

if (currentText) {
parts.push({ text: currentText.trim(), type: 'normal' });
}

return parts;
}

async function processBible(inputFile, cleanedOutput, parsedOutput) {
try {
const data = await fs.readFile(inputFile, 'utf8');
const bible = JSON.parse(data);

const cleanedBible = {};
const parsedBible = {};

for (const [book, chapters] of Object.entries(bible)) {
cleanedBible[book] = {};
parsedBible[book] = {};
for (const [chapter, verses] of Object.entries(chapters)) {
cleanedBible[book][chapter] = verses.map(cleanVerse);
parsedBible[book][chapter] = verses.map((verse, index) => ({
[index + 1]: parseVerse(verse)
}));
}
}

await fs.writeFile(cleanedOutput, JSON.stringify(cleanedBible, null, 2));
await fs.writeFile(parsedOutput, JSON.stringify(parsedBible, null, 2));

console.log('Processing complete. Files created:');
console.log(cleanedOutput);
console.log(parsedOutput);
} catch (error) {
console.error('An error occurred:', error);
}
}

// Run the process
const inputFile = path.join(__dirname, 'bible.json');
const cleanedOutput = path.join(__dirname, 'bible_cleaned.json');
const parsedOutput = path.join(__dirname, 'bible_parsed.json');

processBible(inputFile, cleanedOutput, parsedOutput);
Loading

0 comments on commit 84f6525

Please sign in to comment.