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

@woocommerce/navigation

v8.2.0

Published

WooCommerce navigation utilities.

Downloads

8,591

Readme

Navigation

A collection of navigation-related functions for handling query parameter objects, serializing query parameters, updating query parameters, and triggering path changes.

Installation

Install the module

pnpm install @woocommerce/navigation --save

Usage

getHistory

A single history object used to perform path changes. This needs to be passed into ReactRouter to use the other path functions from this library.

import { getHistory } from '@woocommerce/navigation';

render() {
	return (
		<Router history={ getHistory() }>
			…
		</Router>
	);
}

getPath() ⇒ String

Get the current path from history.

Returns: String - Current path.

getTimeRelatedQuery(query) ⇒ Object

Gets time related parameters from a query.

Returns: Object - Object containing the time related queries.

| Param | Type | Description | | --- | --- | --- | | query | Object | Query containing the parameters. |

getIdsFromQuery(queryString) ⇒ Array

Get an array of IDs from a comma-separated query parameter.

Returns: Array - List of IDs converted to an array of unique integers.

| Param | Type | Description | | --- | --- | --- | | queryString | string | string value extracted from URL. |

getNewPath(query, path, currentQuery) ⇒ String

Return a URL with set query parameters.

Returns: String - Updated URL merging query params into existing params.

| Param | Type | Description | | --- | --- | --- | | query | Object | object of params to be updated. | | path | String | Relative path (defaults to current path). | | currentQuery | Object | object of current query params (defaults to current querystring). |

getQuery() ⇒ Object

Get the current query string, parsed into an object, from history.

Returns: Object - Current query object, defaults to empty object.

onQueryChange(param, path, query) ⇒ function

This function returns an event handler for the given param

Returns: function - A callback which will update param to the passed value when called.

| Param | Type | Description | | --- | --- | --- | | param | string | The parameter in the querystring which should be updated (ex page, per_page) | | path | string | Relative path (defaults to current path). | | query | string | object of current query params (defaults to current querystring). |

updateQueryString(query, path, currentQuery)

Updates the query parameters of the current page.

| Param | Type | Description | | --- | --- | --- | | query | Object | object of params to be updated. | | path | String | Relative path (defaults to current path). | | currentQuery | Object | object of current query params (defaults to current querystring). |

flattenFilters(filters) ⇒ Array

Collapse an array of filter values with subFilters into a 1-dimensional array.

Returns: Array - Flattened array of all filters.

| Param | Type | Description | | --- | --- | --- | | filters | Array | Set of filters with possible subfilters. |

getActiveFiltersFromQuery(query, config) ⇒ Array.<activeFilters>

Given a query object, return an array of activeFilters, if any.

Returns: Array.<activeFilters> - - array of activeFilters

| Param | Type | Description | | --- | --- | --- | | query | object | query oject | | config | object | config object |

getDefaultOptionValue(config, options) ⇒ string | undefined

Get the default option's value from the configuration object for a given filter. The first option is used as default if no defaultOption is provided.

Returns: string | undefined - - the value of the default option.

| Param | Type | Description | | --- | --- | --- | | config | object | a filter config object. | | options | array | select options. |

getQueryFromActiveFilters(activeFilters, query, config) ⇒ object

Given activeFilters, create a new query object to update the url. Use previousFilters to Remove unused params.

Returns: object - - query object representing the new parameters

| Param | Type | Description | | --- | --- | --- | | activeFilters | Array.<activeFilters> | activeFilters shown in the UI | | query | object | the current url query object | | config | object | config object |

getUrlKey(key, rule) ⇒ string

Get the url query key from the filter key and rule.

Returns: string - - url query key.

| Param | Type | Description | | --- | --- | --- | | key | string | filter key. | | rule | string | filter rule. |

activeFilter : Object

Describe activeFilter object.

Properties

| Name | Type | Description | | --- | --- | --- | | key | string | filter key. | | [rule] | string | a modifying rule for a filter, eg 'includes' or 'is_not'. | | value | string | filter value(s). |