Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

rdfprefix

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rdfprefix

RDF Prefix helper to expand and compact iri (compatible with json-ld context)

latest
Source
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

rdfprefix

js-standard-style travis npm downloads

RDF Prefix helper to expand and compact iri (compatible with json-ld context)

Features

  • Expand prefixed iri to iri
  • Compact iri to prefixed iri
  • Support JSON-LD context as prefix definition

Installation

npm install --save rdfprefix

Usage

var rdfprefix = require('rdfprefix')

// Basic initialization
var prefixes = rdfprefix()

// Initialize with prefixes
var prefixes = rdfprefix({schema: 'http://schema.org'})

// Initialize with an array of prefixes
var prefixes = rdfprefix([
  {owl: 'http://www.w3.org/2002/07/owl#'},
  {schema: 'http://schema.org/'}
])

// Supports Json-ld @context
var prefixes = rdfprefix({
  '@vocab': 'http://purl.org/dc/terms/',
  'schema': 'http://schema.org/',
  'displayName': 'schema:name',
  'alias': {
    '@id': 'schema:alternateName',
    '@container': '@set'
  },
  'schema:sameAs': {
    '@type': 'schema:URL',
    '@container': '@set'
  }
})

// Add prefixes...
prefixes('owl', 'http://www.w3.org/2002/07/owl#')
prefixes({
  'cc': 'http://creativecommons.org/ns#',
  'rdfs': 'http://www.w3.org/2000/01/rdf-schema#',
  'Class': 'rdfs:Class'
})

// Use prefixes
var schema = prefixes('schema')
schema('name') // -> 'http://schema.org/name'

// Expand prefixed iri
prefixes.expand('schema:name') // -> 'http://schema.org/name'
prefixes.expand('abstract') // -> 'http://purl.org/dc/terms/abstract' (see '@vocab')
prefixes.expand('http://www.exemple.org/play') // -> 'http://www.exemple.org/play'
prefixes.expand('undefinedprefix:foo') // -> throw Error()
prefixes.expand('undefinedprefix:foo', true) // -> 'undefinedprefix:foo' (tolerant = true)

// Compact iri
prefix.compact('http://schema.org/name') // -> 'schema:name'
prefix.compact('http://purl.org/dc/terms/abstract') // -> 'abstract' (see '@vocab')
prefix.compact('http://www.exemple.org/play') // -> 'http://www.exemple.org/play'

// Get a serializable copy of prefixes
prefix.toJSON() // -> { schema: 'http://schema.org/', ... } (without '@vocab')

// Like toJSON but with the '@vocab' prefix if any
prefix.toContext() // -> { '@vocab': 'http://purl.org/dc/terms/abstract', schema: ... }

Test coverage

Statements100% ( 76/76 )
Branches100% ( 52/52 )
Functions100% ( 14/14 )
Lines100% ( 76/76 )

Credit & great tools

  • See the fabulous N3 library by @RubenVerborgh
  • The must have jsonld.js library

The MIT License • By Novadiscovery

Keywords

rdf

FAQs

Package last updated on 28 Oct 2015

Did you know?

Socket

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.

Install

Related posts