query-string-utils
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "query-string-utils", | ||
"version": "0.1.0", | ||
"description": "A small collection of helper functions for working with query strings.", | ||
"version": "0.2.0", | ||
"description": "A small collection of utility functions for working with query strings.", | ||
"main": "lib/index.js", | ||
@@ -11,7 +11,7 @@ "types": "lib/index.d.ts", | ||
"lint": "tslint -p tsconfig.json", | ||
"postversion" : "git push && git push --tags", | ||
"prepublishOnly" : "npm test && npm run lint", | ||
"preversion" : "npm run lint", | ||
"postversion": "git push && git push --tags", | ||
"prepublishOnly": "npm test && npm run lint", | ||
"preversion": "npm run lint", | ||
"test": "jest --config jestconfig.json", | ||
"version" : "npm run format && git add -A src" | ||
"version": "npm run format && git add -A src" | ||
}, | ||
@@ -18,0 +18,0 @@ "files": [ |
@@ -14,3 +14,3 @@ # Query string utils | ||
```js | ||
import { getQsNumber, getQsNumbers, getQsString, getQsStrings } from 'query-string-utils'; | ||
import { getQsDate, getQsDates, getQsNumber, getQsNumbers, getQsString, getQsStrings } from 'query-string-utils'; | ||
@@ -20,3 +20,3 @@ const searchParams = new URLSearchParams(window.location.search); | ||
// ?id=42 | ||
const id = getQsNumber(searchParams, 'id', 0); | ||
const [ id = 0 ] = getQsNumber(searchParams, 'id'); | ||
console.log(id); | ||
@@ -26,3 +26,3 @@ //=> 42 | ||
// ?id=13&id=30&id=7 | ||
const ids = getQsNumbers(searchParams, 'id', []); | ||
const ids = getQsNumber(searchParams, 'id'); | ||
console.log(ids); | ||
@@ -32,3 +32,3 @@ //=> [13, 30, 7] | ||
// ?key=foo | ||
const key = getQsString(searchParams, 'key', ''); | ||
const [ key = '' ] = getQsString(searchParams, 'key'); | ||
console.log(key); | ||
@@ -38,5 +38,25 @@ //=> 'foo' | ||
// ?key=foo&key=bar&key=baz | ||
const keys = getQsStrings(searchParams, 'key', []); | ||
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 | ||
``` |
5790
58