Skip to content

Commit

Permalink
fix: custom header of different casing
Browse files Browse the repository at this point in the history
  • Loading branch information
csgulati09 committed Jan 10, 2025
1 parent ce11b09 commit 5f5d802
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/apis/createHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@ export const createHeaders = (
if (config['forwardHeaders']) {
// logic to convert forwardHeaders values to kebab-case
forwardHeaders = config['forwardHeaders'].map((header: string) => {
return header
.replace('ID', 'Id')
.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
return (
header
.replace('ID', 'Id')
// Handle consecutive capitals (acronyms)
.replace(
/([A-Z]+)([A-Z][a-z])/g,
(_, group1, group2) =>
`${group1.toLowerCase()}-${group2.toLowerCase()}`
)
// Handle first letter
.replace(/^[A-Z]/, (letter) => letter.toLowerCase())
// Handle remaining capital letters
.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`)
);
});
}

Expand All @@ -37,6 +48,14 @@ export const createHeaders = (

k = k
.replace('ID', 'Id')
// Handle consecutive capitals (acronyms)
.replace(
/([A-Z]+)([A-Z][a-z])/g,
(_, group1, group2) => `${group1.toLowerCase()}-${group2.toLowerCase()}`
)
// Handle first letter
.replace(/^[A-Z]/, (letter) => letter.toLowerCase())
// Handle remaining capital letters
.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
if (!isEmpty(v) && typeof v == 'object') {
v = JSON.stringify(v);
Expand Down

0 comments on commit 5f5d802

Please sign in to comment.