Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaotian committed Jul 9, 2024
1 parent 7d97d20 commit 3e2075f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ export function encodeParams<T = any>(
const encodedParams = [];
const encodeURIFn = encodeURI ? encodeURIComponent : (v: string) => v;
const paramsIsArray = Array.isArray(params);
const { arrayFormat, allowDots, serializeDate } = options || {};
const getKey = (key: string) => {
if (options?.allowDots && !paramsIsArray) return `.${key}`;
if (allowDots && !paramsIsArray) return `.${key}`;
if (paramsIsArray) {
if (options?.arrayFormat === 'brackets') {
if (arrayFormat === 'brackets') {
return `[]`;
} else if (options?.arrayFormat === 'repeat') {
} else if (arrayFormat === 'repeat') {
return ``;
}
}
Expand All @@ -37,7 +38,7 @@ export function encodeParams<T = any>(
const encodedKey = parentKey ? `${parentKey}${getKey(key)}` : (key as string);

if (value instanceof Date) {
value = options?.serializeDate ? options?.serializeDate(value) : value.toISOString();
value = serializeDate ? serializeDate(value) : value.toISOString();
}
if (typeof value === 'object') {
// If the value is an object or array, recursively encode its contents
Expand Down

0 comments on commit 3e2075f

Please sign in to comment.