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

@graviola/json-schema-graph-extract

v0.1.1

Published

<h1 align="center"> SPARQL Query generator: @graviola/json-schema-graph-extract </h1> <p> <img alt="Version" src="https://img.shields.io/badge/version-0.1.1-blue.svg?cacheSeconds=2592000" /> <img src="https://img.shields.io/badge/node-%3E%3D10-blue.sv

Downloads

6

Readme

A library to get JSON documents using JSON-Schema out of a knowledge graph

🏠 Homepage

Prerequisites

  • node >=10

Install

yarn add @graviola/json-schema-graph-extract

Usage

given the following json schema

{
  "$defs": {
    "Address": {
      "type": "object",
      "properties": {
        "addressCountry": {
          "type": "string"
        },
        "addressRegion": {
          "type": "string"
        },
        "postalCode": {
          "type": "string"
        },
        "streetAddress": {
          "type": "string"
        },
      }
    },
    "Person": {
      "title": "Person",
      "description": "A human being",
      "type": "object",
      "properties": {
        "familyName": {
          "type": "string"
        },
        "givenName": {
          "type": "string"
        },
        "address": {
          "$ref": "#/$defs/Address"
        }
      }
    }
  },
  "$schema": "http://json-schema.org/draft-06/schema#",
  "$id": "https://example.com/person.schema.json",
}

and a knowledge graph that contains the following triples:

@prefix : <https://example.com/person.schema.json#> .
@prefix ex: <http://example.com/entities#> .

ex:me a :Person ;
  :familyName "Meneman" ;
  :givenName "Max" ;
  :address ex:address .
    :addressCountry "Germany" ;
    :addressRegion "Berlin" ;
    :postalCode "10967" ;
    :streetAddress "Humboldforum 7821" .

call the extractDocumentFromDataset function with on any dataset:

    const baseIRI = 'http://example.com',
          entityIRI = 'http://example.com/entities#me'
    const data = extractDocumentFromDataset(
      baseIRI, 
      entityIRI, 
      dataset, 
      schema, 
      { 
        omitEmptyArrays: true,
        omitEmptyObjects: true,
        maxRecursionEachRef: 1,
        maxRecursion: 5 
      })

the result data serialized to json will look like this:

{
  "@id": "http://example.com/entities#me",
  "@type": "Person",
  "familyName": "Meneman",
  "givenName": "Max",
  "address": {
    "addressCountry": "Germany",
    "addressRegion": "Berlin",
    "postalCode": "10967",
    "streetAddress": "Humboldforum 7821"
  }
}

if the entry exists within the dataset and the document is valid according to the schema.

In the example the maxRecursionEachRef and maxRecursion options are used to limit the depth of the recursion. It is possible to have a schema that references itself, which would lead to an infinite recursion.

In future versions a more fine grained control over the recursion will be possible.

The omitEmptyArrays and omitEmptyObjects options are used to omit empty arrays and objects from the result.

Author

👤 Sebastian Tilsch

Show your support

Give a ⭐️ if this project helped you!