Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@rdfjs-elements/formats-pretty
Advanced tools
Readme
Common RDF/JS parsers and serializers, the latter returning a nicely formatted output.
For basic usage see @rdfjs/formats-common
Format | Pretty or not | Implementation |
---|---|---|
application/ld+json | 😀 | @rdfjs/serializer-jsonld-ext |
application/trig | 🤩 | @graphy/content.trig.writer |
text/n3 | 🤩 | @graphy/content.ttl.writer |
text/turtle | 🤩 | @graphy/content.ttl.writer |
application/n-triples | 😶 | @rdfjs/serializer-ntriples |
application/n-quads | 😶 | @rdfjs/serializer-ntriples |
application/rdf+xml | 😶 | @graphy/content.xml.scribe |
Individual serializer skins can also be created by importing from @rdfjs-elements/formats-pretty/serializers
. This
allows for initializing a sink preloaded with a given set of prefixes.
import prefixes from '@zazuko/prefixes'
import { TurtleSerializer } from '@rdfjs-elements/formats-pretty'
const { schema, dcterms, foaf } = prefixes
const sink = new TurtleSerializer({
prefixes: { schema, dcterms, foaf, ex: 'http://example/org/' }
})
This sink can then be used to produce pretty-printed RDF
import rdf from '@rdfjs/data-model'
import { Readable } from 'readable-stream'
import getStream from 'get-stream'
// Example data
const data = [
rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Alice')),
rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://xmlns.com/foaf/0.1/knows'), rdf.namedNode('http://example/org/o1')),
rdf.quad(rdf.namedNode('http://example/org/o1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Bob'))
]
const stream = await sink.import(Readable.from(data))
console.log(await getStream(stream))
// Outputs:
// @prefix schema: <http://schema.org/> .
// @prefix dcterms: <http://purl.org/dc/terms/> .
// @prefix foaf: <http://xmlns.com/foaf/0.1/> .
// @prefix ex: <http://example/org/> .
//
// ex:s1 schema:name "Alice" ;
// foaf:knows ex:o1 .
//
// ex:o1 schema:name "Bob" .
To get an output in n-triples, n-quads or n3 format the sink map interface can be used where media type must be specified:
import rdf from '@rdfjs/data-model'
import prefixes from '@zazuko/prefixes'
import formats from '@rdfjs-elements/formats-pretty'
import { Readable } from 'readable-stream'
import getStream from 'get-stream'
// Example data
const data = [
rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Alice')),
rdf.quad(rdf.namedNode('http://example/org/s1'), rdf.namedNode('http://xmlns.com/foaf/0.1/knows'), rdf.namedNode('http://example/org/o1')),
rdf.quad(rdf.namedNode('http://example/org/o1'), rdf.namedNode('http://schema.org/name'), rdf.literal('Bob'))
]
const { schema, dcterms, foaf } = prefixes
const stream = formats.serialisers.import('application/n-triples', Readable.from(data), { schema, dcterms, foaf, ex:'http://example/org/' })
console.log(await getStream(stream))
Format | Implementation |
---|---|
application/ld+json | @rdfjs/parser-jsonld |
application/trig | @rdfjs/parser-n3 |
text/n3 | @rdfjs/parser-n3 |
text/turtle | @rdfjs/parser-n3 |
application/n-triples | @rdfjs/parser-n3 |
application/n-quads | @rdfjs/parser-n3 |
application/rdf+xml | rdfxml-streaming-parser |
FAQs
RDF/JS Sink Maps with serializers configured for pretty printing
The npm package @rdfjs-elements/formats-pretty receives a total of 980 weekly downloads. As such, @rdfjs-elements/formats-pretty popularity was classified as not popular.
We found that @rdfjs-elements/formats-pretty demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.