Skip to content

Instantly share code, notes, and snippets.

@akshitkrnagpal
Created March 24, 2021 10:01
Show Gist options
  • Save akshitkrnagpal/2baf5b7d41751bfcdc98f2d380bec3b0 to your computer and use it in GitHub Desktop.
Save akshitkrnagpal/2baf5b7d41751bfcdc98f2d380bec3b0 to your computer and use it in GitHub Desktop.
Custom Param for Array for serialize-query-params
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