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

@sportdevs/endpoint

v1.0.0

Published

A request generation utility for the SportDevs APIs and other Postgrest-compatible APIs

Downloads

11

Readme

SportDevs Endpoint Utility

A request generation utility for the SportDevs APIs.

Installation

You can install this library using npm, it's available as the @sportdevs/endpoint package.

npm install @sportdevs/endpoint

Usage

This library only has a single export called endpoint which can be used to generate request URLs.

import endpoint from "@sportdevs/endpoint";
// ... or
const endpoint = require("@sportdevs/endpoint").default;

You can chain all the transforms to create a complex query, like this:

endpoint("events")
  .property("season_id")
  .equals(18820)
  .or((obj) =>
    obj
      .property("away_team_score->current")
      .greaterThan(3)
      .property("home_team_score->current")
      .greaterThan(3)
  )
  .select("away_team_id", "home_team_id", "away_team_score", "home_team_score")
  .order((o) => o.property("id").descending);
// events?season_id=eq.18820&or=(away_team_score->current.gt.3,home_team_score->current.gt.3)&select=away_team_id,home_team_id,away_team_score,home_team_score&order=id.desc

endpoint(name)

Creates an object that is associated with an endpoint.

endpoint("events");

toString()

Turns an endpoint object to a string.

endpoint("events").toString();

Response Transforms

offset(value)

Skips value amount of elements.

endpoint("events").offset(1);
// events?offset=1

limit(value)

Limits the response to value amount of objects.

endpoint("events").limit(1);
// events?limit=1

select(...props)

Makes the returned object only contain the selected properties.

endpoint("events").select("home_team_id", "away_team_id");
// events?select=home_team_id,away_team_id

Property Transforms

All the property transforms can be negated using the not. prefix.

endpoint("events").property("id").not.lessThan(10);
// events?id=not.lt.10

property(name)

Applies a transform using a property.

endpoint("events").property("id").lessThan(10);
// events?id=lt.10

equals(value)

Checks if a property is equal to value.

endpoint("events").property("id").equals(10);
// events?id=eq.10

greaterThan(value)

Checks if a property is greater than value.

endpoint("events").property("id").greaterThan(10);
// events?id=gt.10

greaterThanOrEqual(value)

Checks if a property is greater than or equal to value.

endpoint("events").property("id").greaterThanOrEqual(10);
// events?id=gte.10

lessThan(value)

Checks if a property is less than value.

endpoint("events").property("id").lessThan(10);
// events?id=lt.10

lessThanOrEqual(value)

Checks if a property is less than or equal to value.

endpoint("events").property("id").lessThanOrEqual(10);
// events?id=lte.10

like(exp)

Checks if a property matches a glob expression.

endpoint("players").property("first_name").like("A*");
// players?first_name=like.A*

insensitive.like(exp)

Checks if a property matches a glob expression (case insensitive).

endpoint("players").property("first_name").insensitive.like("A*");
// players?first_name=ilike.A*

match(exp)

Checks is a property matches a POSIX regular expression.

endpoint("players").property("first_name").match("^A");
// players?first_name=match.^A

insensitive.match(exp)

Checks is a property matches a POSIX regular expression.

endpoint("players").property("first_name").insensitive.match("^A");
// players?first_name=imatch.^A

in(...values)

Checks if the property is inside the array value.

endpoint("events").property("id").in(1, 2, 3);
// events?id=in.(1,2,3)

is(value)

Checks if the property is exactly equal to value.

endpoint("events").property("id").is("null");
// events?id=is.null

Logical Transforms

All the logical transforms can be negated with the not. prefix.

endpoint("events").not.or((obj) =>
  obj.property("id").lessThan(10).property("id").not.equals(1)
);
// events?not.or=(id.lt.10,id.not.eq.1)

and(fn)

Combines the transforms using the logical and operator.

endpoint("events").and((obj) =>
  obj.property("id").lessThan(10).property("id").not.equals(1)
);
// events?and=(id.lt.10,id.not.eq.1)

or(fn)

Combines the transforms using the logical or operator.

endpoint("events").or((obj) =>
  obj.property("id").lessThan(10).property("id").not.equals(1)
);
// events?or=(id.lt.10,id.not.eq.1)

Sort Transforms

order(fn)

Applies a sorting transform.

endpoint("events").order((obj) => obj.property("id").ascending);
// events?order=id.asc

property(name)

Applies a sorting transform using a property.

endpoint("events").order((obj) => obj.property("id").ascending);
// events?order=id.asc

ascending

Sorts the returned objects in ascending order based on a property.

endpoint("events").order((obj) => obj.property("id").ascending);
// events?order=id.asc

descending

Sorts the returned objects in descending order based on a property.

endpoint("events").order((obj) => obj.property("id").descending);
// events?order=id.desc

nullsFirst

Makes the null values appear first.

endpoint("events").order(
  (obj) => obj.property("id").ascending.property("id").nullsFirst
);
// events?order=id.asc.nullsfirst

nullsLast

Makes the null values appear last.

endpoint("events").order(
  (obj) => obj.property("id").descending.property("id").nullsLast
);
// events?order=id.desc.nullslast