GithubHelp home page GithubHelp logo

object-compare's Introduction

A object compare module

Installation

    npm install object-compare-function --save

Usage

    var compare = require('object-compare-function');
    var result = compare({name: 'object1'}, {name: 'object2'});

    console.log(result);

Test

    var assert = require('assert');
    var compare = require('./index.js');

    var result = compare({l: 1}, {l: 1});
    assert(true === result, 'expected true');

    result = compare({l: 1}, {l: 2});
    assert(false === result, 'expected false');

    result = compare({l: 1, key: {}}, {l: 1, key: {}});
    assert(true === result, 'expected true');

    result = compare({l: 1, key: {}}, {l: 1, key: null});
    assert(false === result, 'expected false');

    result = compare({l: 1, key: null}, {l: 1, key: null});
    assert(true === result, 'expected true');

    result = compare({l: 1, key: null}, {l: 1, key: undefined});
    assert(false === result, 'expected false');

    result = compare({
        level: 1,
            one: {
            level: '2',
            two: {
                level: 3,
                three: [{
                    'four-1': [1, '2', {five: 'deep'}],
                    'four-2': [1, 2, 3, ['a', 'b', 'c']]
                }]
            }
          },
          name: 'object'
    }, {
        level: 1,
        one: {
            level: '2',
            two: {
                level: 3,
                three: [{
                    'four-1': [1, '2', {five: 'deep'}],
                    'four-2': [1, 2, 3, ['a', 'b', 'c']]
                }]
            }
        },
        name: 'object'
    });
    assert(true === result, 'expected true');

    result = compare({
        level: 1,
        one: {
            level: '2',
            two: {
                level: 3,
                three: [{
                    'four-1': [1, '2', {five: 'deep???'}],
                    'four-2': [1, 2, 3, ['a', 'b', 'c']]
                }]
            }
        },
        name: 'object'
    }, {
        level: 1,
        one: {
            level: '2',
            two: {
                level: 3,
                three: [{
                    'four-1': [1, '2', {five: 'deep'}],
                    'four-2': [1, 2, 3, ['a', 'b', 'c']]
                }]
            }
        },
        name: 'object'
    });
    assert(false === result, 'expected false');

    result = compare([{}, [{key: null}]], [{}, [{key: null}]]);
    assert(true === result, 'expected true');

    result = compare([{}, [{key: null}]], [{}, [{key: undefined}]]);
    assert(false === result, 'expected false');

Note

This module use === operator instead of == operator, so you will get false when {key: false} {key: null} {key: undefined} {key: 0} {key: NaN} {key: ''} is compared each other.

object-compare's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.