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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vterzic/sparql-builder

v0.2.1

Published

Just a simple SPARQL query builder

Readme

sparql-builder

Just a simple, zero-dependency library for creating SPARQL queries.

Motivation

This library was made in order to speed up development process when creation of SPARQL queries is needed.

TODO

  • ~~SELECT Query~~
  • CONSTRUCT Query
  • UPDATE Query

Installation

npm i @vterzic/sparql-builder

Examples

Examples can also be found in ./test/select-query.spec.ts

Simple select

SELECT * WHERE {
  ?s ?p ?o .
}
const { builder } = require('@vterzic/sparql-builder');

const q = new Select()
    .select('*')
    .where('s', 'p', 'o');

q.render();

Simple select with variables

SELECT ?s ?p WHERE {
  ?s ?p ?o .
}
const { builder } = require('@vterzic/sparql-builder');

const q = builder.selectQuery()
        .select('s', 'p')
        .where('s', 'p', 'o');

q.render();

Select with optionals

SELECT * WHERE {
  ?s ?p ?o .
  OPTIONAL {
    ?o ?p2 ?o2 .
    ?o ?p3 ?o3 .
  }
}
const { builder } = require('@vterzic/sparql-builder');

const q = builder.selectQuery()
.select('*')
.where('s', 'p', 'o')
.optional(
    builder
        .optional()
        .where('o', 'p2', 'o2')
        .where('o', 'p3', 'o3')
);

q.render();

Select with offset and limit

SELECT ?s ?p WHERE {
  ?s ?p ?o .
} OFFSET 5 LIMIT 10
const { builder } = require('@vterzic/sparql-builder');

const q = builder.selectQuery()
        .select('s', 'p')
        .where('s', 'p', 'o')
        .offset(5)
        .limit(10);

q.render();

Group by query

SELECT ?location (SUM(?amount) as ?totalAmount) WHERE {
  ?location schema:amount ?amount .
} GROUP BY ?location HAVING(?totalAmount > 10) OFFSET 5 LIMIT 10
const { builder, operators: op } = require('@vterzic/sparql-builder');

const q = builder.selectQuery()
        .prefix(op.prefix('schema', op.iri('http://schema.org/')))
        .select('location', op.sum('?amount', 'totalAmount'))
        .where('location', 'schema:amount', '?amount')
        .groupBy('location')
        .having('?totalAmount > 10')
        .offset(5)
        .limit(10);
        
q.render();

Order by

SELECT * WHERE {
  ?s ?p ?o .
} ORDER BY DESC(?p) ASC(?o)
const { builder, operators: op } = require('@vterzic/sparql-builder');

const q = builder.selectQuery()
.select('*')
.where('s', 'p', 'o')
.orderBy(op.desc('p'))
.orderBy(op.asc('o'));

Nested query (subquery)

PREFIX schema: <http://schema.org/>
SELECT * WHERE {
  {
    SELECT ?s WHERE {
      BIND ('sparql-builder' as ?varName) .
      ?s schema:name ?varName .
    }
  }
}
const { builder, operators: op } = require('@vterzic/sparql-builder');

const q = const q = builder.selectQuery()
    .prefix(op.prefix('schema', 'http://schema.org/'))
    .select('*')
    .nest(
        builder.selectQuery()
            .bind(op.toStringLiteral('sparql-builder'), 'varName')
            .select('s')
            .where('s', 'schema:name', 'varName'),
    );


q.render();

Nested queries UNION

const { builder } = require('@vterzic/sparql-builder');

PREFIX schema: <http://schema.org/>
SELECT * WHERE {
  {
    SELECT ?s WHERE {
      ?s schema:name 'example1' .
    }
  }
  UNION
  {
    SELECT ?s WHERE {
      ?s schema:lastName 'example2' .
    }
  }
}
const { builder, operators: op } = require('@vterzic/sparql-builder');

const subQuery1 = builder.selectQuery()
    .select('s')
    .where('s', 'schema:name', op.toStringLiteral('example1'));
const subQuery2 = builder.selectQuery()
    .select('s')
    .where('s', 'schema:lastName', op.toStringLiteral('example2'));

const q = builder.selectQuery()
    .prefix(op.prefix('schema', 'http://schema.org/'))
    .select('*')
    .nest(subQuery1)
    .nest(subQuery2, 'UNION');

q.render();

Nested queries optional

PREFIX schema: <http://schema.org/>
SELECT * WHERE {
  {
    SELECT ?s WHERE {
      ?s schema:name 'example1' .
    }
  }
  OPTIONAL {
    SELECT ?s WHERE {
      ?s schema:lastName 'example2' .
    }
  }
}
const { builder, operators: op } = require('@vterzic/sparql-builder');

const subQuery1 = new SelectQuery()
    .select('s')
    .where('s', 'schema:name', op.toStringLiteral('example1'));
const subQuery2 = new SelectQuery()
    .select('s')
    .where('s', 'schema:lastName', op.toStringLiteral('example2'));

const q = new SelectQuery()
    .prefix(op.prefix('schema', 'http://schema.org/'))
    .select('*')
    .nest(subQuery1)
    .nest(subQuery2, 'OPTIONAL');

q.redner();