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

@tpluscode/rdf-ns-builders

v4.3.0

Published

Generated RDF/JS namespace builders for common vocabularies

Downloads

77,630

Readme

@tpluscode/rdf-ns-builders

Common RDF vocabularies extracted from @zazuko/vocabularies and wrapped as @rdfjs/namespace builder objects.

Also includes TypeScript declarations of the terms included in the known vocabularies as extracted from the actual RDF source file.

Why?

  1. If you're tired of typing const schema = namespace(prefixes.schema) every so often
  2. If you want to have your IDE "Find usages" of a @rdfjs/namespace-generated term

Installation

npm i -S @tpluscode/rdf-ns-builders

Usage

Simply import a namespace builder by its prefix defined in @zazuko/vocabularies

import { schema } from '@tpluscode/rdf-ns-builders'
import { NamedNode } from '@rdfjs/types'

const schemaPerson: NamedNode = schema.Person

Usage with RDF/JS Environment

You can also add all vocabularies to an environment. Note that this will load everything immediately, even if unused

import { NamedNode } from '@rdfjs/types'
import Environment from '@rdfjs/environment/Environment.js'
import NsBuildersFactory from '@tpluscode/rdf-ns-builders'

const rdf = new Environment([NsBuildersFactory])

const schemaPerson: NamedNode = rdf.ns.schema.Person

Loose builder

The namespace builders exported from the main module allow arbitrary term but in TypeScript, an error will be shown if they do not exist in the vocabulary. Alternatively, loose builders can be imported which will ignore terms from outside the vocabulary.

import { schema } from '@tpluscode/rdf-ns-builders/loose'
import { NamedNode } from '@rdfjs/types'

// will not show error
const schemaPerson: NamedNode = schema.Persona

Roll your own

Given a package with same exports as @zazuko/vocabularies, it is possible to generate a set of namespace builders generated from your own vocabularies.

Install required peer dependencies:

npm i -D ts-node ts-morph clownface @zazuko/vocabularies safe-identifier

Run the following command to generate builders package by providing the source package name and output directory.

npm run rdf-ns-builders generate -p @my/vocabularies -o builders

This will create a directory source, containing typescript modules for all vocabularies, similar to those from src.

Adding your own vocabularies

To extend the interface of env.ns you need to add you own factory which will add additional namespace builders to the environment. TypeScript users will also need to extend the CustomPrefixes interface.

// ./ns.ts
import { NamespaceBuilder } from '@rdfjs/namespace'

type ExampleTerms = 'foo' | 'bar

declare module '@tpluscode/rdf-ns-builders' {
  interface CustomNamespaces {
    ex: NamespaceBuilder<ExampleTerms>
  }
}

export class ExampleNsFactory {
  init(this: Environment<NsBuildersFactory | NamespaceFactory>) {
    this.ns = {
      ...this.ns,
      ex: this.namespace<ExampleTerms>('https://example.com/'),
    }
  }
}

Then, use it to create an extended environment.

// ./env.ts
import { create } from '@zazuko/env'
import { ExampleNsFactory } from './ns.js'

export default create(TalosNsFactory)