@grafctory/core - v0.15.0
    Preparing search index...

    Function getIRIParent

    • Extracts the identifier of the collection enclosing a reference.

      Navigates one level up a path hierarchy: the parent of a member (a/b) is the collection holding it (a/), and the parent of a collection (a/b/) is the collection enclosing it (a/). The parent always ends with a slash, drops the query and fragment of iri, and keeps its variant:

      • Hierarchical (for example, http://example.org/a/b?q#f, base:/a/b/): an absolute identifier sharing scheme and authority (http://example.org/a/, base:/a/), down to the root path (http://example.org/a and http://example.org/a/ both yield http://example.org/)
      • Internal (for example, /a/b): a root-relative path (/a/), down to the root path (/a yields /)
      • Relative (for example, a/b, a, ../a/): a path-relative reference (a/, ./, ../); as relative references may climb indefinitely, a parent always exists, expressed through .. segments where needed (.. yields ../../)

      Dot segments are resolved per RFC 3986 § 5.2.4, so http://example.org/a/./b/../c yields http://example.org/a/ and a/../b yields ./; relative references keep their leading .. segments, as no base is there to absorb them.

      Rooted parents whose path opens with an empty segment keep a /. guard, so /a/..//b yields /.// rather than a // that would read as a network-path reference naming an authority (RFC 3986 § 4.2).

      Parameters

      • iri: string

        The reference to extract the parent from

      Returns Optional<string>

      The parent reference, or undefined if iri has none: root paths of hierarchical and internal references, opaque identifiers (for example, urn:example:a), relative references with an empty path (for example, "", ?q, #f, whose parent depends on the base they are resolved against), and invalid references (for example, strings carrying an isolated UTF-16 surrogate or opening with //)