platform-bible-utils
    Preparing search index...

    Class UsjReaderWriter

    Represents USJ formatted scripture with helpful utilities for working with it. Some notable features:

    • Find Scripture text in the USJ document

      • extractText
      • extractTextBetweenPoints
      • findNextLocationOfMatchingText
      • search
      • usfmVerseLocationToNextTextLocation
    • Edit the USJ document: removeContentNodes

    • Transform USJ to USFM: toUsfm

    • Transform USJ document locations to USFM locations and vice versa

      • usfmVerseLocationToUsjDocumentLocation
      • usjDocumentLocationToUsfmVerseRefVerseLocation
    • Use the version of USFM you need by passing in a custom markers map to the constructor if the version in your USJ document is not supported by default: UsjReaderWriterOptions.markersMap

    Notes:

    • "node" is a term used in the methods in this class that usually means an object or content string somewhere in the USj document, either Usj or MarkerContent. However, in specific situations, it may refer only to MarkerObject or MarkerContent. The TypeScript types indicate when this is the case.
    • See UsfmVerseLocation and UsjDocumentLocation for information about transforming USFM locations and USJ locations including what kinds of USFM locations are and are not representable in USJ locations, which USJ locations actually correspond to something in USJ, etc.
    • It is best to reuse the same UsjReaderWriter for the same USJ document as long as possible because there is a significant amount of processing and caching done internally to facilitate various operations. Note that, if the USJ document added to UsjReaderWriter changes, you must run usjChanged to clear the internal caches and receive accurate results from future method calls

    Implements

    Index

    Constructors

    Methods

    • Determine if the passed in marker is the top-level USJ marker.

      Note that USJ markers that are not the top-level USJ markers technically should not occur, but they can occur. We should treat them like any other marker. They conform to MarkerObject, so it's not hard to do.

      Parameters

      • marker: Usj | MarkerContent

        Marker to test if it is USJ marker

      • workingStack: WorkingStack

      Returns marker is Usj

      true if it is a USJ marker; false otherwise

    • Convert a JSONPath query into a SerializedVerseRef and offset

      Parameters

      • jsonPathQuery: string

        JSONPath search expression that indicates a node within this USJ data. If the expression matches more than one node, then only the first node found is considered. Note that this query must yield a MarkerContent or Usj; JSONPaths yielding properties on nodes are not currently supported.

      • OptionalbookIdIfNotFound: string

        3-letter ID of the book this USJ document is in (only used if a book ID is not found in the USJ document)

      Returns UsfmVerseRefVerseLocation

      SerializedVerseRef and offset that represent the location within this USJ data indicated by jsonPathQuery

      If not able to find a book ID in the USJ document and bookIdIfNotFound is not provided