- Fix(core): if params include
Date
value, call.toISOString()
and utilsencodeParams
support optionsallowDot: true
andarrayFormat: 'indices' | 'repeat' | 'brackets'
(default is'indices'
). Fix issues/22 and issues/23
Code example:
import xior, { encodeParams } from 'xior';
const filter = {
ids: [1, 2, 3],
dateFrom: new Date(),
dateTo: new Date(),
};
const http = xior.create({
paramsSerializer: (params: any) =>
encodeParams(params, true, null, {
allowDots: false,
arrayFormat: 'indices', // 'indices' | 'repeat' | 'brackets'
serializeDate: (date) => date.toISOString(),
}),
});
/*
'indices': { a: ['b', 'c'] } -> 'a[0]=b&a[1]=c'
'brackets': { a: ['b', 'c'] } -> 'a[]=b&a[]=c'
'repeat': { a: ['b', 'c'] } -> 'a=b&a=c'
*/
http.get('https://example.com', { params: { filter } });
Full Changelog: v0.5.1...v0.5.2