Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    compare-structurepublic

    compare-structure

    compare the structure of two objects

    Usage

    pass an object, and a comparison object:

        var someObject = {
            foo: {
                bar: 3
            },
            baz: { // <------- Additional structure, will pass normal comparison.
                majigger: 1
            }
        };
    
        var expectedStructure = {
            foo:{
                bar: null
            },
            baz: null
        };
    
        compare(someObject, expectedStructure); // -> true
    

    You can optionally pass true as the third parameter to fail if the structure contains additional keys/objects:

        var someObject = {
            foo: {
                bar: 3
            },
            baz: { // <------- Additional structure, will fail a strict comparison.
                majigger: 1
            }
        };
    
        var expectedStructure = {
            foo:{
                bar: null
            },
            baz: null
        };
    
        compare(someObject, expectedStructure, true); // -> false
    

    Keywords

    none

    install

    npm i compare-structure

    Downloadsweekly downloads

    2

    version

    1.0.1

    license

    ISC

    repository

    githubgithub

    last publish

    collaborators

    • avatar