dist/bbn.js
/**
     * Merges the contents of two or more objects together into the first object.
     * 
     * A boolean true argument can be done to operate a deep extend. In this case, 
     * the content of properties or subproperties arrays and objects will also be merged.
     *
     * @method   extend
     * @global
     * @example
     * ```javascript
     * bbn.fn.extend(
     *   {prop1: 10, prop2: 20},
     *   {prop1: 11, prop3: 21},
     *   {prop2: 22, prop4: false},
     *   {prop5: false, prop3: 45}
     * );
     * // {prop1: 11, prop2: 22, prop3: 45, prop4: false, prop5: false}
     * ```
     * @example
     * ```javascript
     * bbn.fn.extend(
     *   {
     *     prop1: [3, 5, 6],
     *     prop2: {
     *       subprop1: 87,
     *       subprop2: 100
     *     }
     *   }, {
     *     prop1: 11,
     *     prop3: [8, 12, {aProperty: 1, anotherProperty: true}, 26]
     *   }, {
     *     prop2: {
     *       subprop1: 90,
     *       subprop3: 25
     *     },
     *     prop4: false
     *   }, {
     *     prop5: false,
     *     prop3: [8, 45, {anotherProperty: false, andAnother: true}]
     *   }
     * );
     * // {
     * //   prop1: 11,
     * //   prop2: {subprop1: 90, subprop3: 25},
     * //   prop3: [8, 45, {anotherProperty: false, andAnother: true}],
     * //   prop4: false,
     * //   prop5: false
     * // }
     * ```
     * @example
     * ```javascript
     * // Deep
     * bbn.fn.extend(
     *   true, 
     *   {
     *     prop1: [3, 5, 6],
     *     prop2: {
     *       subprop1: 87,
     *       subprop2: 100
     *     }
     *   }, {
     *     prop1: 11,
     *     prop3: [8, 12, {aProperty: 1, anotherProperty: true}, 26]
     *   }, {
     *     prop2: {
     *       subprop1: 90,
     *       subprop3: 25
     *     },
     *     prop4: false
     *   }, {
     *     prop5: false,
     *     prop3: [8, 45, {anotherProperty: false, andAnother: true}]
     *   }
     * );
     * // {
     * //   prop1: 11,
     * //   prop2: {subprop1: 90, subprop3: 25},
     * //   prop3: [8, 45, {aProperty: 1, anotherProperty: false, andAnother: true}, 26],
     * //   prop4: false,
     * //   prop5: false
     * // }
     * ```
     * @memberof bbn.fn
     * @returns  {Object} The first object argument, merged with the other objects given
     */
Merges the contents of two or more objects together into the first object.

A boolean true argument can be done to operate a deep extend. In this case,
the content of properties or subproperties arrays and objects will also be merged.


Merges the contents of two or more objects together into the first object . A boolean true argument can be done to operate a deep extend . In this case the content of properties or subproperties arrays and objects will also be merged .
extend(){
      let deep = false;
      let args = [];
      for ( let i = 0; i < arguments.length; i++ ){
        if ( arguments[i] === true ){
          deep = true;
        }
        else if ( !arguments[i] ){
          continue;
        }
        else if ( typeof arguments[i] !== 'object' ){
          throw new Error(bbn._("Error in bbn.fn.extend: all arguments should be object, you have given ") + typeof(arguments[i]));
        }
        else{
          args.push(arguments[i]);
        }
      }
      if ( !args.length ){
        throw new Error("No argument given");
      }
      let out = args[0];
      for ( let i = 1; i < args.length; i++ ){
        bbn.fn.iterate(args[i], (a, key) => {
          if ( deep ){
            if ( bbn.fn.isArray(a) ){
              out[key] = bbn.fn.isArray(out[key]) ? out[key] : [];
              bbn.fn.each(a, (b, i) => {
                if ( b && (typeof b === 'object') ){
                  let tmp = out[key][i];
                  if (bbn.fn.isArray(b)) {
                    if (!bbn.fn.isArray(tmp)) {
                      tmp = [];
                    }
                  } 
                  else if (!bbn.fn.isObject(tmp)) {
                    tmp = {};
                  }
                  out[key][i] = bbn.fn.extend(true, tmp, b);
                }
                else{
                  out[key][i] = b;
                }
              });
            }
            else if ( bbn.fn.isObject(a) ){
              out[key] = bbn.fn.extend(true, out[key] && (typeof out[key] === 'object') ? out[key] : {}, a);
            }
            else{
              out[key] = a;
            }
          }
          else if ( out[key] !== a ){
            out[key] = a;
          }
        });
      }
      return out;
    }
extend ( ) { let deep = false ; let args = [ ] ; for ( let i = 0 ; i < arguments . length ; i ++ ) { if ( arguments [ i ] === true ) { deep = true ; } else if ( ! arguments [ i ] ) { continue ; } else if ( typeof arguments [ i ] !== 'object' ) { throw new Error ( bbn . _ ( "Error in bbn.fn.extend: all arguments should be object, you have given " ) + typeof ( arguments [ i ] ) ) ; } else { args . push ( arguments [ i ] ) ; } } if ( ! args . length ) { throw new Error ( "No argument given" ) ; } let out = args [ 0 ] ; for ( let i = 1 ; i < args . length ; i ++ ) { bbn . fn . iterate ( args [ i ] , ( a , key ) => { if ( deep ) { if ( bbn . fn . isArray ( a ) ) { out [ key ] = bbn . fn . isArray ( out [ key ] ) ? out [ key ] : [ ] ; bbn . fn . each ( a , ( b , i ) => { if ( b && ( typeof b === 'object' ) ) { let tmp = out [ key ] [ i ] ; if ( bbn . fn . isArray ( b ) ) { if ( ! bbn . fn . isArray ( tmp ) ) { tmp = [ ] ; } } else if ( ! bbn . fn . isObject ( tmp ) ) { tmp = { } ; } out [ key ] [ i ] = bbn . fn . extend ( true , tmp , b ) ; } else { out [ key ] [ i ] = b ; } } ) ; } else if ( bbn . fn . isObject ( a ) ) { out [ key ] = bbn . fn . extend ( true , out [ key ] && ( typeof out [ key ] === 'object' ) ? out [ key ] : { } , a ) ; } else { out [ key ] = a ; } } else if ( out [ key ] !== a ) { out [ key ] = a ; } } ) ; } return out ; }
Merges the contents of two or more objects together into the first object.
Merges the contents of two or more objects together into the first object .