mpyw / axios-case-converter

Axios transformer/interceptor that converts snake_case/camelCase
MIT License
160 stars 18 forks source link

fix: 🐛 Don't transform number keys #54

Closed mpyw closed 1 year ago

mpyw commented 1 year ago

It might be broken if you customized snake-case functions.

const client = applyCaseMiddleware(axios.create(), {
    caseFunctions: {
        snake: (s) => s.replace(/[A-Z]|\d+/g, (s) => `_${s.toLowerCase()}`),
    },
});

cleint.post({ data: ['X', 'Y']});

The code above actually sends {"data": []} instead of {"data": ["X", "Y"]}because it transforms

Array { 0: 'X', 1: 'Y', length: 2 }

into

Array { '_0': 'X', '_1': 'Y', length: 2 }