Skip to content

Commit

Permalink
update 13 files
Browse files Browse the repository at this point in the history
  • Loading branch information
The-Best-Codes committed Jul 24, 2024
1 parent 6aea38c commit bbbf264
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 95 deletions.
52 changes: 21 additions & 31 deletions dist/cjs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,32 @@ const { isValidBook, isValidChapter, isValidVerse } = require(`./utils/validatio
* Parses a verse string and returns either an array of word objects or a cleaned string.
*
* @param {string} verse - The verse string to parse.
* @param {string} [outputType="default"] - The type of output. Can be "default" or "indexed".
* @param {string} [outputType="default"] - The type of output. Can be "default", "string", or "indexed".
* @return {Array|String} The parsed verse based on the output type.
*/
function parseVerse(verse, outputType = "default") {
const wordRegex = /[\s,;:.!?()]+/;
const words = verse.split(wordRegex);
const parsedWords = [];
let isParagraph = false;
words.forEach(word => {
let isTranslatorAdded = false;
let cleanWord = word;
// Check if the word is a paragraph indicator
if (cleanWord === '#') {
isParagraph = true;
return; // Skip adding the '#' to parsedWords
}
// Check if the word is added by translators
if (cleanWord.startsWith('[') && cleanWord.endsWith(']')) {
isTranslatorAdded = true;
cleanWord = cleanWord.substring(1, cleanWord.length - 1);
}
if (cleanWord) { // To avoid pushing empty strings
parsedWords.push({
word: cleanWord,
isParagraph: isParagraph,
isTranslatorAdded: isTranslatorAdded
});
isParagraph = false; // Reset paragraph indicator after using it
}
});
if (outputType === "indexed") {
return parsedWords;
// Remove translation identifiers (text within square brackets)
let cleanedVerse = verse.replace(/\[(.*?)\]/g, '$1');
// Remove any '#' at the start of the verse
cleanedVerse = cleanedVerse.replace(/^#\s*/, '');
// Trim any extra whitespace
cleanedVerse = cleanedVerse.trim();
// Remove multiple spaces
cleanedVerse = cleanedVerse.replace(/\s+/g, ' ');
if (outputType === "default" || outputType === "string") {
return cleanedVerse;
}
else if (outputType === "indexed") {
// Split the cleaned verse into words
const words = cleanedVerse.split(' ');
// Create an array of word objects
return words.map((word, index) => ({
word: word,
index: index
}));
}
else {
// Return the cleaned verse
return parsedWords.map(wordObj => wordObj.word).join(' ');
throw new Error("Invalid outputType. Use 'default' or 'indexed'.");
}
}
/**
Expand Down
52 changes: 21 additions & 31 deletions dist/esm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,32 @@ const { isValidBook, isValidChapter, isValidVerse } = require(`./utils/validatio
* Parses a verse string and returns either an array of word objects or a cleaned string.
*
* @param {string} verse - The verse string to parse.
* @param {string} [outputType="default"] - The type of output. Can be "default" or "indexed".
* @param {string} [outputType="default"] - The type of output. Can be "default", "string", or "indexed".
* @return {Array|String} The parsed verse based on the output type.
*/
function parseVerse(verse, outputType = "default") {
const wordRegex = /[\s,;:.!?()]+/;
const words = verse.split(wordRegex);
const parsedWords = [];
let isParagraph = false;
words.forEach(word => {
let isTranslatorAdded = false;
let cleanWord = word;
// Check if the word is a paragraph indicator
if (cleanWord === '#') {
isParagraph = true;
return; // Skip adding the '#' to parsedWords
}
// Check if the word is added by translators
if (cleanWord.startsWith('[') && cleanWord.endsWith(']')) {
isTranslatorAdded = true;
cleanWord = cleanWord.substring(1, cleanWord.length - 1);
}
if (cleanWord) { // To avoid pushing empty strings
parsedWords.push({
word: cleanWord,
isParagraph: isParagraph,
isTranslatorAdded: isTranslatorAdded
});
isParagraph = false; // Reset paragraph indicator after using it
}
});
if (outputType === "indexed") {
return parsedWords;
// Remove translation identifiers (text within square brackets)
let cleanedVerse = verse.replace(/\[(.*?)\]/g, '$1');
// Remove any '#' at the start of the verse
cleanedVerse = cleanedVerse.replace(/^#\s*/, '');
// Trim any extra whitespace
cleanedVerse = cleanedVerse.trim();
// Remove multiple spaces
cleanedVerse = cleanedVerse.replace(/\s+/g, ' ');
if (outputType === "default" || outputType === "string") {
return cleanedVerse;
}
else if (outputType === "indexed") {
// Split the cleaned verse into words
const words = cleanedVerse.split(' ');
// Create an array of word objects
return words.map((word, index) => ({
word: word,
index: index
}));
}
else {
// Return the cleaned verse
return parsedWords.map(wordObj => wordObj.word).join(' ');
throw new Error("Invalid outputType. Use 'default' or 'indexed'.");
}
}
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function searchVerse(query: string, caseSensitive?: boolean | undefined,
* Parses a verse string and returns either an array of word objects or a cleaned string.
*
* @param {string} verse - The verse string to parse.
* @param {string} [outputType="default"] - The type of output. Can be "default" or "indexed".
* @param {string} [outputType="default"] - The type of output. Can be "default", "string", or "indexed".
* @return {Array|String} The parsed verse based on the output type.
*/
export function parseVerse(verse: string, outputType?: string | undefined): any[] | string;
Expand Down
52 changes: 20 additions & 32 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,35 @@ const { isValidBook, isValidChapter, isValidVerse } = require(`./utils/validatio
* Parses a verse string and returns either an array of word objects or a cleaned string.
*
* @param {string} verse - The verse string to parse.
* @param {string} [outputType="default"] - The type of output. Can be "default" or "indexed".
* @param {string} [outputType="default"] - The type of output. Can be "default", "string", or "indexed".
* @return {Array|String} The parsed verse based on the output type.
*/
function parseVerse(verse, outputType = "default") {
const wordRegex = /[\s,;:.!?()]+/;
const words = verse.split(wordRegex);
const parsedWords = [];
// Remove translation identifiers (text within square brackets)
let cleanedVerse = verse.replace(/\[(.*?)\]/g, '$1');

let isParagraph = false;
// Remove any '#' at the start of the verse
cleanedVerse = cleanedVerse.replace(/^#\s*/, '');

words.forEach(word => {
let isTranslatorAdded = false;
let cleanWord = word;
// Trim any extra whitespace
cleanedVerse = cleanedVerse.trim();

// Check if the word is a paragraph indicator
if (cleanWord === '#') {
isParagraph = true;
return; // Skip adding the '#' to parsedWords
}

// Check if the word is added by translators
if (cleanWord.startsWith('[') && cleanWord.endsWith(']')) {
isTranslatorAdded = true;
cleanWord = cleanWord.substring(1, cleanWord.length - 1);
}
// Remove multiple spaces
cleanedVerse = cleanedVerse.replace(/\s+/g, ' ');

if (cleanWord) { // To avoid pushing empty strings
parsedWords.push({
word: cleanWord,
isParagraph: isParagraph,
isTranslatorAdded: isTranslatorAdded
});
isParagraph = false; // Reset paragraph indicator after using it
}
});
if (outputType === "default" || outputType === "string") {
return cleanedVerse;
} else if (outputType === "indexed") {
// Split the cleaned verse into words
const words = cleanedVerse.split(' ');

if (outputType === "indexed") {
return parsedWords;
// Create an array of word objects
return words.map((word, index) => ({
word: word,
index: index
}));
} else {
// Return the cleaned verse
return parsedWords.map(wordObj => wordObj.word).join(' ');
throw new Error("Invalid outputType. Use 'default' or 'indexed'.");
}
}

Expand Down
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const verse = getVerse('John', 3, 25);

console.log(verse);

console.log(getVerse('John', 3, 25, undefined, false));

console.log(bibleStats())

//console.log(searchVerse('Jesus'))

0 comments on commit bbbf264

Please sign in to comment.