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

@limitless.claver/laravel-query-builder

v0.2.9

Published

JavaScript Query Builder provides an easy way to build a query string compatible with spatie/laravel-query-builder.

Downloads

3

Readme

Laravel Query Builder

NPM version GitHub Workflow Status GitHub issues GitHub top language npm js-standard-style

The spatie function is a URL builder that allows you to easily add query parameters to a URL using a fluent interface compatible with spatie/laravel-query-builder.

Install

You can install package using yarn (or npm):

yarn add @limitless.claver/laravel-query-builder

Usage

To use the spatie function, simply call it with a URL string as its argument. The returned object has three methods: filter, include, and sort, which can be chained together to build the desired URL.

const {spatie} = require("@limitless.claver/laravel-query-builder");

Example

const url = 'https://example.com';

const result = spatie(url)
  .filter('status', 'published')
  .include('author', 'categories')
  .sort('title', '-date')
  .build();

console.log(result); 
// Outputs: https://example.com?filter[status]=published&include=author,categories&sort=title,-date

Methods

filter(key: string, value: string)

Adds a filter query parameter to the URL. The key argument is the name of the filter, and the value argument is the value of the filter. If the URL already has query parameters, the filter is added with an ampersand (&) separator. Otherwise, the filter is added with a question mark (?) separator.

Example:

const url = 'https://example.com/posts';

const result = spatie(url)
  .filter('status', 'published')
  .build();

console.log(result); 
// Outputs: https://example.com/posts?filter[status]=published

include(...value: any)

Adds an include query parameter to the URL. The value argument can be a string or an array of strings.

If the URL already has an include parameter, the new values are appended to the existing ones. Otherwise, a new include parameter is added.

Example:

const url = 'https://example.com/posts';

const result = spatie(url)
  .include('author', 'categories')
  .build();

console.log(result); 
// Outputs: https://example.com/posts?include=author,categories

sort(...field: string[])

Adds a sort query parameter to the URL. The field argument can be a string or an array of strings. If the URL already has a sort parameter, the new values are appended to the existing ones. Otherwise, a new sort parameter is added.

Example:

const url = 'https://example.com/posts';

const result = spatie(url)
  .sort('title', '-date')
  .build();

console.log(result); 
// Outputs: https://example.com/posts?sort=title,-date

when(condition: boolean, callback: (param: any)=> any)

Adds a query parameter to the URL. The condition argument must be a boolean. And the callback should would return an interface for further chaining or building.

Example

const url = 'https://example.com/posts';

const result = spatie(url).include('author')
    .when('claver'.length > 5, q => q.sort('-title'))
    .sort('name')
    .filter("status","Published").build()

console.log(result);
// Outputs: https://example.com/posts?include=author&sort=-title,name&filter[status]=Published

build()

Returns the built URL string.

Example

const url = 'https://example.com/posts';

const result = spatie(url)
  .filter('status', 'published')
  .include('author', 'categories')
  .sort('title', '-date')
  .build();

console.log(result); 
// Outputs: https://example.com/posts?filter[status]=published&include=author,categories&sort=title,-date