platform-bible-utils
    Preparing search index...

    Interface IUsjReaderWriter

    Utilities for reading from and writing to Usj objects

    interface IUsjReaderWriter {
        extractText(
            start: UsjNodeAndDocumentLocation,
            desiredLength: number,
        ): string;
        extractTextBetweenPoints(
            start: UsjNodeAndDocumentLocation,
            end: UsjNodeAndDocumentLocation,
            maxLength: number,
        ): string;
        findNextLocationOfMatchingText(
            start: UsjNodeAndDocumentLocation,
            text: string,
            maxTextLengthToSearch: number,
        ): undefined | UsjNodeAndDocumentLocation<UsjTextContentLocation>;
        findParent<T>(jsonPathQuery: string): undefined | T;
        findSingleValue<T>(jsonPathQuery: string): undefined | T;
        jsonPathToUsfmVerseRefVerseLocation(
            jsonPathQuery: string,
            bookIdIfNotFound?: string,
        ): UsfmVerseRefVerseLocation;
        jsonPathToUsjNodeAndDocumentLocation(
            jsonPathQuery: string,
        ): UsjNodeAndDocumentLocation;
        nodeToJsonPath(node: MarkerObject): ContentJsonPath;
        nodeToUsfmVerseRefVerseLocation(
            node: Usj | MarkerContent,
            nodeParent?: Usj | MarkerObject | MarkerContent[],
            bookIdIfNotFound?: string,
        ): UsfmVerseRefVerseLocation;
        nodeToUsjNodeAndDocumentLocation(
            node: Usj | MarkerContent,
            nodeParent?: Usj | MarkerObject | MarkerContent[],
        ): UsjNodeAndDocumentLocation;
        removeContentNodes(
            searchFunction: (potentiallyMatchingNode: MarkerContent) => boolean,
        ): number;
        search(regex: RegExp): UsjSearchResult[];
        toUsfm(): string;
        usfmVerseLocationToIndexInUsfm(
            usfmVerseLocation: UsfmVerseLocation,
        ): number;
        usfmVerseLocationToNextTextLocation(
            usfmVerseLocation: UsfmVerseLocation,
        ): UsjNodeAndDocumentLocation<UsjTextContentLocation>;
        usfmVerseLocationToUsjDocumentLocation(
            usfmVerseLocation: UsfmVerseLocation,
        ): UsjDocumentLocation;
        usfmVerseLocationToUsjNodeAndDocumentLocation(
            usfmVerseLocation: UsfmVerseLocation,
        ): UsjNodeAndDocumentLocation;
        usjChanged(): void;
        usjDocumentLocationToUsfmVerseRefVerseLocation(
            usjLocation: UsjDocumentLocation,
            bookIdIfNotFound?: string,
        ): UsfmVerseRefVerseLocation;
    }

    Implemented by

    Index

    Methods

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

      Parameters

      • start: UsjNodeAndDocumentLocation

        Point where the search for text will start

      • text: string

        Text to find. Note you can use an empty string to find the closest text in or after the start point.

      • maxTextLengthToSearch: number

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

      Returns undefined | UsjNodeAndDocumentLocation<UsjTextContentLocation>

      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 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

    • Convert a JSONPath query into a USJ node, JSONPath, 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.

      Returns UsjNodeAndDocumentLocation

      USJ node, JSONPath, and offset that represent the location within this USJ data indicated by jsonPathQuery

    • Determine the location in the USFM representation of this data that corresponds to the location of a node somewhere within this USJ data

      Parameters

      • node: Usj | MarkerContent

        JSON object or string in the USJ data to get the USFM location for

      • OptionalnodeParent: Usj | MarkerObject | MarkerContent[]

        JSON object that owns the content array that includes node. Required if node is a string; optional and unused if node is a MarkerObject or Usj

      • 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 representing the location of node, if one could be found

      If node is a string and no nodeParent is provided

      If not able to establish relationship between string node and nodeParent

      If not able to find the node in the USJ document

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

    • Get the index in the USFM representation of this data relative to the start of the document that corresponds to the absolute verse location in USFM space passed in

      Parameters

      • usfmVerseLocation: UsfmVerseLocation

        The location in USFM space relative to a verse to get the index for

      Returns number

      Index in the USFM representation of this data relative to the start of the document

    • Get the node + offset and JSONPath query within this USJ data of the first encountered string after the provided USFM location for a specific verse in a USJ document.

      Note: this may return a node that is in a subsequent verse or even chapter depending on how much content the USJ data contains. It simply looks through the rest of the USJ data for the first text node and returns that.

      Parameters

      • usfmVerseLocation: UsfmVerseLocation

        Indicates the location in USFM space (book, chapter, verse, character offset) to find the next text for

      Returns UsjNodeAndDocumentLocation<UsjTextContentLocation>

      Object containing the first USJ text node after verseRef, and a JSONPath string that indicates the location of the USJ text node within this USJ data.

      Error if there is no text after usfmVerseLocation

      Error if usfmVerseLocation does not point to a valid location in this USJ data

    • Convert a verse-based location in USFM space into a location in USJ space within this USJ data.

      If the USJ document has no book markers in it to determine which book the USJ is in, the verseRef.book will be ignored, and only the chapter and verse numbers will be used to determine the location.

      Parameters

      • usfmVerseLocation: UsfmVerseLocation

        Location in USFM space - a book, chapter, verse, and character offset within the verse's USFM

      Returns UsjDocumentLocation

      Object containing the USJ location within the USJ document indicated by usfmVerseLocation.

    • Convert a verse-based location in USFM space into a node and location in USJ space within this USJ data.

      If the USJ document has no book markers in it to determine which book the USJ is in, the verseRef.book will be ignored, and only the chapter and verse numbers will be used to determine the location.

      Parameters

      • usfmVerseLocation: UsfmVerseLocation

        Location in USFM space - a book, chapter, verse, and character offset within the verse's USFM

      Returns UsjNodeAndDocumentLocation

      Object containing the USJ node and location within the USJ document indicated by usfmVerseLocation. 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 location in USJ space within this USJ data into a location in USFM space.

      Parameters

      • usjLocation: UsjDocumentLocation

        Location in USJ space - a jsonPath and other information about where the location is

      • 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

      Location in USFM space that is equivalent to the USJ location specified

      If not able to find the location in the USJ document

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