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

qproc-mongo-qs

v1.2.0

Published

Provides a query string builder class to create url encoded query strings that are compatible with qproc-mongo.

Downloads

2

Readme

qproc-mongo-qs

Targets ES5+

Provides a query string builder class to create url encoded query strings that are compatible with qproc-mongo.

Table of Contents

Install

npm i -S qproc-mongo-qs

Usage

const { QSBuilder } = require("qproc-mongo-qs");
const qs = new QSBuilder();

qs.limit(100)
  .skip(0)
  .sort("timestamp", -1);

qs.prop("word").in("one", "two", "three");
qs.prop("value")
  .gt(10)
  .lte(20);
qs.prop("nested.status").ne("active");
qs.prop("text").regex(/^[A-z0-9]/);

console.log(qs.toString());

/*

limit=100&sort=desc:timestamp&word=in:one,two,three&value=gt:10,lte:20&nested.status=ne:active&text=regex:/%5E[A-z0-9]/

*/

const uri = `https://rest-api.com/api/items?${qs.toString()}`;

Keys

The limit, skip, sort, and search keys should match the keys qproc-mongo is configured with. The defaults match the qproc-mongo defaults.

| Key | Default | Description | Example | | ------ | -------- | ---------------------------------------- | ----------------------- | | limit | limit | The maximum number of records to return. | qs.limitKey('count') | | skip | skip | The number of records to skip. | qs.skipKey('offset') | | sort | sort | The sort property name(s) and order(s). | qs.sortKey('orderBy') | | search | search | The search term. | qs.searchKey('q') |

Example

const { QSBuilder } = require("qproc-mongo-qs");

const qs = new QSBuilder();
qs.limitKey("count")
  .skipKey("offset")
  .sortKey("orderBy")
  .searchKey("q")
  .limit(10)
  .sort("value", 1);

qs.prop("value")
  .gt(1)
  .lte(10);

console.log(qs.toString());

/*

count=10&orderBy=asc:value&value=gt:1,lte:10

*/

Limit

The limit method expects a positive Number argument and returns the QSBuilder so that calls are chainable.

Skip

The skip method expects a positive Number argument and returns the QSBuilder so that calls are chainable.

Sort

The sort method expects a property name and a numerical direction as arguments. It can be called multiple times with different property name values for complex sorts. Returns the QSBuilder so that calls are chainable.

| Direction | Sort Order | Example | | --------- | ---------- | -------------------------- | | -1 | Descending | qs.sort('timestamp', -1) | | 1 | Ascending | qs.sort('timestamp', 1) |

Search

The search method expects a String or Number. As stated in the qproc-mongo documentation, when a search key is present in the query parameters, all other query parameters are ignored. See the qproc-mongo documentation for more info. Returns the QSBuilder so that calls are chainable.

Query Parameters

The prop method expects a property name argument and returns a QSParam. The prop exposes the following operator functions. The operator functions return the QSParam for chaining.

| Function | Argument Type | Description | Example | | -------- | -------------------- | ----------------------------------------------------------- | --------------------------- | | eq | String | Number | Equal. | prop('key').eq('value') | | ne | String | Number | Not equal. | prop('key').ne('value') | | in | String | Number | In the list of values. Accepts any number of arguments. | prop('key').in(1,2,3,4) | | nin | String | Number | Not in the list of values. Accepts any number of arguments. | prop('key').nin(1,2,3,4) | | gt | String | Number | Greater than. | prop('key').gt(1) | | gte | String | Number | Greater than or equal to. | prop('key').gte(1) | | lt | String | Number | Less than. | prop('key').lt(1) | | lte | String | Number | Less than or equal to. | prop('key').lte(1) | | all | String | Number | Contains all values. Accepts any number of arguments. | prop('key').all(1,2,3,4) | | regex | String | RegExp | Match regular expression. | prop('key').regex(/^A-z/) |

Calling the same operator method on the same prop multiple times will overwrite the previous value.