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

@shexjs/node

v1.0.0-alpha.28

Published

Shape Expressions packages for node.

Downloads

259

Readme

NPM Version ShapeExpressions Gitter chat https://gitter.im/shapeExpressions/Lobby DOI

@shexjs/node

Introduction

This module extends @shexjs/loader with file: access. This modules is probably not appropriate for use in a browser.

Installation

Node.js + npm

npm install @shexjs/node
const ShExIo = require('@shexjs/node');

Used with @shexjs suite:

core functions

parse and write ShExC

exectuables

  • @shexjs/cli - command line interface for validation and format conversion
  • @shexjs/webapp - webpacks and the shex-simple interface

validation

extensions

ShapePath

Methods

load(schema, data, schemaOptions = {}, dataOptions = {})

load shex and json files into a single ShEx schema and turtle into a graph.

@shexjs/node extends the @shexjs/loader load method to allow the source to be a file path.

SOURCE may be

  • file path or URL - where to load item.
  • object: {text: string, url: string} - text and URL of already-loaded resource.
  • (schema) ShExJ object
  • (data) RdfJs data store

parameters:

  • schema - { shexc: [ShExC SOURCE], json: [JSON SOURCE] }
  • data - { turtle: [Turtle SOURCE], jsonld: [JSON-LD SOURCE] }
  • schemaOptions
  • dataOptions

returns: {Promise<{schema: any, dataMeta: [], data: (|null), schemaMeta: *[]}>}

example (same as @shexjs/loader example, but using file paths):

// Initialize @shexjs/loader with implementations of APIs.
const ShExLoader = require("@shexjs/node")({
  rdfjs: require('n3'),         // use N3 as an RdfJs implementation
  fetch: require('node-fetch'), // fetch implementation
  jsonld: require('jsonld')     // JSON-LD (if you need it)
});

// Schemas from URL and filepath:
const schemaFromUrl =
      "https://shex.io/webapps/packages/shex-cli/test/cli/1dotOr2dot.shex";
const schemaFromFile =
      "../shex-cli/test/cli/1dotOr2dot.shex";

// Data graphs from URL, text and graph API:
const graphFromUrl =
      "https://shex.io/webapps/packages/shex-cli/test/cli/p1.ttl";
const graphFromFile =
      "../shex-cli/test/cli/p2p3.ttl";

// ShExLoader.load returns a promise to load and merge schema and data.
const schemaAndDataP = ShExLoader.load(
  { shexc: [ schemaFromUrl, schemaFromFile ] },
  { turtle: [ graphFromUrl, graphFromFile ] }
);

// Print out results to show off returned structure.
schemaAndDataP.then(({schema, schemaMeta, data, dataMeta}) => {
  console.log('schemaMeta:\n' + JSON.stringify(schemaMeta, null, 2));
  console.log('shapes:\n' + schema.shapes.map(s => '  ' + s.id).join('\n'));
  console.log('dataMeta:\n' + JSON.stringify(dataMeta, null, 2));
  console.log('triples:\n' + data.getQuads().map(
    q => '  ' +
      (['subject', 'predicate', 'object'])
      .map(t => q[t].value).join(' ')).join('\n'));
});

output:

schemaMeta:
[ { "mediaType": "text/shex", "url": "file:…cli/1dotOr2dot.shex",
    "base": "file:…cli/1dotOr2dot.shex", "prefixes": {} },
  { "mediaType": "text/shex", "url": "https:…cli/1dotOr2dot.shex",
    "base": "https:…cli/1dotOr2dot.shex", "prefixes": {} }
]
shapes:
  http://a.example/S1
dataMeta:
[ { "mediaType": "text/turtle", "url": "file:…cli/p2p3.ttl",
    "base": "file:…cli/p2p3.ttl", "prefixes": {
      "": "http://a.example/",
      "xsd": "http://www.w3.org/2001/XMLSchema#" } },
  { "mediaType": "text/turtle", "url": "https:…cli/p1.ttl",
    "base": "https:…cli/p1.ttl", "prefixes": {
      "": "http://a.example/"
    } }
]
triples:
  file:…cli/x http://a.example/p2 p2-0
  file:…cli/x http://a.example/p3 p3-0
  https:…cli/x http://a.example/p1 p1-0

See @shexjs/loader load method for more description.

loadExtensions function(globs[])

prototype of loadExtensions. does nothing

GET function(url, mediaType)

return promise of {contents, url}

Examples

Use @shexjs/node directly:

const ShExIo = require("@shexjs/node")({
  rdfjs: N3,
  fetch: require('node-fetch')
});

Extend @shexjs/node with jsonld and a non-standard jsonld document loader:

const ShExIo = require("@shexjs/node")({
  rdfjs: N3,
  fetch: require('node-fetch'),
  jsonld: require('jsonld'),
  jsonLdOptions: { documentLoader }
});

async function documentLoader (url, options) {
  # see https://github.com/digitalbazaar/jsonld.js#custom-document-loader
}

Lerna Monorepo

This repo uses lerna to manage multiple NPM packages. These packages are located in packages/*: