0.3.1 • Published 10 years ago

mixit v0.3.1

Weekly downloads
10
License
MIT
Repository
github
Last release
10 years ago

mixit

a smart mixin helper method to provide object property mixin.

Why ?

This library is a small helper to enable the mix of two objects while merging object properties. It is different from _.extend which override a property already define, while mixit enables the merge of the two object.

var a = {
  name: {
    firstname: 'foo',
    lastname: 'bar'
  },
};


var b = {
  name: {
    alias: 'foo'
  }
});

// extending the a object with b
_.extend({}, a, b);
/*
{
  name: {
    alias: 'foo',
  }
}
*/

// merging the two objects
mixit({}, a, b);
/*
{
  name: {
    firstname: 'foo',
    lastname: 'bar',
    alias: 'foo',
  }
}
*/

It has no external dependency, and weight about ~1.3kB and 590B minified. With gzip compression this small library should have not any impact on the size of your site, SPA or whatever!

Installation

Using npm:

$ npm install mixit

For frontend dependencies:

$ bower install --save mixit

Usage

  • CommonJS:
var mixit = require('mixit');

var obj = {
  name: {
    firstname: 'foo',
    lastname: 'bar'
  },
};

mixit(obj, {
  name: {
    alias: 'foo'
  }
});

console.log(obj.name.alias); // 'foo'
  • AMD
define(['mixit'], function (mixit) {
  var obj = {
    name: {
      firstname: 'foo',
      lastname: 'bar'
    },
  };

  mixit(obj, {
    name: {
      alias: 'foo'
    }
  });

  return obj;
})
  • Browser
<script src="mixit.js"></script>
<script>
  var obj = {
    name: {
      firstname: 'foo',
      lastname: 'bar'
    },
  };

  mixit(obj, {
    name: {
      alias: 'foo'
    }
  });

  console.log(obj.name.alias); // 'foo'
</script>
0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago