@domonda/query-params
Advanced tools
+16
-0
@@ -6,2 +6,18 @@ # Change Log | ||
| # [2.0.0](https://github.com/domonda/domonda-js/compare/@domonda/query-params@1.5.9...@domonda/query-params@2.0.0) (2020-07-20) | ||
| ### Features | ||
| * null for params without values and undefined for missing params ([67e4e5a](https://github.com/domonda/domonda-js/commit/67e4e5a9922cfd2bb1c769993c9a1420c64287ed)) | ||
| ### BREAKING CHANGES | ||
| * Query params now treat null and undefined differently. If there is a parameter in the URL but no value - its treated as `null`; however, if the paramter is completely missing from the URL - then its `undefined`. BEWARE: because of this, the `defaultValue` will be used exclusively if the value is `undefined` (since `null` is treated as a set value). | ||
| ## [1.5.9](https://github.com/domonda/domonda-js/compare/@domonda/query-params@1.5.8...@domonda/query-params@1.5.9) (2020-07-01) | ||
@@ -8,0 +24,0 @@ |
+1
-3
| { | ||
| "name": "@domonda/query-params", | ||
| "version": "1.5.9", | ||
| "version": "2.0.0", | ||
| "description": "Useful but simple query params manipulator for React.", | ||
@@ -31,4 +31,2 @@ "keywords": [ | ||
| "history": "^4.10.1", | ||
| "lodash.clonedeepwith": "^4.5.0", | ||
| "lodash.pickby": "^4.6.0", | ||
| "query-string": "^6.13.1" | ||
@@ -35,0 +33,0 @@ }, |
+1
-1
@@ -7,3 +7,3 @@ /** | ||
| export declare function strictUriEncode(str: string): string; | ||
| /** Stringify function which omits `undefined`, `null`, and empty arrays. */ | ||
| /** Stringify function which omits `undefined` values and persists empty arrays. */ | ||
| export declare function stringify(value: { | ||
@@ -10,0 +10,0 @@ [key: string]: any; |
+15
-11
@@ -7,4 +7,2 @@ /** | ||
| import { stringify as qsStringify, parse as qsParse } from 'query-string'; | ||
| import pickBy from 'lodash/pickBy'; | ||
| import cloneDeepWith from 'lodash/cloneDeepWith'; | ||
| import { parseISOToDate, stripTime } from './date'; | ||
@@ -22,18 +20,24 @@ const ARRAY_FORMAT = 'bracket'; | ||
| } | ||
| /** Stringify function which omits `undefined`, `null`, and empty arrays. */ | ||
| /** Stringify function which omits `undefined` values and persists empty arrays. */ | ||
| export function stringify(value, props = {}) { | ||
| const { prependQuestionMark } = props; | ||
| const str = qsStringify(pickBy(cloneDeepWith(value, (val) => { | ||
| // persist empty arrays | ||
| if (Array.isArray(val) && val.length === 0) { | ||
| return [null]; | ||
| const str = qsStringify(Object.entries(value).reduce((acc, [key, val]) => { | ||
| // omit `undefined`s | ||
| if (val === undefined) { | ||
| return acc; | ||
| } | ||
| // convert valid dates to iso strings | ||
| // convert valid dates to iso strings, omit invalid dates | ||
| if (val instanceof Date) { | ||
| if (isNaN(val.getDate())) { | ||
| return null; | ||
| return acc; | ||
| } | ||
| return val.toISOString(); | ||
| return Object.assign(Object.assign({}, acc), { [key]: val.toISOString() }); | ||
| } | ||
| }), (part) => part != null), { arrayFormat: ARRAY_FORMAT }); | ||
| // persist empty arrays | ||
| if (Array.isArray(val) && val.length === 0) { | ||
| return Object.assign(Object.assign({}, acc), { [key]: [null] }); | ||
| } | ||
| // everything else is just passed through | ||
| return Object.assign(Object.assign({}, acc), { [key]: val }); | ||
| }, {}), { arrayFormat: ARRAY_FORMAT }); | ||
| if (prependQuestionMark && str.length > 0) { | ||
@@ -40,0 +44,0 @@ return '?' + str; |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
24030
3.79%5
-28.57%310
1.31%1
Infinity%- Removed
- Removed
- Removed
- Removed