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

fastquery

v1.0.1

Published

Fast Query is a lightweight and super fast query string parser for node javascript.

Downloads

3

Readme

Fast Query

Fast Query is a lightweight and super fast query string parser for node javascript.

With fastquery you don't have to parse the querystring from the url first, we do that for you using the most optimized method just send us the req.url for example.

Fast Query parses string types...

/test/home/?custom1=zing&custom2=zoom&custom3=blah

custom1=zing&custom2=zoom&custom3=blah

?custom1=zing&custom2=zoom&custom3=blah

Installation

npm i fastquery --save

Usage

parse(querystring, options, sep, eq) → {parsedQuery}

Params

| Name | Type | Default |Description | |--|--|--|--| | querystring | string | !required | The query string you wish to parse | | options | object | 100 | Currently only features options.maxFields | | sep | string | & | multiple query parameters are separated by the ampersand "&" | | eq | string | = | Each separation contains a pair field=value |

Assuming you have already installed fastquery

const fq = require('fastquery');

We can set our own options to parse our query string such as maxFields..

let options = {
    maxFields: 200
}
let sep = '&';
let eq = '=';
let querystring = '/test/home/?custom1=zing&custom2=zoom&custom3=blah';

let parsed = fq.parse(querystring, options, sep, eq);
console.log(parsed);

This is just a basic example of parsing a query and getting the value from one of the custom fields.

Example

const fq = require('fastquery');
// If were using http webserver we could pass the req.url like so
let req = '/test/home/?custom1=zing&custom2=zoom&custom3=blah'

let query = fq.parse(req);
// Output the parsed query string.
console.log(query);
// Get the value of a specific field
console.log(query.custom1);

Benchmarks

These benchmarks also reflect the jsperf results found here slice vs substring vs indexof vs regex

First I did a few simple tests and find the best method for splitting a string.

| Method | Time Taken | Output | | -- | -- | -- | | split | 1614.155ms | imsplitthere | | indexOf | 2308.475ms | imsplitthere | | slice | 2200.492ms | imsplitthere |

From this result, we can clearly see that split, is clearly faster. So we built our querystring parser based on this regex is slower sorry not included. Maybe later..

Then we tested different methods that I gathered up to see which would be the fastest to parse the whole querystring. I developed the fastest regex, and used the current querystring module to compare against while also using some of that code in our own so its backwards compatible and its nicely written.

| Method | Time Taken | Output | | -- | -- | -- | | fastRegex | 8868.756ms | {custom1:'zing',custom2:'zoom',custom3:'blah'} | | querystring | 31618.960ms | {custom1:'zing',custom2:'zoom',custom3:'blah'} | | fastquery | 5160.376ms | {custom1:'zing',custom2:'zoom',custom3:'blah'} |

fastquery is the fastest and will parse multiple types of strings. I did benchtest other methods of parsing a string but these 3 stood out... You can replace the decode function on querystring, because its using indexOf it is still slightly slower than fastquery.

fastRegex isn't that far behind.. Its also a very useful regex.

Please checkout the bench.js for source code for the other query string parsers and the full bench test.

To Do...

  • Extra features
  • More examples

Coming soon...

  • Possibly fast routing...

Feedback

Feedback and improvments are always appreciated and help us to improve so please leave some!

License

Licensed under MIT.