mirror of
https://github.com/arthurfiorette/axios-cache-interceptor.git
synced 2025-12-08 17:36:16 +00:00
refactor: simplified defaultKeyGenerator function
This commit is contained in:
parent
a7751fd1cb
commit
c15598241a
@ -7,18 +7,26 @@ const SLASHES_REGEX = /^\/|\/+$/g;
|
||||
export const defaultKeyGenerator: KeyGenerator = ({
|
||||
baseURL = '',
|
||||
url = '',
|
||||
method: nullableMethod,
|
||||
method,
|
||||
params,
|
||||
id
|
||||
}) => {
|
||||
if (id) return String(id);
|
||||
if (id) {
|
||||
return id;
|
||||
}
|
||||
|
||||
// Remove trailing slashes
|
||||
baseURL = baseURL.replace(SLASHES_REGEX, '');
|
||||
url = url.replace(SLASHES_REGEX, '');
|
||||
|
||||
const method = nullableMethod?.toLowerCase() || 'get';
|
||||
const jsonParams = params ? JSON.stringify(params, Object.keys(params).sort()) : '{}';
|
||||
|
||||
return `${method}::${baseURL + (url && baseURL ? '/' : '') + url}::${jsonParams}`;
|
||||
return `${
|
||||
// method
|
||||
method?.toLowerCase() || 'get'
|
||||
}::${
|
||||
// complete url
|
||||
baseURL + (baseURL && url ? '/' : '') + url
|
||||
}::${
|
||||
//params
|
||||
params ? JSON.stringify(params, Object.keys(params).sort()) : '{}'
|
||||
}`;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user