Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function dispatch (action) {
self.lastAction = action;
if (typeof action === 'undefined') {
return;
}
if (is.promise(action)) { // promise middleware
self.status = YIELDING;
return action.then(f => {
self.status = IDLE;
self.run([f]);
});
}
if (action === null || typeof action.type === 'undefined') {
return stackPush(action);
}
let tokenValue = action.value;
switch (action.type) {
case '@@Action':
if (isImmediate(action)) {
},
get: () => prefixUrl
});
// Make it possible to remove default headers
for (const [key, value] of Object.entries(normalizedOptions.headers)) {
if (is.undefined(value)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete normalizedOptions.headers[key];
}
}
for (const hook of normalizedOptions.hooks.init) {
const result = hook(normalizedOptions);
if (is.promise(result)) {
throw new TypeError('The `init` hook must be a synchronous function');
}
}
return normalizedOptions;
};
url = urlToOptions(new URL(url, options.baseUrl));
} else {
url = url.replace(/^unix:/, 'http://$&');
url = urlParseLax(url);
}
} else if (is(url) === 'URL') {
url = urlToOptions(url);
}
// Override both null/undefined with default protocol
options = merge({path: ''}, url, {protocol: url.protocol || 'https:'}, options);
for (const hook of options.hooks.init) {
const called = hook(options);
if (is.promise(called)) {
throw new TypeError('The `init` hook must be a synchronous function');
}
}
const {baseUrl} = options;
Object.defineProperty(options, 'baseUrl', {
set: () => {
throw new Error('Failed to set baseUrl. Options are normalized already.');
},
get: () => baseUrl
});
const {query} = options;
if (is.nonEmptyString(query) || is.nonEmptyObject(query) || query instanceof URLSearchParams) {
if (!is.string(query)) {
options.query = (new URLSearchParams(query)).toString();
testError.stack = arg.replace(errorMessage, '').trim();
return formatError(testError);
}
// This hack lets chalk template our strings, like '{blue i am blue}'
const array = [arg] as TemplateStringsArray;
array.raw = [arg.replace(/\\/g, '\\\\')];
try {
return chalk(array);
} catch {
// If chalk has errors just return original
}
return arg;
}
if (is.promise(arg)) {
return chalk`{blue [Promise]}`;
}
if (is.error(arg)) {
return formatError(arg);
}
if (is.generator(arg) || is.generatorFunction(arg)) {
return chalk`{blue [Generator]}`;
}
return formatObject(arg);
};