npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rdfprefix

v1.0.0

Published

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

Downloads

69

Readme

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

| | | | ------------ | -------------- | | Statements | 100% ( 76/76 ) | | Branches | 100% ( 52/52 ) | | Functions | 100% ( 14/14 ) | | Lines | 100% ( 76/76 ) |

Credit & great tools

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

The MIT License • By Novadiscovery