Interface IUsjReaderWriter

Utilities for reading from and writing to Usj objects

interface IUsjReaderWriter {
    extractText(start: UsjContentLocation, desiredLength: number): string;
    extractTextBetweenPoints(
        start: UsjContentLocation,
        end: UsjContentLocation,
        maxLength: number,
    ): string;
    findNextLocationOfMatchingText(
        start: UsjContentLocation,
        text: string,
        maxTextLengthToSearch: number,
    ): undefined | UsjContentLocation;
    findParent<T>(jsonPathQuery: string): undefined | T;
    findSingleValue<T>(jsonPathQuery: string): undefined | T;
    jsonPathToVerseRefAndOffset(
        jsonPathQuery: string,
        bookId?: string,
    ): VerseRefOffset;
    nodeToJsonPath(node: MarkerObject): ContentJsonPath;
    nodeToVerseRefAndOffset(
        bookId: string,
        node: MarkerContent,
        nodeParent: undefined | MarkerObject | MarkerContent[],
    ): undefined | { offset: number; verseRef: VerseRef };
    removeContentNodes(
        searchFunction: (potentiallyMatchingNode: MarkerContent) => boolean,
    ): number;
    usjChanged(): void;
    verseRefToUsjContentLocation(
        verseRef: VerseRef,
        verseRefOffset: number,
    ): UsjContentLocation;
}

Implemented by

Methods

  • Given a starting point, find the next location in this USJ data that matches the given text

    Parameters

    • start: UsjContentLocation

      Point where the search for text will start

    • text: string

      Text to find

    • maxTextLengthToSearch: number

      Maximum length of text to search before stopping (default is 1000)

    Returns undefined | UsjContentLocation

    Object containing the USJ node where text begins (it might be split across nodes), offset within that node that indicates where text begins, and a JSONPath string that indicates the location of the of USJ node within usj. Note that if the USJ node returned is an object, it is the same object that is within this USJ data. So if you change it, you are changing this USJ data.

  • Convert a JSONPath query into a VerseRef 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.

    • OptionalbookId: string

      3 letter ID of the book being searched (must be defined in this USJ data if not provided here)

    Returns VerseRefOffset

    VerseRef and offset that represents the location within this USJ data indicated by jsonPathQuery

  • Determine the VerseRef and offset that correspond to the location of a node somewhere within this USJ data

    Parameters

    • bookId: string

      ID of the book represented by this USJ data

    • node: MarkerContent

      JSON object representing the location of the VerseRef and offset

    • nodeParent: undefined | MarkerObject | MarkerContent[]

      JSON object that owns the content array that includes node. If 'undefined' is provided then the UsjReaderWriter will attempt to lookup the parent of node. The lookup will always fail and throw an error if node is a string.

    Returns undefined | { offset: number; verseRef: VerseRef }

    VerseRef and offset representing the location of node, if one could be found

  • Remove all nodes from this USJ data that match a given search function.

    Parameters

    • searchFunction: (potentiallyMatchingNode: MarkerContent) => boolean

      Function that returns true if the given node should be removed

    Returns number

    Number of nodes removed

  • Convert a verse ref + offset into a node + offset within this USJ data and a JSONPath query

    Parameters

    • verseRef: VerseRef

      Indicates the book, chapter, and verse of interest to find

    • verseRefOffset: number

      Specific location within verse text (defaults to 0)

    Returns UsjContentLocation

    Object containing the USJ node indicated by verseRef and verseRefOffset, offset within that node that matches the verseRefOffset, and a JSONPath string that indicates the location of the of USJ node within this USJ data. Note that if the USJ node returned is an object, it is the same object that is within this USJ data. So if you change it, you are changing this USJ data.