• Assigns own enumerable properties of source objects to the destination object for all destination properties that resolve to undefined.

    This function fills in undefined properties in an object with the first value present in any of the source objects. Source objects are applied from left to right.

    Parameters

    • obj: Record<string, unknown>

      The destination object.

    • ...sources: Record<string, unknown>[]

      The source objects.

    Returns Record<string, unknown>

    The destination object.

    import { defaults } from './AcCmLodashUtils'

    const object = { a: 1 }
    const result = defaults(object, { b: 2 }, { a: 3, c: 3 })
    console.log(result) // { a: 1, b: 2, c: 3 }

    // undefined properties are filled in
    const partial = { a: 1, b: undefined }
    defaults(partial, { b: 2, c: 3 })
    console.log(partial) // { a: 1, b: 2, c: 3 }