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

    Module resource

    Resource identifiers and HTTP utilities.

    Provides types and functions for resource identifiers (URI/IRI), namespace factories, HTTP error handling, and fetch operations.

    Type Guards

    import { isURI, isIRI } from "@metreeca/core";

    const value = "http://example.org/resource";

    if (isURI(value)) {
    // value is typed as URI (ASCII-only)
    }

    if (isIRI(value)) {
    // value is typed as IRI (allows Unicode)
    }

    Identifier Factories

    import { asURI, asIRI } from "@metreeca/core";

    // Absolute identifiers

    const absoluteURI = asURI("http://example.org/resource");
    const absoluteIRI = asIRI("http://example.org/resource");

    // Relative references

    const relativeURI = asURI("../resource", "relative");
    const relativeIRI = asIRI("../resource", "relative");

    // Root-relative (internal) paths

    const internalURI = asURI("/resource", "internal");
    const internalIRI = asIRI("/resource", "internal");

    // Unicode in IRIs (throws for URIs)

    const unicodeIRI = asIRI("http://example.org/资源");

    Reference Operations

    import { resolve, relativize, internalize, asURI } from "@metreeca/core";

    const base = asURI("http://example.com/a/b/c");

    // Resolve relative references against base

    resolve(base, asURI("../d", "relative")); // "http://example.com/a/d"
    resolve(base, asURI("/d", "internal")); // "http://example.com/d"

    // Convert absolute to root-relative (internal) path

    internalize(base, asURI("http://example.com/x/y")); // "/x/y"

    // Convert absolute to relative path

    relativize(base, asURI("http://example.com/a/d")); // "../d"

    Namespace Factories

    import { createNamespace } from "@metreeca/core";

    // Closed namespace with predefined terms

    const rdfs = createNamespace("http://www.w3.org/2000/01/rdf-schema#", [
    "label",
    "comment"
    ]);

    rdfs(); // IRI: "http://www.w3.org/2000/01/rdf-schema#"
    rdfs.label; // IRI: "http://www.w3.org/2000/01/rdf-schema#label"
    rdfs("comment"); // IRI: "http://www.w3.org/2000/01/rdf-schema#comment"
    rdfs("seeAlso"); // Throws RangeError: unknown term

    // Open namespace for dynamic terms

    const ex = createNamespace("http://example.org/");

    ex(); // IRI: "http://example.org/"
    ex("anything"); // IRI: "http://example.org/anything"

    HTTP Error Handling

    import { Problem } from "@metreeca/core";

    const problem: Problem = {
    status: 404,
    title: "Not Found",
    detail: "Resource /api/users/123 does not exist",
    instance: "/api/users/123",
    report: { timestamp: "2025-12-02T10:30:00Z" }
    };

    Fetch Utilities

    import { createFetch } from "@metreeca/core";

    const guard = createFetch(fetch);

    try {
    const response = await guard("https://api.example.com/data");
    // response.ok is guaranteed true
    } catch (problem) {
    // problem is a Problem with parsed error details
    console.error(problem.status, problem.detail, problem.report);
    }

    Type Aliases

    URI

    Uniform Resource Identifier (URI) as defined by RFC 3986.

    IRI

    Internationalized Resource Identifier (IRI) as defined by RFC 3987.

    Variant

    Identifier variant per RFC 3986 §§ 4.2-4.3.

    Namespace

    Factory function type for generating IRIs within a common namespace.

    Terms

    Mapped type for namespace term properties.

    Interfaces

    Problem

    Problem Details for HTTP APIs.

    Functions

    isURI

    Checks if a value is a valid URI.

    asURI

    Creates a validated URI from a string.

    isIRI

    Checks if a value is a valid IRI.

    asIRI

    Creates a validated IRI from a string.

    resolve

    Resolves a reference against a base identifier.

    internalize

    Extracts a root-relative reference.

    relativize

    Creates a relative reference from base to reference.

    createNamespace

    Creates a namespace factory for generating IRIs within a common namespace.

    createFetch

    Creates a fetch function with consistent promise resolution/rejection behavior.