npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

uw-quote-helpers

v1.1.7

Published

An open component package for generating target quotes from an aligned Bible.

Readme

uw-quote-helpers

A helpers library for handling and generating quotes from ®unfoldingWord scripture resources.

Installation

npm install uw-quote-helpers
# or
pnpm add uw-quote-helpers
# or
yarn add uw-quote-helpers

Peer Dependencies

This library requires usfm-js as a peer dependency:

npm install usfm-js
# or
pnpm add usfm-js
# or
yarn add usfm-js

API

Quote Functions

getTargetQuoteFromSourceQuote({ quote, ref, sourceBook, targetBook, options })

Gets the target quote string from a source quote string.

Parameters:

  • quote (string): The source quote
  • ref (string): The reference (e.g. "1:1,10")
  • sourceBook (object): The source book chapters object (see Book Data Structure below)
  • targetBook (object): The target book chapters object (see Book Data Structure below)
  • options (object):
    • occurrence (number|string): The occurrence to find in the given reference (default: -1)
    • fromOrigLang (boolean): True if the source language is an original language (default: true)

Example:

const params = {
  quote: "καὶ μεθ' ἡμῶν ἔσται",
  ref: "1:2",
  sourceBook: greekBook,
  targetBook: englishBook,
  options: { occurrence: 1 }
};

const result = getTargetQuoteFromSourceQuote(params);
console.log(result); // "and will be with us"

cleanQuoteString(quote)

Cleans and normalizes a quote string by fixing punctuation and spacing.

Example:

const quote = '"Hello ,world"  ...  how are you?';
const cleaned = cleanQuoteString(quote);
console.log(cleaned); // "Hello, world … how are you?"

normalize(str, isOrigLang)

Normalizes a string by tokenizing and rejoining with spaces.

Example:

const str = "μεθ' ἡμῶν";
const normalized = normalize(str, true);
console.log(normalized); // "μεθ ἡμῶν"

Scripture Functions

getQuoteMatchesInBookRef({ quote, ref, bookObject, isOrigLang, occurrence })

Finds matches for a quote within a specific book reference.

Example:

const params = {
  quote: "καὶ μεθ' ἡμῶν",
  ref: "1:2",
  bookObject: sourceBook,
  isOrigLang: true,
  occurrence: 1
};

const matches = getQuoteMatchesInBookRef(params);
console.log(matches);
/* Returns a Map with entries like:
Map {
  "1:2" => [
    { text: "καὶ", occurrence: 1 },
    { text: "μεθ", occurrence: 1 },
    { text: "ἡμῶν", occurrence: 1 }
  ]
}
*/

getTargetQuoteFromWords({ targetBook, wordsMap })

Generates target language quotes from matched words.

Parameters:

  • targetBook (object): The target book chapters object (see Book Data Structure below)
  • wordsMap (Map): A map of verse references to arrays of word objects (see getQuoteMatchesInBookRef return value)

Example:

const wordsMap = new Map([
  ["1:2", [
    { text: "καὶ", occurrence: 1 },
    { text: "μεθ", occurrence: 1 },
    { text: "ἡμῶν", occurrence: 1 }
  ]]
]);

const result = getTargetQuoteFromWords({
  targetBook,
  wordsMap
});
console.log(result); // "and with us"

getParsedUSFM(usfmData)

Parses USFM data into a JSON structure. To get the book data structure needed for other functions, access the .chapters property of the result.

Parameters:

  • usfmData (string): USFM data to parse

Returns:

  • A parsed USFM object. Use .chapters to get the book data structure needed for other functions.

Example:

const usfmData = '\\id GEN\n\\c 1\n\\v 1 In the beginning...';
const parsedData = getParsedUSFM(usfmData);
console.log(parsedData.chapters);
/* Output:
{
  "1": {
    "1": {
      "verseObjects": [
        { "text": "In", "type": "word" },
        { "text": " ", "type": "text" },
        { "text": "the", "type": "word" },
        { "text": " ", "type": "text" },
        { "text": "beginning", "type": "word" }
      ]
    }
  }
}
*/

setBook(bookData, ref)

Creates a book object with verse iteration capabilities.

Parameters:

  • bookData (object): A book chapters object (obtained from getParsedUSFM(usfmData).chapters)
  • ref (string): The reference to set (e.g. "1:1,10")

Returns:

  • A book object with verse iteration capabilities.

Example:

const bookData = getParsedUSFM(usfmData).chapters;
const book = setBook(bookData, "1:1,10");
console.log(book);
/* Output:
{
  "1": { "1": { "verseObjects": [...], "ref": "1:1,10" } }
}
*/

verseObjectsToString(verseObjects, map)

Converts verse objects to a string representation.

Parameters:

  • verseObjects (array): An array of verse objects (see getParsedUSFM return value)
  • map (Map): A map of verse references to arrays of word objects (see getQuoteMatchesInBookRef return value)

Returns:

  • A string representation of the verse objects.

Example:

const verseObjects = [{ text: "In", type: "word" }, { text: " ", type: "text" }, { text: "the", type: "word" }];
const map = new Map([["1:1", [{ text: "In", occurrence: 1 }, { text: " ", occurrence: 1 }, { text: "the", occurrence: 1 }]]]);
const result = verseObjectsToString(verseObjects, map);
console.log(result); // "In the"

Book Data Structure

The book data structure used by this library (for sourceBook and targetBook parameters) follows this format:

{
  "1": {  // chapter number
    "1": {  // verse number
      "verseObjects": [  // array of verse objects
        { "text": "In", "type": "word" },
        { "text": " ", "type": "text" },
        { "text": "the", "type": "word" },
        // ...
      ]
    },
    "2": {
      // next verse
    }
  },
  "2": {
    // next chapter
  }
}

You can obtain this structure by parsing USFM data:

const bookData = getParsedUSFM(usfmData).chapters;

Getting Started Developing

Using pnpm in terminal

  • clone the repo and cd into it
  • install by doing: pnpm i
  • run tests: pnpm test
  • do build: pnpm build
  • to publish a beta build: pnpm publish --tag beta
  • to publish final release: pnpm publish

Examples

  1. Getting target quotes from source quotes (Node.js)