@roots/bud-api
Version:
bud.js core module
52 lines (41 loc) • 1.28 kB
text/typescript
import type {Bud} from '@roots/bud-framework'
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 type {Parameters} from './proxy.types.js'
import {
assignOptions,
assignOptionsCallback,
assignPort,
assignReplacements,
assignUrl,
isFalse,
isOptionsObject,
isUrl,
maybeEnable,
} from './helpers.js'
/**
* bud.proxy interface
*/
export interface proxy {
(...params: Parameters): Promise<Bud>
}
/**
* bud.proxy method
*/
export const proxy: proxy = async function (this: Bud, 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
}