@bnidev/js-utils
    Preparing search index...

    Function defaults

    • Fills in default values from source into target object.

      Type Parameters

      • T extends Record<string, unknown>

        The type of the target object.

      • S extends Record<string, unknown>

        The type of the source object.

      Parameters

      • target: T

        The target object to apply defaults to.

      • source: S

        The source object containing default values.

      Returns T & S

      A new object with defaults applied.

      // ES Module
      import { defaults } from '@bnidev/js-utils'

      // CommonJS
      const { defaults } = require('@bnidev/js-utils')
      const config = { timeout: 100 }
      const defaultValues = { timeout: 5000, retries: 3 }
      const result = defaults(config, defaultValues)
      // result: { timeout: 100, retries: 3 }