Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
rdf-string
Advanced tools
Convenience functions for creating and serializing RDF terms and quads
This package contains utility functions to convert between the string-based and RDFJS representations of RDF terms, quads and triples.
If you are looking for a Turtle-based string syntax, have a look at RDF String Turtle
This allows for convenient and compact interaction with RDF terms and quads, as they can be serialized as plain JSON.
This string-based representation is based on the old triple representation of N3.js. Namely, quads are represented as follows:
{
subject: 'http://example.org/cartoons#Tom',
predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
object: 'http://example.org/cartoons#Cat'
graph: 'http://example.org/myGraph'
}
Different terms types in quads are represented as follows:
'http://example.org/cartoons#Tom'
'"Tom"'
, '"Tom"@en-gb'
, '"1"^^http://www.w3.org/2001/XMLSchema#integer'
?
: '?variableName'
The following examples assume the following imports:
import * as RdfDataModel from "rdf-data-model";
import * as RdfString from "rdf-string";
Convert an RDFJS term to the string-based representation.
// Prints http://example.org
console.log(RdfString.termToString(RdfDataModel.namedNode('http://example.org')));
// Prints _:b1
console.log(RdfString.termToString(RdfDataModel.blankNode('b1')));
// Prints "abc"
console.log(RdfString.termToString(RdfDataModel.literal('abc')));
// Prints "abc"@en-us
console.log(RdfString.termToString(RdfDataModel.literal('abc', 'en-us')));
// Prints "abc"^^http://example.org/
console.log(RdfString.termToString(RdfDataModel.literal('abc', namedNode('http://example.org/'))));
// Prints ?v1
console.log(RdfString.termToString(RdfDataModel.variable('v1')));
// Prints empty string
console.log(RdfString.termToString(RdfDataModel.defaultGraph()));
Convert an string-based term to the RDFJS representation.
Optionally, a custom RDFJS DataFactory can be provided as second argument to create terms instead of the built-in DataFactory.
// Outputs a named node
RdfString.stringToTerm('http://example.org');
// Outputs a blank node
RdfString.stringToTerm('_:b1');
// Outputs a literal
RdfString.stringToTerm('"abc"');
// Outputs a literal with a language tag
RdfString.stringToTerm('"abc"@en-us');
// Outputs a literal with a datatype
RdfString.stringToTerm('"abc"^^http://example.org/');
// Outputs a variable
RdfString.stringToTerm('?v1');
// Outputs a default graph
RdfString.stringToTerm('');
Convert an RDFJS quad to a string-based quad.
// Prints { subject: 'http://example.org', predicate: 'http://example.org', object: '"abc"', graph: '' }
console.log(RdfString.quadToStringQuad(RdfDataModel.triple(
namedNode('http://example.org'),
namedNode('http://example.org'),
literal('abc'),
)));
Converts a string-based quad to an RDFJS quad.
Optionally, a custom RDFJS DataFactory can be provided as second argument to create quads and terms instead of the built-in DataFactory.
// Outputs a quad
RdfString.stringQuadToQuad({
subject: 'http://example.org',
predicate: 'http://example.org',
object: '"abc"',
graph: '',
});
This software is written by Ruben Taelman. These utility functions are inspired by the implementation of N3.js.
This code is released under the MIT license.
FAQs
Convenience functions for creating and serializing RDF terms and quads
The npm package rdf-string receives a total of 12,640 weekly downloads. As such, rdf-string popularity was classified as popular.
We found that rdf-string demonstrated a not healthy version release cadence and project activity because the last version was released 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
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.