# @tpluscode/rdf-string

> Simplifies creating of RDF strings using ECMAscript templates

Latest version **1.3.4** (published 2024-09-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install @tpluscode/rdf-string
pnpm add @tpluscode/rdf-string
yarn add @tpluscode/rdf-string
bun add @tpluscode/rdf-string
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.4 |
| Published | 2024-09-23 |
| First published | 2020-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 45.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Tomasz Pluskiewicz |
| Maintainers | tpluscode |
| Keywords | rdf, sparql |

## Links

- npm: https://www.npmjs.com/package/@tpluscode/rdf-string
- Repository: https://github.com/tpluscode/rdf-string
- Homepage: https://github.com/tpluscode/rdf-string#readme
- Issues: https://github.com/tpluscode/rdf-string/issues
- npm.io page: https://npm.io/package/@tpluscode/rdf-string

## Dependencies (6)

- [@rdfjs/types](https://npm.io/package/@rdfjs/types.md) *
- [@rdfjs/term-map](https://npm.io/package/@rdfjs/term-map.md) ^2.0.0
- [@zazuko/prefixes](https://npm.io/package/@zazuko/prefixes.md) >=1
- [@rdfjs/data-model](https://npm.io/package/@rdfjs/data-model.md) ^2.0.0
- [@rdfjs/environment](https://npm.io/package/@rdfjs/environment.md) ^1.0.0
- [@tpluscode/rdf-ns-builders](https://npm.io/package/@tpluscode/rdf-ns-builders.md) >=3

## Recent versions

- 1.3.4 (latest) — 2024-09-23
- 0.2.29 — 2024-09-23
- 1.3.3 — 2024-05-23
- 0.2.28 — 2024-05-23
- 1.3.2 — 2024-05-23
- 1.3.1 — 2024-05-06
- 1.3.0 — 2024-03-28
- 1.2.1 — 2024-03-26
- 1.2.0 — 2024-03-22
- 1.1.3 — 2024-01-22
- 1.1.2 — 2024-01-19
- 1.1.1 — 2024-01-18
- 1.1.0 — 2023-10-11
- 1.0.3 — 2023-05-06
- 1.0.2 — 2023-03-26
- … 39 more at https://npm.io/package/@tpluscode/rdf-string/versions

## README

> # @tpluscode/rdf-string ![Test](https://github.com/tpluscode/rdf-string/workflows/Test/badge.svg) [![codecov](https://codecov.io/gh/tpluscode/rdf-string/branch/master/graph/badge.svg)](https://codecov.io/gh/tpluscode/rdf-string) [![npm version](https://badge.fury.io/js/%40tpluscode%2Frdf-string.svg)](https://badge.fury.io/js/%40tpluscode%2Frdf-string)

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][template-literals].
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

```js
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.

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

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

### turtle

TBD

### n-triples

TBD

[template-literals]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

---
_Source: https://npm.io/package/@tpluscode/rdf-string · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
