Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@tpluscode/rdf-string

tpluscode39.6kMIT1.3.4TypeScript support: included

Simplifies creating of RDF strings using ECMAscript templates

rdf, sparql

readme

@tpluscode/rdf-string Test codecov npm version

Simplifies the construction of RDF strings (turtle, n-triples, SPARQL, etc.) by taking care of correctly serializing values to their string representation and automatically prefixing URIs.

Usage

The heart of the library are EcmaScript template string tag functions. All interpolated values are serialized according to the syntactic rules of the given RDF format.

Formats which support prefixes will automatically abbreviate the URIs and return the prefix declarations according to the specific syntax.

SPARQL

import * as RDF from '@rdfjs/data-model' 
import { prefixes } from '@zazuko/rdf-vocabularies'
import namespace from '@rdfjs/namespace'

import { sparql } from '@zazuko/rdf-string'

const person = RDF.variable('person')
const PersonType = RDF.namedNode('http://example.com/Person')
const schema = namespace(prefixes.schema)
const name = "John"

const query = sparql`SELECT * WHERE {
  ${person} a ${PersonType} .
  ${person} ${schema.name} ${name} .
}`

query.toString()

The last line will return a complete query.

PREFIX schema: <http://schema.org/>

SELECT * WHERE {
  ?person a <http://example.com/Person> .
  ?person schema:name "John" .
}

turtle

TBD

n-triples

TBD

changelog

Changelog

1.3.4

Patch Changes

  • a93d424: Whole number xsd:decimal would have been serialised as an xsd:integer

1.3.3

Patch Changes

  • ff439be: In cases when 1.x and 0.x versions were mixed in a project, building an RDF string would fail trying to access the RDF/JS Environment which is required by the latest versions

1.3.2

Patch Changes

  • 69dce5d: IRIs which contained a slash or hash were not correctly escaped when the would be encoded as prefixed name

1.3.1

Patch Changes

  • 30d5c7f: Explicitly declare return types of tag function to avoid "TS2742: The inferred type of 'X' cannot be named without a reference to '/node_modules/@tpluscode/rdf-string/lib/TemplateResult.js'. This is likely not portable. A type annotation is necessary." errors

1.3.0

Minor Changes

  • 2c4b2ce: Re-export Options types from each syntax module

1.2.1

Patch Changes

  • 4fa006f: This fixes the import of the following modules by explicitly adding the .js extension:

    • @rdfjs/environment/Environment
    • @rdfjs/term-map/Factory

1.2.0

Minor Changes

  • 4f51f6b: Remove dependency on @zazuko/env to improve browser compatibility

1.1.3

Patch Changes

  • 62f331b: Remove usages of rdf-js

1.1.2

Patch Changes

  • 75d1f4b: More strict dependency on @rdfjs/environment

1.1.1

Patch Changes

  • 012b73f: Support @zazuko/env v2

1.1.0

Minor Changes

  • 4135a1f: Use @zazuko/env instead of separate packages
  • 7ecd35d: Add option to turtle and sparql to disable prefixed URIs

1.0.3

Patch Changes

  • 5cc2988: Relax dependency on @zazuko/prefixes

1.0.2

Patch Changes

  • 907f149: Export *Options interfaces to fix errors like TS4053 Return type of public method from exported class has or is using name '*Options' from external module "Y" but cannot be named

1.0.1

Patch Changes

  • 1b627ee: Installing from NPM tried to call patch-package

1.0.0

Major Changes

  • 8b7597c: The package is now only ESM
  • 8b7597c: Use @zazuko/prefixes instead of @zazuko/rdf-vocabularies

0.2.29

Patch Changes

  • 4b241c0: Whole number xsd:decimal would have been serialised as an xsd:integer

0.2.28

Patch Changes

  • 7c6d1da: IRIs which contained a slash or hash were not correctly escaped when the would be encoded as prefixed name

0.2.27

Patch Changes

  • 3cbfa26: Add prefixes argument to turtle and SPARQL option (closes #3)

0.2.26

Patch Changes

  • 0e2d234: Updated @tpluscode/rdf-ns-builders to v2

0.2.25

Patch Changes

  • b0e69ef: Support for interpolating any iterator types

0.2.24

Patch Changes

  • 4628196: Update @tpluscode/rdf-ns-builders and typescript RDF/JS types

0.2.23

Patch Changes

  • 388fdd0: Array: remove recursion from interpolating arrays

0.2.22

Patch Changes

  • b98d78c: Relax dependency on @zazuko/rdf-vocabularies

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

0.2.21 (2020-11-02)

0.2.20 (2020-09-18)

0.2.19 (2020-09-18)

0.2.18 (2020-08-24)

0.2.17 (2020-08-03)

Features

  • sparql: interpolating quads and datasets with patterns (bc0a32f)

0.2.16 (2020-07-01)

0.2.15 (2020-06-11)

0.2.14 (2020-06-08)

0.2.13 (2020-06-07)

0.2.12 (2020-05-21)

0.2.11 (2020-04-18)

Bug Fixes

  • properly escape multiple literals and sepcial chars (eb420cc)

0.2.10 (2020-04-08)

Features

  • reduce arrays by interpolating individual items (3c47ccc)

0.2.9 (2020-04-03)

Features

  • turtle: support base URI (d5eb53c)

0.2.8 (2020-02-27)

Features

  • make it possible to create custom interpolatable objects (24c60b1)

Bug Fixes

  • allow any object to be interpolated value (87184eb)

0.2.7 (2020-02-27)

Features

  • interpolating built-in JS types (85151cc)

0.2.6 (2020-02-27)

Features

  • turtle: compress output by removing subject/predicate repetition (0d2f121)
  • turtle: options to do cheap compression (618ffa0)
  • added ntriples support (62aef77)

0.2.5 (2020-02-26)

Bug Fixes

  • dep: now data model package is missing completely 😖 (8aade7c)

0.2.4 (2020-02-26)

Bug Fixes

  • dep: data model package was not a runtime dependency (7582da1)

0.2.3 (2020-02-26)

Bug Fixes

  • dep: namespace builder package was not a runtime dependency (6196216)

0.2.2 (2020-02-25)

0.2.1 (2020-02-25)

Features

  • turtle: defaultGraph is serialized with option for named (1f087c1)
  • turtle initial version (fc83c08)

Bug Fixes

  • sparql: remove superfluous blank lines added in head (d4b5f0f)

0.2.0 (2020-02-24)

⚠ BREAKING CHANGES

  • renamed parameter of SparqlOptions

Bug Fixes

  • base was not applied to nested templates (7b443e4)

0.1.0 (2020-02-24)

⚠ BREAKING CHANGES

  • plain string will not be wrapped as RDF/JS literal

Bug Fixes

  • it's not possible to interpolate plain string (1fc417a)

0.0.8 (2020-02-23)

0.0.8 (2020-02-23)

0.0.7 (2020-02-23)

Bug Fixes

  • sparql: variables were stringified without question mark (0b05db7)

0.0.6 (2020-02-22)

Features

0.0.5 (2020-02-21)

0.0.4 (2020-02-21)

Bug Fixes

  • type SparqlValue must be generic (32ab34e)

0.0.3 (2020-02-21)

Bug Fixes

0.0.2 (2020-02-21)

0.0.1 (2020-02-21)

Features

  • sparql: first features for SPARQL template string (5d68055)
  • sparql: nested templates and null/undefined (56f5549)
  • sparql: shrink URIs and extract prefixes (5da6aef)