New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mirage-msw

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mirage-msw - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

57

lib/msw-config.js
import { rest, setupWorker } from 'msw';
const defaultRouteOptions = {
coalesce: false,
timing: undefined,
};
/**
* Determine if the object contains a valid option.
*
* @method isOption
* @param {Object} option An object with one option value pair.
* @return {Boolean} True if option is a valid option, false otherwise.
* @private
*/
function isOption(option) {
if (!option || typeof option !== "object") {
return false;
}
let allOptions = Object.keys(defaultRouteOptions);
let optionKeys = Object.keys(option);
for (let i = 0; i < optionKeys.length; i++) {
let key = optionKeys[i];
if (allOptions.indexOf(key) > -1) {
return true;
}
}
return false;
}
/**
* Extract arguments for a route.
*
* @method extractRouteArguments
* @param {Array} args Of the form [options], [object, code], [function, code]
* [shorthand, options], [shorthand, code, options]
* @return {Array} [handler (i.e. the function, object or shorthand), code,
* options].
*/
function extractRouteArguments(args) {
let [lastArg] = args.splice(-1);
if (isOption(lastArg)) {
lastArg = assign({}, defaultRouteOptions, lastArg);
} else {
args.push(lastArg);
lastArg = defaultRouteOptions;
}
let t = 2 - args.length;
while (t-- > 0) {
args.push(undefined);
}
args.push(lastArg);
return args;
}
export default class MswConfig {

@@ -34,3 +88,4 @@ urlPrefix;

this[verb] = (path, ...args) => {
let handler = mirageServer.registerRouteHandler(verb, path, args);
let [rawHandler, customizedCode, options] = extractRouteArguments(args);
let handler = mirageServer.registerRouteHandler(verb, path, rawHandler, customizedCode, options);
let fullPath = this._getFullPath(path);

@@ -37,0 +92,0 @@ let mswHandler = rest[verb](fullPath, async (req, res, ctx) => {

2

package.json
{
"name": "mirage-msw",
"version": "0.1.0",
"version": "0.1.1",
"description": "Allow mirage to use MSW (Mock Service Worker) as the interceptor",

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

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