• Extracts a literal value (primitive) from an RDF node

    Handles type coercion based on the JSON Schema type:

    • string: Returns the string value as-is
    • number: Parses as float, returns undefined if NaN
    • integer: Parses as int, returns undefined if NaN
    • boolean: Converts "true"/"false" strings to boolean
    • null: Returns null

    Parameters

    • node: GraphPointer

      The RDF node containing the literal value

    • schema: JSONSchema7

      The JSON Schema defining the expected type

    • ctx: ExtractionContext

      Extraction context for logging

    Returns string | number | boolean

    The extracted and coerced value, or undefined if missing/invalid

    // String literal
    const name = extractLiteral(node, { type: "string" }, ctx);
    // → "John Doe"

    // Number literal
    const age = extractLiteral(node, { type: "number" }, ctx);
    // → 42

    // Boolean literal
    const active = extractLiteral(node, { type: "boolean" }, ctx);
    // → true