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

qhistory

v1.1.0

Published

Wrap history with query support

Downloads

25,601

Readme

qhistory

Add query object support to history library location objects.

You will need to supply stringify and parse methods.

stringify

A function that takes a query object and returns a search string.

stringify({ occupation: 'computer' }) // 'occupation=computer'

parse

A function that takes a search string and returns a query object.

parse('stopDownloading=true') // { stopDownloading: 'true' }

There are lots of different query string packages that you can choose from. Some popular ones include:

There may be subtle differences in the way that each parses and stringifies, so you will need to determine which supports the features that you want.

Installation

npm install --save qhistory

Usage

import { createBrowserHistory } from 'history'
import qhistory from 'qhistory'

import { stringify, parse } from 'qs'

const history = qhistory(
  createBrowserHistory({ /* history configuration options */ }),
  stringify,
  parse
)

Usage with React Router

This can be used with React Router v4 to add query string support to location objects. If a location object has both a search string and a query object, the search string's value will be overwritten by the stringified query object.

import { Router } from 'react-router-dom'
import { createBrowserHistory } from 'history'
import qhistory from 'qhistory'

import { stringify, parse } from 'qs'

const history = qhistory(
  createBrowserHistory({ /* history configuration options */ }),
  stringify,
  parse
)

render((
  <Router history={history}>
    <App />
  </Router>
), document.getElementById('root'))

If you're using React Router 4's BrowserRouter you can incorporate qhistory like this:

class QueryRouter extends React.Component {
  static propTypes = {
    basename: PropTypes.string,
    forceRefresh: PropTypes.bool,
    getUserConfirmation: PropTypes.func,
    keyLength: PropTypes.number,
    children: PropTypes.node,
    stringify: PropTypes.func,
    parse: PropTypes.func,
  }

  history = qhistory(
    createBrowserHistory(this.props),
    this.props.stringify,
    this.props.parse
  )

  render() {
    return <Router history={this.history} children={this.props.children} />
  }
}

// usage
render((
  <QueryRouter stringify={stringify} parse={parse}>
    <App />
  </QueryRouter>
), document.getElementbyId('root'))