@roots/bud-api
Version:
bud.js core module
31 lines (30 loc) • 1.14 kB
JavaScript
import isArray from '@roots/bud-support/isArray';
import isFunction from '@roots/bud-support/isFunction';
import isNumber from '@roots/bud-support/isNumber';
import isString from '@roots/bud-support/isString';
import isUndefined from '@roots/bud-support/isUndefined';
import { assignOptions, assignOptionsCallback, assignPort, assignReplacements, assignUrl, isFalse, isOptionsObject, isUrl, maybeEnable, } from './helpers.js';
/**
* bud.proxy method
*/
export const proxy = async function (input, options) {
// Bail early in production
if (!this.isDevelopment)
return this;
maybeEnable(this, input);
if (isFalse(input) || isUndefined(input))
return this;
if (isString(input) || isUrl(input))
assignUrl(this, input);
if (isNumber(input))
assignPort(this, input);
if (isFunction(input))
assignOptionsCallback(this, input);
if (isOptionsObject(input))
assignOptions(this, input);
if (isArray(options) || isFunction(options))
assignReplacements(this, options);
if (isOptionsObject(options))
assignOptions(this, options);
return this;
};