0.4.0 • Published 6 years ago
axios-case-converter-updated v0.4.0
axios-case-converter-updated
Axios transformer/interceptor that converts snake_case/camelCase
- Converts outgoing
dataparamsobject keys into snake_case - Converts incoming
dataobject keys into camelCase - Converts outgoing
headersobject keys into Header-Case - Converts incoming
headersobject keys into camelCase
Usage
You can fully use camelCase.
import applyConverters from 'axios-case-converter-updated';
import axios from 'axios';
(async () => {
const client = applyConverters(axios.create());
const { data } = await client.post(
'https://example.com/api/endpoint',
{
targetId: 1
},
{
params: { userId: 1 },
headers: { userAgent: 'Mozilla' }
}
);
console.log(data.actionResult.users[0].screenName);
})();Attention
FormData compatibility
If you use FormData on Internet Explorer or Safari, you need polyfill of FormData.prototype.entries().
If you use FormData on React Native, please ignore the following warnings after confirming that polyfill is impossible.
// RN >= 0.52
import { YellowBox } from 'react-native';
YellowBox.ignoreWarnings([
'Be careful that FormData cannot be transformed on React Native.'
]);
// RN < 0.52
console.ignoredYellowBox = [
'Be careful that FormData cannot be transformed on React Native.'
];Symbol compatibility
If you use React Native for Android development, you should use Symbol polyfill from core-js to avoid bugs with iterators:
- Create
polyfill.jsin root directory with code:
global.Symbol = require('core-js/es6/symbol');
require('core-js/fn/symbol/iterator');- Include
polyfill.jsin entry point of your app (e.g.app.js):
import { Platform } from 'react-native';
// ...
if (Platform.OS === 'android') {
require('./polyfill.js');
}0.4.0
6 years ago