Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

axios-mock-shim

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

axios-mock-shim - npm Package Compare versions

Comparing version 1.0.5 to 1.0.6

6

dist/request.js
/* eslint-disable */
const MockAdapter = require('axios-mock-adapter');
import { firstUp, isArray, isFn, stringify, warn } from './utils';
import { snakifyKeys, firstUp, isArray, isFn, stringify, warn } from './utils';
import { mockDefaultConfig, httpMethodList } from './config';

@@ -102,3 +102,3 @@ // Cache for whole page

const { $instance, $options } = this;
const { beforeResponse } = $options;
const { beforeResponse, snakifyData } = $options;
if (!httpMethodList.has(method.toUpperCase()))

@@ -111,5 +111,5 @@ return warn('Invalid http method', method);

? 'params'
: 'data']: data,
: 'data']: snakifyData ? snakifyKeys(data) : data,
}).then(beforeResponse ? beforeResponse : (res) => res);
},
};

@@ -0,1 +1,25 @@

function camelizeStr(str) {
return str.replace(/[_.-](\w|$)/g, (_, x) => x.toUpperCase());
}
function snakifyStr(str) {
return str.replace(/(?:^|\.?)([A-Z])/g, (_, x) => `_${x.toLowerCase()}`);
}
function convertCase(convertFunc) {
function converter(thing) {
if (thing instanceof Array) {
return thing.map((i) => converter(i));
}
if (thing instanceof Object) {
const newObj = {};
Object.keys(thing).forEach((k) => {
newObj[convertFunc(k)] = converter(thing[k]);
});
return newObj;
}
return thing;
}
return converter;
}
export const camelizeKeys = convertCase(camelizeStr);
export const snakifyKeys = convertCase(snakifyStr);
export function isFn(v) {

@@ -2,0 +26,0 @@ return v !== null && typeof v === 'function';

{
"name": "axios-mock-shim",
"version": "1.0.5",
"version": "1.0.6",
"description": "A plugin build for easily using axios-mock-adapter with axios",

@@ -5,0 +5,0 @@ "main": "./index.js",

@@ -140,2 +140,7 @@ # Axios Mock Shim

### snakifyData
Whether snakify keys in params or data in request.
### beforeResponse

@@ -142,0 +147,0 @@

@@ -16,2 +16,3 @@ export interface MockAdapterOptions {

beforeResponse?: Function;
snakifyData?: boolean;
}

@@ -18,0 +19,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc