@rdfjs/namespace
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/rdfjs__namespace package

2.0.1 • Public • Published

@rdfjs/namespace

build status npm version

Named Node builder.

Usage

The package exports a factory to create builders for Named Nodes. The baseIRI given to the factory will be used together with the parameter given to the builder to create Named Nodes.

Factory

The factory must be called with the baseIRI as a string:

const builder = namespace('http://example.org/base-iri#')

An optional factory can be defined:

const builder = namespace('http://example.org/base-iri#', { factory: customFactory })

By default @rdfjs/data-model is used.

Builder

The builder can be called in three different ways:

  • function call: (builder('property'))
  • tagged template string: (builder`property` )
  • property: (builder.property)

Calling the builder using the propery requires Proxy support. At the moment IE11 is the only major platform which doesn't support Proxy.

Example

This example shows how to create a builder and create Named Nodes using the three different ways. The properties of the Named Nodes are written to the console.

import namespace from '@rdfjs/namespace'

const schema = namespace('http://schema.org/')

const hasPart = schema('hasPart')
console.log(hasPart.termType) // NamedNode
console.log(hasPart.value) // http://schema.org/hasPart

const person = schema`Person`
console.log(person.termType) // NamedNode
console.log(person.value) // http://schema.org/Person

const comment = schema.Comment
console.log(comment.termType) // NamedNode
console.log(comment.value) // http://schema.org/Comment

Package Sidebar

Install

npm i @rdfjs/namespace

Weekly Downloads

24,507

Version

2.0.1

License

MIT

Unpacked Size

8.78 kB

Total Files

8

Last publish

Collaborators

  • bergos