@metreeca/core - v0.12.0
    Preparing search index...

    Function relativize

    • Creates a relative reference from base to reference.

      • Hierarchical identifiers: Computes the shortest path-relative reference that, when resolved against base, yields reference
      • Authority-less hierarchical identifiers (app:/…, file:///…): Returns the root-relative path
      • Opaque identifiers: Returns the scheme-specific part if schemes match

      The returned reference always resolves back to reference under RFC 3986 § 5 and under any conforming URL parser: a first segment carrying a colon is prefixed with a ./ dot segment so it cannot read as a scheme, and where an empty first segment would read as an authority the absolute reference is returned instead. Callers may therefore resolve the result against base without further escaping.

      Parameters

      • base: string

        The absolute base identifier

      • reference: string

        The reference to relativize

      Returns string

      A relative reference from base to reference, or the normalized absolute reference if not relativizable

      RangeError If base is not a valid absolute identifier or reference is not a valid relative reference, for instance because it carries an isolated UTF-16 surrogate or opens with //