assign-default-values-to-object
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.2 • Public • Published

    Assign default values to object

    An npm module exporting a function to assign default values to an object.

    Installing

    npm i assign-default-values-to-object

    Basic Usage

    import assignDefaultValuesToObject, { RecursiveRequired } from "assign-default-values-to-object";
     
    interface IObject {
        requiredProp: string;
        optionalProp1?: string;
        optionalProp2?: string;
    }
     
    const object: IObject = {
        requiredProp: "objectRequiredProp",
        optionalProp1: "objectOptionalProp1"
    };
     
    const defaultObject: IObject = {
        requiredProp: "defaultObjectRequiredProp",
        optionalProp1: "defaultObjectOptionalProp1",
        optionalProp2: "defaultObjectOptionalProp2"
    };
     
    const parsedObject = assignDefaultValuesToObject(defaultObject, object) as RecursiveRequired<
        IObject
    >;
     
    console.log(parsedObject.requiredProp)
    // objectRequiredProp
     
    console.log(parsedObject.optionalProp1)
    // objectOptionalProp1
     
    console.log(parsedObject.optionalProp2)
    // defaultObjectOptionalProp2

    Contributing

    Please read CONTRIBUTING.md.

    Install

    npm i assign-default-values-to-object

    DownloadsWeekly Downloads

    13

    Version

    1.0.2

    License

    GPL-3.0-only

    Unpacked Size

    50.6 kB

    Total Files

    14

    Last publish

    Collaborators

    • straight-outta-crompton