Skip to content

v0.5.2

Compare
Choose a tag to compare
@suhaotian suhaotian released this 09 Jul 03:55
· 24 commits to main since this release
  • Fix(core): if params include Date value, call .toISOString() and utils encodeParams support options allowDot: true and arrayFormat: '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