Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
axios-case-converter
Advanced tools
Axios transformer/interceptor that converts snake_case/camelCase
Axios transformer/interceptor that converts snake_case/camelCase
data
params
object keys into snake_casedata
object keys into camelCaseheaders
object keys into Header-Caseheaders
object keys into camelCasenpm install axios-case-converter
[!IMPORTANT]
Axios is a peer dependency of axios-case-converter and must be installed separately.
npm install axios
<script src="https://unpkg.com/axios-case-converter@latest/dist/axios-case-converter.min.js"></script>
It is strongly recommended that you replace latest
with a fixed version.
You can fully use camelCase in your JavaScript codes.
import applyCaseMiddleware from 'axios-case-converter';
import axios from 'axios';
(async () => {
const client = applyCaseMiddleware(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);
})();
const client = applyCaseMiddleware(axios.create(), options);
preservedKeys
: string[] | Function
Disable transformation when the string matched or satisfied the condition.
const options = {
preservedKeys: ['preserve_this_key_1', 'preserve_this_key_2']
};
const options = {
preservedKeys: (input) => {
return ['preserve_this_key_1', 'preserve_this_key_2'].includes(input);
}
};
ignoreHeaders
: boolean
Disable HTTP headers transformation.
const options = {
ignoreHeaders: true
};
ignoreParams
: boolean
Disable HTTP URL parameters transformation.
const options = {
ignoreParams: true
};
caseFunctions
: { snake?: Function, camel?: Function, header?: Function }
Override built-in change-case
functions.
const options = {
caseFunctions: {
camel: (input, options) => {
return (input.charAt(0).toLowerCase() + input.slice(1)).replace(/[-_](.)/g, (match, group1) => group1.toUpperCase());
}
}
};
caseOptions
: { stripRegexp?: RegExp }
By default, { stripRegexp: /[^A-Z0-9[\]]+/gi }
is used as default change-case
function options.
This preserves []
chars in object keys.
If you wish keeping original change-case
behavior, override the options.
const options = {
caseOptions: {
stripRegexp: /[^A-Z0-9]+/gi
}
};
caseMiddleware
: { requestTransformer?: Function, responseTransformer?: Function, requestInterceptor?: Function }
Totally override axios-case-converter
behaviors.
const options = {
caseMiddleware: {
requestInterceptor: (config) => {
// Disable query string transformation
return config;
}
}
};
[!WARNING]
Object
compatibilityIf you run on Internet Explorer, you need polyfill for
Object.prorotypte.entries()
.
[!WARNING]
FormData
compatibilityIf you use
FormData
on Internet Explorer, you need polyfill ofFormData.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.' ];
[!WARNING]
Symbol
compatibilityIf you use React Native for Android development, you should use Symbol polyfill from
core-js
to avoid bugs with iterators:
- Create
polyfill.js
in root directory with code:
global.Symbol = require('core-js/es6/symbol'); require('core-js/fn/symbol/iterator');
- Include
polyfill.js
in entry point of your app (e.g.app.js
):
import { Platform } from 'react-native'; // ... if (Platform.OS === 'android') { require('./polyfill.js'); }
FAQs
Axios transformer/interceptor that converts snake_case/camelCase
The npm package axios-case-converter receives a total of 50,282 weekly downloads. As such, axios-case-converter popularity was classified as popular.
We found that axios-case-converter demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.