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

urlq

v0.1.0

Published

url query library to get and modify query params

Downloads

1,476

Readme

urlq

A lightweight library to get/set url query string values.

Usage

const urlq = require('urlq');
const q1 = '?sections=carbs,dessert&diets=gluten-free';

urlq.getParam(q1, 'sections')
=> ['carbs', 'dessert']

urlq.getParam(q1, 'diets')
=> ['gluten-free']

urlq.getParam(q1, 'non-existing')
=> []

var q2 = urlq.addVal(q1, 'sections', 'soups');
q2;
=> '?sections=carbs,dessert,soups&diets=gluten-free'

urlq.updateQuery(q2);
urlq.getParam(window.location.search, 'sections');
=> ['carbs', 'dessert', 'soups']

var q3 = urlq.updateParam(q2, 'diets', ['vegetarian', 'pescepescetarian']);
urlq.removeParam(q2, 'sections');
q3;
=> '?diets=vegetarian,pescepescetarian'

Functions

addVal(q, p, v) ⇒ String

Returns a new query string with values added to a query parameter.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The query string. | | p | String | The query parameter to update. | | v | * | The value to add. |

getParam(q, p) ⇒ Array

Returns an array of values for a query parameter.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The query string. | | p | String | The query parameter. |

makeValidQuery(q) ⇒ String

Returns a valid formatted url query string

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The query string to format. |

removeVal(q, p, v) ⇒ String

Returns a new query string with a value removed from a parameter.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The query string to update. | | p | String | The parameter to remove the value. | | v | String | The value to remove from a parameter. |

removeParam(q, p) ⇒ String

Returns a new query string with a parameter removed.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The query string to update. | | p | String | The parameter to remove. |

updateParam(q, p, vs) ⇒ String

Returns a new query string with updated values from a parameter. If newVals.length = 0 the parameter is removed.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The query string to update. | | p | String | The param to update. | | vs | Array | The new values for the param. |

updateQuery(q)

Updates the browser history with a new query string.

Kind: global function

| Param | Type | Description | | --- | --- | --- | | q | String | The new query string. |

Test

npm test