🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

query-string-utils

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

query-string-utils

A small collection of utility functions for working with query strings.

0.2.1
latest
Source
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Query string utils

A small collection of utility functions for working with query strings.

Install

$ npm install query-string-utils

Usage

import { getQsDate, getQsDates, getQsNumber, getQsNumbers, getQsString, getQsStrings } from 'query-string-utils';

const searchParams = new URLSearchParams(window.location.search);

// ?id=42
const [ id = 0 ] = getQsNumber(searchParams, 'id');
console.log(id);
//=> 42

// ?id=13&id=30&id=7
const ids = getQsNumber(searchParams, 'id');
console.log(ids);
//=> [13, 30, 7]

// ?key=foo
const [ key = '' ] = getQsString(searchParams, 'key');
console.log(key);
//=> 'foo'

// ?key=foo&key=bar&key=baz
const keys = getQsString(searchParams, 'key');
console.log(keys);
//=> ['foo', 'bar', 'baz']

// ?key=1970-01-01T13:30:07
const [ date = new Date() ] = getQsDate(searchParams, 'date');
console.log(date);
//=> Date Thu Jan 01 1970 13:30:07 GMT+0100 (Central European Standard Time)

// ?date=1962-10-16&date=1962-10-28
const dates = getQsDate(searchParams, 'date');
console.log(dates);
//=> [ Date Tue Oct 16 1962 01:00:00 GMT+0100 (Central European Standard Time), Date Sun Oct 28 1962 01:00:00 GMT+0100 (Central European Standard Time) ]

// ?status=true
const [ status = false ] = getQsBoolean(searchParams, 'status');
console.log(active);
//=> true

// ?status=true&status=yes&status=false&status=on
const statuses = getQsBoolean(searchParams, 'status');
console.log(statuses);
//=> true, true, false, true

Keywords

querystring

FAQs

Package last updated on 13 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts