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

modelld

v0.11.1

Published

A JavaScript API for selecting and manipulating linked data subgraphs

Downloads

27

Readme

modelld

NPM Version Build Status Coverage Status

A JavaScript API for selecting and manipulating subgraphs of linked data.

This is a work in progress! The API will definitely change.

About

modelld is a library which helps you build apps on top linked data. It provides a higher-level interface for graph manipulation than you'd get using something like rdf-ext or rdflib.js out of the box. It also makes it easy to save graphs back to LDP services even if your models are made up of data from several different URIs.

modelld makes working with linked data easier by providing developers with an API for defining their own schemas on top of graphs of data. It's sort of like an ORM but for linked data.

Roadmap

modelld is a work in progress. Don't depend on it for anything.

Here are the things that I'm either actively working on, or that should be worked on in the near future:

  • Determine an architecture for handling multiple RDF libraries
    • RDF JS task force API?
    • Dependency injection?
  • Support all RDF types

Example

Here's how you might use modelld to model part of a Solid user profile:

import { modelFactory } from 'modelld'
import { vocab, rdflib, web } from 'solid-client'

const profileModel = modelFactory(rdflib, {
  name: vocab.foaf('name'),
  picture: vocab.foaf('img'),
  phone: vocab.foaf('phone')
})

const defaultGraph = 'https://me.databox.me/profile/card'
const webId = 'https://me.databox.me/profile/card#me'
// Suppose you've got an RDF graph named 'graph'
const profile = profileModel(graph, defaultGraph, webId)

// Get the value of some fields
profile.any('phone') // => 'tel:000-000-0000'
profile.get('phone') // => ['tel:000-000-0000', 'tel:111-111-1111']
profile.fields('phone') // => [Field('tel:000-000-0000'), Field('tel:111-111-1111')]
// Undeclared fields don't show up
profile.any('undeclared-field') // => undefined
profile.get('undeclared-field') // => []
profile.fields('undeclared-field') // => []

// Add a field.  Models are immutable, so adding/setting/removing fields always
// returns a new model.
const newProfile = profile.add('phone', 'tel:123-456-7890')
profile.get('phone') // => ['tel:000-000-0000', 'tel:111-111-1111']
newProfile.get('phone') // => ['tel:000-000-0000', 'tel:111-111-1111', 'tel:123-456-7890']

// Remove a field
const myName = profile.fields('name')[0]
profile
  .remove(myName)
  .any('name') // => undefined

// Update a field's value
const name = profile.fields('name')[0]
profile
  .set(name, 'Daniel')
  .any('name') // => 'Daniel'

// Update the namedGraph for a field
profile.setAny('name', {namedGraph: 'https://example.com/other-resource'})

// Save a model back to the LDP server(s) it came from
const name = profile.fields('name')[0]
profile
  .set(name, 'Daniel')
  .add('phone', 'tel:123-456-7890')
  .save(rdflib, web)
  .then(newModel => {
    console.log(newModel.get('name'))
    console.log(newModel.get('phone'))
  })
  .catch(err => {
    // err.model is the model including all the updates which worked
    // err.diffMap describes the RDF statements which should have been inserted and removed from the server
    // err.failedURIs describes the URIs for which the PATCH requests failed
  })

Installing

$ npm install --save modelld