Created
March 24, 2021 10:01
-
-
Save akshitkrnagpal/2baf5b7d41751bfcdc98f2d380bec3b0 to your computer and use it in GitHub Desktop.
Custom Param for Array for serialize-query-params
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { encodeDelimitedArray, decodeDelimitedArray } from "serialize-query-params"; | |
/** Uses a comma to delimit entries. e.g. ['a', 'b'] => qp?=a,b */ | |
const CommaArrayParam = { | |
encode: array => { | |
if (!array || array.length === 0) return undefined; | |
return encodeDelimitedArray(array, ","); | |
}, | |
decode: arrayStr => { | |
if (!arrayStr) return undefined; | |
return decodeDelimitedArray(arrayStr, ","); | |
}, | |
}; | |
export default CommaArrayParam; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment