) - Readonly - The expected datatypes.
- **message** (string) - The error message.
- **name** (string) - The name of the error.
- **stack** (string) - Optional - The stack trace.
- **term** (Term) - Readonly - The term associated with this error.
```
--------------------------------
### Function string
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.string.html
Converts a string value into an RDF Term using the provided DataFactory.
```APIDOC
## Function string
### Description
Converts a string value into an RDF Term using a provided DataFactory.
### Parameters
- **value** (string) - Required - The string value to convert.
- **factory** (DataFactory) - Required - The DataFactory instance used to create the Term.
### Returns
- **Term** - The resulting RDF Term.
```
--------------------------------
### Function string
Source: https://rdf.js.org/wrapper/functions/BlankNodeFrom.string.html
Converts a string value into an RDF Term using the provided DataFactory.
```APIDOC
## Function string
### Description
Converts a string value into an RDF Term using the provided DataFactory.
### Parameters
- **value** (string | undefined) - Required - The string value to convert.
- **factory** (DataFactory) - Required - The factory used to create the term.
### Returns
- **Term** - The resulting RDF term.
```
--------------------------------
### Convert Base64 RDF Literal to Uint8Array
Source: https://rdf.js.org/wrapper/functions/LiteralAs.uInt8Array.html
Demonstrates mapping an xsd:base64Binary literal to a Uint8Array using a TermWrapper class.
```text
"MDEyMzQ1Njc4OQ=="^^ .
```
```typescript
class Class extends TermWrapper {
public get property(): Uint8Array {
return RequiredFrom.subjectPredicate(this, "p", LiteralAs.uInt8Array)
}
}
```
--------------------------------
### Add Item to Container using Dataset
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Use this method to add an item to a container within the dataset. This involves creating a new quad and adding it to the dataset.
```typescript
class Container extends TermWrapper {
add(something: string) {
const subject = this as Quad_Subject
const predicate = this.factory.namedNode("http://example.com/contains")
const object = this.factory.literal(something)
const quad = this.factory.quad(subject, predicate, object)
this.dataset.add(quad)
}
}
```
--------------------------------
### Function string
Source: https://rdf.js.org/wrapper/functions/NamedNodeFrom.string.html
Converts a string value into an RDF/JS Term using the provided factory.
```APIDOC
## string(value, factory)
### Description
Converts a string value into an RDF/JS Term using the provided DataFactory.
### Parameters
- **value** (string) - Required - The string value to convert.
- **factory** (DataFactory) - Required - The RDF/JS DataFactory instance used to create the term.
### Returns
- **Term** - The resulting RDF/JS Term object.
```
--------------------------------
### Usage of nested Person class
Source: https://rdf.js.org/wrapper/index.html
Demonstrates accessing and setting nested properties on wrapped objects.
```javascript
const person2 = new Person("https://example.org/person2", dataset_z, DataFactory)
// Get property
console.log(person2.name)
// outputs "Bob"
// Get property from child class
console.log(person2.mum.name)
// outputs "Alice"
// Set class properties
const person3 = new Person("https://example.org/person3", dataset_z, DataFactory)
person3.name = "Joanne"
person1.mum = person3
console.log(person1.mum.name)
// outputs "Joanne"
console.log(person2.mum.mum.name)
// outputs "Joanne"
```
--------------------------------
### DataFactory Usage
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Accessing the DataFactory to create new RDF terms such as literals and quads.
```APIDOC
## factory
### Description
Returns the DataFactory instance used by the wrapper to create terms.
### Returns
- **DataFactory**: A collection of methods for creating terms.
### Example
```typescript
const date = new Date().toISOString();
const xsdDateTime = this.factory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime");
return this.factory.literal(date, xsdDateTime);
```
```
--------------------------------
### Define a People dataset wrapper
Source: https://rdf.js.org/wrapper/index.html
Extends DatasetWrapper to iterate over subjects matching a specific predicate.
```javascript
class People extends DatasetWrapper {
[Symbol.iterator]() {
return this.subjectsOf("https://example.org/name", Person)
}
}
```
--------------------------------
### TermAs Namespace Functions
Source: https://rdf.js.org/wrapper/modules/TermAs.html
Overview of the available functions within the TermAs namespace for RDF/JS term conversion.
```APIDOC
## TermAs Namespace
### Description
A collection of mappers that convert RDF/JS terms to JavaScript constructs.
### Functions
- **instance**: Maps to an instance representation.
- **is**: Checks for term type compatibility.
- **list**: Converts RDF lists to JavaScript arrays.
- **term**: General purpose mapper for RDF/JS terms.
```
--------------------------------
### Define a custom TermWrapper class
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Extend TermWrapper to create models with accessors and mutators that interact with underlying RDF data.
```typescript
class SomeClass extends TermWrapper {
get someProperty(): string {
return RequiredFrom.subjectPredicate(this, "http://example.com/someProperty", LiteralAs.string)
}
set someProperty(value: string) {
RequiredAs.object(this, "http://example.com/someProperty", value, LiteralFrom.string)
}
}
```
--------------------------------
### ILangString Interface
Source: https://rdf.js.org/wrapper/interfaces/ILangString.html
Defines the structure for a language-tagged string, including its string value, language tag, and text direction.
```APIDOC
## Interface ILangString
### Description
Represents a language-tagged string.
### Properties
- **direction** (string) - Optional - Specifies the text direction ('ltr' or 'rtl'). Can also be null.
- **lang** (string) - Required - The language tag (e.g., 'en', 'fr').
- **string** (string) - Required - The actual string value.
```
--------------------------------
### Create Literal from Current Date using Factory
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Use the factory to create a literal term representing the current date and time in ISO format with the xsd:dateTime datatype.
```typescript
class Calendar extends TermWrapper {
get currentDate(): Literal {
const date = new Date().toISOString()
const xsdDateTime = this.factory.namedNode("http://www.w3.org/2001/XMLSchema#dateTime")
return this.factory.literal(date, xsdDateTime)
}
}
```
--------------------------------
### Use Inline Lambda Mapping
Source: https://rdf.js.org/wrapper/interfaces/ITermAsValueMapping.html
Use this for custom term-to-value conversions directly within your code. The lambda receives the term and should return the desired value.
```typescript
class Person extends TermWrapper {
get age(): number {
return RequiredFrom.subjectPredicate(this. "age", term => Number(term.value)) // 2nd param is the mapping
}
}
```
--------------------------------
### Function url
Source: https://rdf.js.org/wrapper/functions/NamedNodeAs.url.html
Maps a named node to a URL. Handles potential discrepancies between RDF IRI rules and JavaScript URL parsing.
```APIDOC
## Function url
### Description
Maps a named node to a URL.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Parameters
- **term** (TermWrapper) - Required - The RDF term to convert.
### Returns
- **URL** - A URL that represents the IRI of the named node.
### Remarks
Lexical values of named nodes can be illegal URLs because the rules for handling IRIs in RDF frameworks that implement RDF/JS can differ from the rules for handling URLs in JavaScript engines.
### Example: Convert a named node to a URL
The RDF
```
BASE
.
```
can be represented by the mapping
```typescript
class Class extends TermWrapper {
public get property(): URL {
return RequiredFrom.subjectPredicate(this, "http://example.com/p", NamedNodeAs.url)
}
}
```
which returns the value `http://example.com/o`.
### Throws
- **ReferenceError** - If the term is `undefined` or `null`.
- **TypeError** - If the term is not a TermWrapper.
- **TermTypeError** - If the term is not a NamedNode.
- **TypeError** - If the value of the term cannot be parsed to a valid URL.
```
--------------------------------
### LiteralFrom Namespace Functions
Source: https://rdf.js.org/wrapper/modules/LiteralFrom.html
This section details the functions available within the LiteralFrom namespace for creating RDF/JS literals from JavaScript primitives.
```APIDOC
## LiteralFrom Namespace
A collection of mappers that create RDF/JS literals from JavaScript primitives.
### Functions
- **anyUriString**
- **anyUriUrl**
- **base64**
- **boolean**
- **datatypeTuple**
- **date**
- **dateTime**
- **double**
- **hex**
- **langString**
- **langTuple**
- **string**
```
--------------------------------
### Function hex
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.hex.html
Converts a Uint8Array to an RDF Term using the provided DataFactory.
```APIDOC
## Function hex
### Description
Converts a Uint8Array to an RDF Term.
### Parameters
#### Path Parameters
- None
#### Query Parameters
- None
#### Request Body
- None
### Request Example
```json
{
"example": "No request body for this function"
}
```
### Response
#### Success Response (200)
- **Term** (Term) - The RDF Term representation of the input Uint8Array.
#### Response Example
```json
{
"example": "RDF Term object"
}
```
```
--------------------------------
### languageDictionary Function
Source: https://rdf.js.org/wrapper/functions/Mapping.languageDictionary.html
The languageDictionary function allows for the creation of a Map from RDF terms, using specified mappings for keys and values.
```APIDOC
## Function languageDictionary
### Description
Creates a Map from RDF terms using provided key and value mapping functions.
### Method
N/A (Function Signature)
### Endpoint
N/A (Internal Function)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Type Parameters
* **TKey**: The type of the keys in the resulting Map.
* **TValue**: The type of the values in the resulting Map.
### Parameters
* **anchor** (TermWrapper) - Required - The anchor term to start the mapping from.
* **p** (string) - Required - A property string used in the mapping process.
* **termAs**: ITermAsValueMapping<[TKey, TValue]> - Required - A mapping function to convert RDF terms into key-value pairs for the Map.
* **termFrom**: ITermFromValueMapping<[TKey, TValue]> - Required - A mapping function to convert values back into RDF terms (used internally).
### Returns
* **Map** - A Map where keys and values are derived from RDF terms based on the provided mappings.
```
--------------------------------
### Instantiate TermTypeError
Source: https://rdf.js.org/wrapper/classes/TermTypeError.html
Demonstrates how to create a new instance of TermTypeError. This constructor is used when an RDF term's type does not match the expected type.
```typescript
new TermTypeError(term, termType, cause?)
```
--------------------------------
### Function datatypeTuple
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.datatypeTuple.html
Creates a Term from a datatype tuple and a factory.
```APIDOC
## Function datatypeTuple
### Description
Creates a Term from a datatype tuple and a factory.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
- **Term** (Term) - The created Term object.
#### Response Example
N/A
```
--------------------------------
### anyUriUrl Function
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.anyUriUrl.html
The anyUriUrl function creates an RDF Term representing a URI.
```APIDOC
## Function anyUriUrl
### Description
Creates an RDF Term representing a URI.
### Parameters
#### Path Parameters
- **value** (URL) - Required - The URL value for the URI.
- **factory** (DataFactory) - Required - The DataFactory to use for creating the Term.
### Returns
- **Term** - The created RDF Term representing the URI.
```
--------------------------------
### Function langTuple
Source: https://rdf.js.org/wrapper/functions/LiteralAs.langTuple.html
Documentation for the langTuple function which extracts language information from a TermWrapper.
```APIDOC
## langTuple
### Description
Extracts language information from a TermWrapper.
### Parameters
- **term** (TermWrapper) - Required - The term to process.
### Returns
- **[string, string]** - A tuple containing the string representation and the language tag.
```
--------------------------------
### Function url
Source: https://rdf.js.org/wrapper/functions/NamedNodeFrom.url.html
The 'url' function creates an RDF Term from a URL value using a provided DataFactory.
```APIDOC
## Function url
### Description
Creates an RDF Term from a URL value.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
- **Term** (object) - The RDF Term created from the URL.
#### Response Example
```json
{
"term": ""
}
```
### Function Signature
`url(value: URL, factory: DataFactory): Term`
### Parameters
- **value** (URL) - The URL to convert into an RDF Term.
- **factory** (DataFactory) - The DataFactory instance to use for creating the Term.
### Returns
- **Term** - An RDF Term representing the provided URL.
```
--------------------------------
### base64 Function
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.base64.html
Encodes a Uint8Array into a base64 encoded RDF Term using a provided DataFactory.
```APIDOC
## Function base64
### Description
Encodes a Uint8Array into a base64 encoded RDF Term.
### Method
Function Call
### Parameters
#### Path Parameters
- **value** (Uint8Array) - Required - The byte array to encode.
- **factory** (DataFactory) - Required - The DataFactory instance to use for creating the Term.
### Returns
- **Term** - The base64 encoded RDF Term.
```
--------------------------------
### anyUriString Function
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.anyUriString.html
The anyUriString function creates an RDF Term representing a URI string.
```APIDOC
## Function anyUriString
### Description
Creates an RDF Term representing a URI string.
### Method
N/A (This is a function, not an HTTP endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
- **Term** (object) - An RDF Term representing the URI string.
#### Response Example
N/A
### Function Signature
`anyUriString(value: string, factory: DataFactory): Term`
### Parameters
- **value** (string) - The string value of the URI.
- **factory** (DataFactory) - The RDFJS DataFactory instance to use for creating the Term.
### Returns
- **Term** (object) - The created RDF Term.
```
--------------------------------
### LiteralAs Namespace Functions
Source: https://rdf.js.org/wrapper/modules/LiteralAs.html
This section details the various functions available within the LiteralAs namespace for converting RDF/JS literals to JavaScript primitives.
```APIDOC
## Namespace LiteralAs
A collection of mappers that convert RDF/JS literals to JavaScript primitives.
### Functions
- **bigint**
- **boolean**
- **datatypeTuple**
- **date**
- **langString**
- **langTuple**
- **number**
- **string**
- **symbol**
- **uInt8Array**
- **url**
```
--------------------------------
### Namespace NamedNodeFrom
Source: https://rdf.js.org/wrapper/modules/NamedNodeFrom.html
The NamedNodeFrom namespace contains functions to create RDF/JS NamedNodes from JavaScript primitives like strings and URLs.
```APIDOC
## Namespace NamedNodeFrom
### Description
A collection of mappers that create RDF/JS named nodes from JavaScript primitives.
### Functions
- **string**: Creates a NamedNode from a string.
- **url**: Creates a NamedNode from a URL.
### See Also
- [NamedNode](link-to-namednode-docs)
- [IRIs in RDF 1.1 Concepts and Abstract Syntax](link-to-rdf-concepts)
```
--------------------------------
### Properties: TermTypeError
Source: https://rdf.js.org/wrapper/classes/TermTypeError.html
Details the properties available on the TermTypeError instance.
```APIDOC
## Properties
- **cause** (unknown) - Optional - The underlying cause of the error.
- **message** (string) - The error message.
- **name** (string) - The name of the error.
- **stack** (string) - Optional - The stack trace.
- **term** (Term) - Readonly - The term associated with this error.
- **termType** ("NamedNode" | "BlankNode" | "Literal" | "Variable" | "DefaultGraph" | "Quad") - Readonly - The expected term type that was not met.
```
--------------------------------
### Constructor: new TermTypeError
Source: https://rdf.js.org/wrapper/classes/TermTypeError.html
Creates a new instance of TermTypeError when an RDF term type expectation is not met.
```APIDOC
## Constructor: new TermTypeError
### Description
Creates a new instance of TermTypeError. This error is thrown when the type of a term is unexpected in the context of RDF processing.
### Parameters
- **term** (Term) - Required - The term associated with this error.
- **termType** ("NamedNode" | "BlankNode" | "Literal" | "Variable" | "DefaultGraph" | "Quad") - Required - The expected term type.
- **cause** (any) - Optional - The specific original cause of the error.
### Returns
- **TermTypeError** - A new instance of the error class.
```
--------------------------------
### Match graph patterns with TermWrapper
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Use a TermWrapper instance to match statements within an RDF dataset.
```typescript
let instance: TermWrapper
let dataset: DatasetCore
// Our instance used as subject when matching statements in a dataset
dataset.match(instance as Term)
```
--------------------------------
### Namespace NamedNodeAs
Source: https://rdf.js.org/wrapper/modules/NamedNodeAs.html
A collection of mappers that convert RDF/JS named nodes to JavaScript primitives.
```APIDOC
## Namespace NamedNodeAs
### Description
A collection of mappers that convert RDF/JS named nodes to JavaScript primitives.
### See
- NamedNode
- IRIs in RDF 1.1 Concepts and Abstract Syntax
## Functions
### string
Converts an RDF/JS named node to a JavaScript string.
### url
Converts an RDF/JS named node to a JavaScript URL object.
```
--------------------------------
### WrapperError Class
Source: https://rdf.js.org/wrapper/classes/WrapperError.html
Documentation for the base WrapperError class used in the rdf-js-wrapper library.
```APIDOC
## Class WrapperError
Base class of all errors thrown by this library.
### Hierarchy
* Error
* WrapperError
* TermError
### Constructors
#### constructor
* `new WrapperError(message?: string, cause?: any): WrapperError`
Creates a new instance of WrapperError.
##### Parameters
- `Optional` **message** (string) - A human-readable description of the error.
- `Optional` **cause** (any) - The specific original cause of the error.
##### Returns
- **WrapperError** - A new instance of WrapperError.
### Properties
#### `Optional` cause
- **cause** (unknown) - The original cause of the error.
#### message
- **message** (string) - A human-readable description of the error.
#### name
- **name** (string) - The name of the error.
#### `Optional` stack
- **stack** (string) - The stack trace of the error.
```
--------------------------------
### RDF JS Wrapper - object Function
Source: https://rdf.js.org/wrapper/functions/RequiredAs.object.html
The object function is used to create RDF terms with specific properties.
```APIDOC
## Function object
### Description
Creates an RDF term object.
### Method
N/A (This is a function definition, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A (This function returns a value, not a response)
#### Response Example
N/A
## Type Parameters
* T
## Parameters
* **anchor**: TermWrapper - The anchor term.
* **p**: string - The property.
* **value**: T - The value of the term.
* **termFrom**: ITermFromValueMapping - A mapping function to convert the value to an RDF term.
## Returns
void (This function modifies or creates an object, it does not return a value directly in the context of a typical API response.)
```
--------------------------------
### Use TermWrapper in quad creation
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Pass a TermWrapper instance as a subject when creating new quads via a DataFactory.
```typescript
let instance: TermWrapper
let factory: DataFactory
const predicate = factory.namedNode("http://example.com/p")
const object = factory.literal("o")
// Our instance used as subject when creating a quad
factory.quad(instance as Quad_Subject, predicate, object)
```
--------------------------------
### Function langString
Source: https://rdf.js.org/wrapper/functions/LiteralAs.langString.html
The langString function creates a language-tagged string from a TermWrapper.
```APIDOC
## Function langString
### Description
Creates a language-tagged string (ILangString) from a given TermWrapper.
### Method
N/A (This is a function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
### Parameters
- **term** (TermWrapper) - Required - The TermWrapper to convert into a language-tagged string.
### Returns
- **ILangString** - The resulting language-tagged string.
```
--------------------------------
### Convert Hexadecimal RDF Literal to Uint8Array
Source: https://rdf.js.org/wrapper/functions/LiteralAs.uInt8Array.html
Demonstrates mapping an xsd:hexBinary literal to a Uint8Array using a TermWrapper class.
```text
"30313233343536373839"^^ .
```
```typescript
class Class extends TermWrapper {
public get property(): Uint8Array {
return RequiredFrom.subjectPredicate(this, "p", LiteralAs.uInt8Array)
}
}
```
--------------------------------
### Function term
Source: https://rdf.js.org/wrapper/functions/TermAs.term.html
Documentation for the term function used to unwrap TermWrapper objects.
```APIDOC
## Function term
### Description
Converts a TermWrapper object back into its original RDF/JS Term representation.
### Parameters
- **term** (TermWrapper) - Required - The wrapped term to be converted.
### Returns
- **Term** - The unwrapped RDF/JS Term object.
```
--------------------------------
### List Function
Source: https://rdf.js.org/wrapper/functions/TermAs.list.html
The 'list' function is used to retrieve a list of terms associated with a subject and predicate, with custom mapping for input and output terms.
```APIDOC
## list(subject: TermWrapper, predicate: string, termAs: ITermAsValueMapping, termFrom: ITermFromValueMapping): ITermAsValueMapping
### Description
Retrieves a list of terms associated with a subject and predicate, applying custom mapping functions for term conversion.
### Method
N/A (This is a function signature, not an HTTP endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A (This is a function signature, not an HTTP endpoint)
#### Response Example
N/A
### Type Parameters
* T - The type of the values to be mapped.
### Parameters
* **subject**: TermWrapper - The subject term to query.
* **predicate**: string - The predicate to query.
* **termAs**: ITermAsValueMapping - A mapping function to convert RDF terms to type T.
* **termFrom**: ITermFromValueMapping - A mapping function to convert type T back to RDF terms.
### Returns
ITermAsValueMapping - A mapping object containing the list of terms converted to type T.
```
--------------------------------
### URL Function
Source: https://rdf.js.org/wrapper/functions/LiteralAs.url.html
The 'url' function converts a TermWrapper to a URL.
```APIDOC
## Function url
### Description
Converts a TermWrapper to a URL.
### Method
N/A (This is a function, not an HTTP endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
### Function Signature
`url(term: TermWrapper): URL`
### Parameters
- **term** (TermWrapper) - The TermWrapper to convert.
### Returns
- **URL** - The resulting URL.
```
--------------------------------
### Function dateTime
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.dateTime.html
Converts a JavaScript Date object into an RDF Term using the specified DataFactory.
```APIDOC
## dateTime
### Description
Converts a JavaScript Date object into an RDF Term.
### Parameters
- **value** (Date) - Required - The JavaScript Date object to convert.
- **factory** (DataFactory) - Required - The DataFactory instance used to create the term.
### Returns
- **Term** - The resulting RDF term representing the date.
```
--------------------------------
### Function date
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.date.html
Converts a JavaScript Date object into an RDF Term using the provided DataFactory.
```APIDOC
## Function date
### Description
Converts a JavaScript Date object into an RDF Term.
### Parameters
- **value** (Date) - Required - The JavaScript Date object to convert.
- **factory** (DataFactory) - Required - The DataFactory instance used to create the term.
### Returns
- **Term** - The resulting RDF term representing the date.
```
--------------------------------
### Use Built-in Mapping - LiteralAs.number
Source: https://rdf.js.org/wrapper/interfaces/ITermAsValueMapping.html
Use this when you need to convert an RDF term to a number using a pre-defined mapping. Ensure the 'LiteralAs' namespace is accessible.
```typescript
class Person extends TermWrapper {
get age(): number {
return RequiredFrom.subjectPredicate(this. "age", LiteralAs.number) // 2nd param is the mapping
}
}
```
--------------------------------
### RDF.js Wrapper - Boolean Function
Source: https://rdf.js.org/wrapper/functions/LiteralAs.boolean.html
Provides information on how to use the `boolean` function from the @rdfjs/wrapper package to check if an RDF term is a boolean literal.
```APIDOC
## Function boolean
### Description
Checks if the given RDF term is a boolean literal.
### Method
N/A (This is a utility function, not an API endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
- **boolean** (boolean) - Returns `true` if the term is a boolean literal, `false` otherwise.
#### Response Example
N/A
```
--------------------------------
### RDF/JS Term Properties
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Standard properties and methods for accessing RDF/JS term data.
```APIDOC
## Term Properties
### Properties
- **datatype** (NamedNode): Returns the datatype of a literal.
- **direction** ("" | "ltr" | "rtl" | null | undefined): Returns the base direction of a literal.
- **graph** (Term): Returns the graph of a quad.
- **language** (string): Returns the language tag of a literal.
- **object** (Term): Returns the object of a quad.
- **predicate** (Term): Returns the predicate of a quad.
- **subject** (Term): Returns the subject of a quad.
- **termType** (string): Returns the type of the term.
- **value** (string): Returns the string value of the term.
### Methods
- **equals(other: Term | null | undefined)**: Returns boolean indicating if the term equals the provided term.
```
--------------------------------
### Function: langTuple
Source: https://rdf.js.org/wrapper/functions/LiteralFrom.langTuple.html
The langTuple function creates a language-tagged RDF term. It accepts an array of strings for the language tag and a DataFactory to create the term.
```APIDOC
## Function: langTuple
### Description
Creates a language-tagged RDF term.
### Parameters
#### Path Parameters
* `__namedParameters` (Array) - Required - An array of strings representing the language tag (e.g., ['en', 'US']).
* `factory` (DataFactory) - Required - The DataFactory instance to use for term creation.
### Returns
* Term - The created language-tagged RDF term.
```
--------------------------------
### bigint(term: TermWrapper)
Source: https://rdf.js.org/wrapper/functions/LiteralAs.bigint.html
Converts an RDF term wrapper into a JavaScript bigint.
```APIDOC
## bigint(term: TermWrapper)
### Description
Converts an RDF term wrapper into a JavaScript bigint.
### Parameters
#### Path Parameters
- **term** (TermWrapper) - Required - The RDF term wrapper to convert.
### Returns
- **bigint** - The resulting bigint value.
```
--------------------------------
### Function date
Source: https://rdf.js.org/wrapper/functions/LiteralAs.date.html
The date function converts a TermWrapper into a native JavaScript Date object.
```APIDOC
## date(term: TermWrapper)
### Description
Converts an RDF term wrapped in a TermWrapper into a JavaScript Date object.
### Parameters
- **term** (TermWrapper) - Required - The term to be converted.
### Returns
- **Date** - The resulting JavaScript Date object.
```
--------------------------------
### ITermWrapperConstructor Type Alias
Source: https://rdf.js.org/wrapper/types/ITermWrapperConstructor.html
Defines the constructor signature for term mapping classes that extend TermWrapper. These classes are used to implement navigation properties on dataset and term wrappers.
```APIDOC
## Type Alias ITermWrapperConstructor
### Description
Represents the constructor signature of term mapping classes that extend TermWrapper. Used by this library where constructors of mappers are accepted for implementing navigation properties that represent graph patterns on dataset and term wrappers.
### Type Parameters
* T - The type of the mapping class whose instance is created.
### Type Declaration
* `new (term: Term, dataset: DatasetCore, factory: DataFactory): T`
#### Parameters
* **term** (Term) - The underlying term being wrapped.
* **dataset** (DatasetCore) - The dataset containing the wrapped term.
* **factory** (DataFactory) - The data factory used for creating new terms.
#### Returns
T - An instance of the mapping class created when invoking the constructor.
### Remarks
Mapping classes do not need to define a constructor that matches this signature, because the base class has a publicly accessible, matching constructor.
### Example: Projecting from a dataset to a mapping class
```javascript
class Person extends TermWrapper {
get name() {
return RequiredFrom.subjectPredicate(this, "name", LiteralAs.string)
}
}
class People extends DatasetWrapper {
[Symbol.iterator]() {
return this.instancesOf("Person", Person) // 2nd param is an ITermWrapperConstructor
}
}
```
```ttl
[ a ; "Alice" ; ] .
[ a ; "Bob" ; ] .
```
```javascript
for(const person of new People(dataset, factory)) {
console.log(person.name)
}
```
Output:
```
Alice
Bob
```
### Example: Projecting from one mapping class to another
```javascript
class Book extends TermWrapper {
get author() {
return RequiredFrom.subjectPredicate(this, "author", TermAs.instance(Person)) // Person is an ITermWrapperConstructor
}
}
class Person extends TermWrapper {
get name() {
return RequiredFrom.subjectPredicate(this, "name", LiteralAs.string)
}
}
```
```ttl
[ "Alice" ; ] .
```
```javascript
const dataset =
const book = new Book("book", dataset, factory)
console.log(book.author.name)
```
Output:
```
Alice
```
### See
* DatasetWrapper.instancesOf
* DatasetWrapper.matchObjectsOf
* DatasetWrapper.matchSubjectsOf
* DatasetWrapper.objectsOf
* TermAs.instance
```
--------------------------------
### Function is
Source: https://rdf.js.org/wrapper/functions/TermAs.is.html
Checks if a given term is an instance of a specific TermWrapper type.
```APIDOC
## Function is
### Description
Checks if a given term is an instance of a specific TermWrapper type.
### Method
N/A (This is a utility function, not an HTTP endpoint)
### Endpoint
N/A
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
N/A
### Request Example
N/A
### Response
#### Success Response (200)
N/A
#### Response Example
N/A
### Type Parameters
* T extends TermWrapper
### Parameters
* **term**: T - The term to check.
### Returns
T - The original term if it matches the type T.
```
--------------------------------
### subjectPredicate Function
Source: https://rdf.js.org/wrapper/modules/SetFrom.html
Exposes RDF/JS graph patterns as a mutable JavaScript set based on subject and predicate.
```APIDOC
## subjectPredicate
### Description
A mapper function that exposes RDF/JS graph patterns as a mutable JavaScript set, specifically targeting subject and predicate relationships.
### Namespace
@rdfjs/wrapper/SetFrom
```
--------------------------------
### Modify Book Author using Dataset
Source: https://rdf.js.org/wrapper/classes/TermWrapper.html
Use this method to update the author of a book directly within the dataset. This operates at a low level; consider using higher-level abstractions for simpler interactions.
```typescript
class Book extends TermWrapper {
set author(value: string) {
const subject = this as Quad_Subject
const predicate = this.factory.namedNode("http://example.com/author")
const object = this.factory.literal(value)
const oldAuthors = this.factory.quad(subject, predicate)
const newAuthor = this.factory.quad(subject, predicate, object)
this.dataset.delete(oldAuthors)
this.dataset.add(newAuthor)
}
}
```
--------------------------------
### Function symbol
Source: https://rdf.js.org/wrapper/functions/LiteralAs.symbol.html
Retrieves the symbol associated with a TermWrapper.
```APIDOC
## symbol
### Description
Returns the symbol associated with the provided TermWrapper instance.
### Parameters
- **term** (TermWrapper) - Required - The term wrapper instance to process.
### Returns
- **symbol** - The symbol associated with the term.
```