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

@rdfjs/fetch

v3.1.1

Published

Wrapper for fetch to simplify sending and receiving RDF data

Downloads

19,609

Readme

@rdfjs/fetch

build status npm version

Wrapper for fetch to simplify sending and retrieving RDF data.

Since version 3.0, this packages is ESM only. Check version 2.x if you are looking for a CommonJS package.

Usage

The package exports a fetch function which wraps the request and response object for on-the-fly RDF quad processing. The function accepts the same parameters as fetch and some additional options. It also provides extra methods.

Options

The options object accepts the following additional parameters:

  • formats: A formats-common-compatible object which contains a set of parsers and serializers. By default formats-common is used.
  • factory: The factory which will be used to create a Dataset when dataset() is called. By default @rdfjs/dataset is used.
  • fetch: An alternative fetch implementation. By default nodeify-fetch is used.

The following options influence the logic of RDF quad processing:

  • headers.accept: The accept header field will be automatically set base on the list of available parsers from the formats object. If it's already set it will not be overwritten. This can be useful when only a subset of the available parsers should be used.
  • headers.content-type: When the request has a body, this header field will be automatically set to use matching media type for the corresponding serializer. By setting this field manually a specific serializer can be enforced.
  • body: If the request should send quads, the quads must be given either as a stream or as an iterable like a DatasetCore object. Iterables will be converted to streams before they are handed over to the serializer.

Response

The following methods are attached to the standard fetch response object:

  • async quadStream(): This method returns the quads of the response as stream. The parser is selected based on the content type header field.
  • async dataset(): This method uses the quadStream() method to parse the content and will pipe it into a dataset, which is also the return value.

Example

This example fetches the RDF Schema vocab and loops over all quad using the dataset API. For all rdfs:label quads the object value is written to the console.

import fetch from '@rdfjs/fetch'

const label = 'http://www.w3.org/2000/01/rdf-schema#label'

fetch('http://www.w3.org/2000/01/rdf-schema')
  .then(res => res.dataset())
  .then(dataset => {
    for (const quad of dataset) {
      if (quad.predicate.value === label) {
        console.log(`${quad.subject.value}: ${quad.object.value}`)
      }
    }
  })
  .catch(err => console.error(err))