Network Powering Makers

    proxy-object-defaults

    1.1.0 • Public • Published

    proxy-object-defaults

    Makes nested JS objects easier to reason with. An experiment in using ES6 proxies (for fun and profit).

    Install

    yarn add proxy-object-defaults

    Example

    import proxyDefaults from 'proxy-object-defaults';
     
    const DEFAULT = {
        filter: {
            showTimes: false,
            maxItems: 10
        }
    }
     
    let userSettings = {
        filter: {
            maxItems: 20
        }
    }
     
    let settings = proxyDefaults(userSettings, DEFAULT);
    console.log(settings.filter);
    // filter: {
    //     showTimes: false,
    //     maxItems: 20
    // }
     
    console.log(settings)
    // filter: {
    //    maxItems: 20
    // }
     
    delete settings.filter;
    console.log(settings)
    // {}

    Usage

    proxyDefaults(obj, defaults, deepClone=true)

    Install

    npm i proxy-object-defaults

    DownloadsWeekly Downloads

    0

    Version

    1.1.0

    License

    GPL-3.0

    Unpacked Size

    185 kB

    Total Files

    7

    Last publish

    Collaborators

    • liamzebedee