From b6cf156ac0a433429ccff1297f89da9f410ccfdb Mon Sep 17 00:00:00 2001
From: Commander-lol <ljcapitanio@gmail.com>
Date: Wed, 1 Jul 2015 01:52:16 +0100
Subject: [PATCH] Updated json.merge to better handle undefined input

---
 bower.json          |  2 +-
 dist/tinydom.js     | 31 +++++++++++++++++++++++++++++--
 dist/tinydom.min.js |  4 ++--
 package.json        |  2 +-
 src/Json.js         | 31 +++++++++++++++++++++++++++++--
 5 files changed, 62 insertions(+), 8 deletions(-)

diff --git a/bower.json b/bower.json
index e09ff0d..b1103c2 100644
--- a/bower.json
+++ b/bower.json
@@ -1,6 +1,6 @@
 {
   "name": "tinyDOM",
-  "version": "1.0.3",
+  "version": "1.0.7",
   "homepage": "https://github.com/Commander-lol/tinyDOM",
   "moduleType": [
     "globals"
diff --git a/dist/tinydom.js b/dist/tinydom.js
index ffc9dce..2060d0a 100644
--- a/dist/tinydom.js
+++ b/dist/tinydom.js
@@ -217,6 +217,13 @@ tinyDOM.triggerOn = function (target, eventName, data, bubbles, cancelable) {
 };
 
 tinyDOM.json = {
+    /**
+     * Gets the keyset of an object
+     * @param   {Object} json The object whose keys are to be
+     *                      retrieved
+     * @returns {Array}  An array of Strings corresponding to
+     *                   the properties of an object
+     */
     keys: function(json) {
         var kys = [],
             indx;
@@ -227,6 +234,13 @@ tinyDOM.json = {
         }
         return kys;
     },
+    /**
+     * Determines if the parameter represents a valid json object
+     * @param   {String}  obj The string to be checked regarding its
+     *                      validity as a JSON object
+     * @returns {Boolean} Whether or not obj represents a valid json
+     *                    object
+     */
     is: function (obj) {
         try {
             JSON.parse(obj);
@@ -235,9 +249,22 @@ tinyDOM.json = {
             return false;
         }
     },
+    /**
+     * Takes two objects and adds the properties of the second to the
+     * first, with those of the second taking presedence in cases where
+     * both objects intersect
+     * @param   {Object} json1 The first object to combine
+     * @param   {Object} json2 The second object to combine
+     * @returns {Object} If json1 is undefined, returns json2. Otherwise returns
+     *                   json1. In cases where json2 is undefined, json1 will be
+     *                   unchanged, otherwise json1 will contain all the properties
+     *                   of json2.
+     */
     merge: function (json1, json2) {
-		if (!this.exists(json1) || !this.exists(json2)) {
-			return null;
+		if (!this.exists(json1)) {
+            return json2;
+        } else if (!this.exists(json2)) {
+			return json1;
 		} else {
             var prop;
 			for (prop in json2) {
diff --git a/dist/tinydom.min.js b/dist/tinydom.min.js
index 720120d..a1521c1 100644
--- a/dist/tinydom.min.js
+++ b/dist/tinydom.min.js
@@ -1,2 +1,2 @@
-/*! tinydom 2015-06-30 */
-!function(){"use strict";var a,b,c;Element&&!Element.prototype.matches&&(a=Element.prototype,a.matches=a.matchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector),b=function(a){var c,d,e;if(!(this instanceof b))return new b(a);if(null===a||"undefined"==typeof a)this.length=0;else if(a.substring)for(c=document.querySelectorAll(a),this.length=c.length,d=0;d<c.length;d++)e=c.item(d),this[d]=e;else if(a.push){for(d=0;d<a.length;d++)e=a[d],this[d]=e;this.length=a.length}else this[0]=a,this.length=1;return this.apiversion="1",this},c=function(a){return new b(a)},window.μ||(window.μ=c),window.mu||(window.mu=c),c.fn=b.prototype={each:function(a){for(var b=this.length;b--;)a(b,this[b],this);return this},on:function(a,b,c){return"string"==typeof b?this.each(function(d,e){e.addEventListener(a,function(a){var d=a.target,f=!1;do d&&d.matches(b)?(c.call(d,a),f=!0):(d=d.parentNode,d&&d.matches&&d!==e||(f=!0));while(f!==!0)})}):(c=b,this.each(function(b,d){d.addEventListener(a,c)})),this},first:function(){return"undefined"!=typeof this[0]?c(this[0]):null},parent:function(a){var b=this[0].parentNode,d=!0;if(c.exists(a)){for(;null!==b&&b!==document;){if(b.matches(a)){d=!1;break}b=b.parentNode}b=d?null:b}return c(b)},children:function(a){var b,d=this[0].childNodes,e=[];for(b=0;b<d.length;b++)c.isElement(d[b])&&(mu.exists(a)?d[b].matches(a)&&e.push(d[b]):e.push(d[b]));return c(e)},data:function(a,b){return"undefined"!=typeof b?(this.each(function(c,d){d.setAttribute("data-"+a,b)}),this):this[0].getAttribute("data-"+a)},attr:function(a,b){return"undefined"!=typeof b?(this.each(function(c,d){d.setAttribute(a,b)}),this):this[0].getAttribute(a)},"class":function(a,b){return c.exists(b)?this.each(function(c,d){d.classList.toggle(a,b)}):this.each(function(b,c){c.classList.toggle(a)}),this},clear:function(){this.each(function(a,b){for(;b.firstChild;)b.removeChild(b.firstChild)})},trigger:function(a,b,d,e){d=c.exists(d)?d:!0,e=c.exists(e)?e:!0;var f=new CustomEvent(a,b,d,e);return this.each(function(a,b){b.dispatchEvent(f)}),this}},c.ready=function(a){document.addEventListener("DOMContentLoaded",a)},c.isElement=function(a){var b=!1;try{b=a instanceof HTMLElement}catch(c){b=a.nodeType&&1===a.nodeType}return b},c.exists=function(a){return null!==a&&"undefined"!=typeof a},c.byID=function(a){return c(document.getElementById(a))},c.triggerOn=function(a,b,d,e,f){e=c.exists(e)?e:!0,f=c.exists(f)?f:!0,a.dispatchEvent(new CustomEvent(b,d,e,f))},c.json={keys:function(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c},is:function(a){try{return JSON.parse(a),null!==a&&"undefined"!=typeof a}catch(b){return!1}},merge:function(a,b){if(this.exists(a)&&this.exists(b)){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}return null}},c.ajax=function(a){var b,c,d=new XMLHttpRequest,e={method:"GET",url:"",async:!0,user:null,password:null,responseType:"text",data:null,headers:[],callbacks:{}},f=function(a){return function(b){a(b.currentTarget.response,b)}};if(this.merge(e,a),d.responseType=e.responseType,this.exists(e.callbacks))for(b in e.callbacks)e.callbacks.hasOwnProperty(b)&&d.addEventListener(b,f(e.callbacks[b]));for(d.open(e.method,e.url,e.async,e.user,e.password),c=0;c<e.headers.length;c++)d.setRequestHeader(e.headers[c].header,e.headers[c].value);return d.send(e.data),d}}();
+/*! tinydom 2015-07-01 */
+!function(){"use strict";var a,b,c;Element&&!Element.prototype.matches&&(a=Element.prototype,a.matches=a.matchesSelector||a.mozMatchesSelector||a.msMatchesSelector||a.oMatchesSelector||a.webkitMatchesSelector),b=function(a){var c,d,e;if(!(this instanceof b))return new b(a);if(null===a||"undefined"==typeof a)this.length=0;else if(a.substring)for(c=document.querySelectorAll(a),this.length=c.length,d=0;d<c.length;d++)e=c.item(d),this[d]=e;else if(a.push){for(d=0;d<a.length;d++)e=a[d],this[d]=e;this.length=a.length}else this[0]=a,this.length=1;return this.apiversion="1",this},c=function(a){return new b(a)},window.μ||(window.μ=c),window.mu||(window.mu=c),c.fn=b.prototype={each:function(a){for(var b=this.length;b--;)a(b,this[b],this);return this},on:function(a,b,c){return"string"==typeof b?this.each(function(d,e){e.addEventListener(a,function(a){var d=a.target,f=!1;do d&&d.matches(b)?(c.call(d,a),f=!0):(d=d.parentNode,d&&d.matches&&d!==e||(f=!0));while(f!==!0)})}):(c=b,this.each(function(b,d){d.addEventListener(a,c)})),this},first:function(){return"undefined"!=typeof this[0]?c(this[0]):null},parent:function(a){var b=this[0].parentNode,d=!0;if(c.exists(a)){for(;null!==b&&b!==document;){if(b.matches(a)){d=!1;break}b=b.parentNode}b=d?null:b}return c(b)},children:function(a){var b,d=this[0].childNodes,e=[];for(b=0;b<d.length;b++)c.isElement(d[b])&&(mu.exists(a)?d[b].matches(a)&&e.push(d[b]):e.push(d[b]));return c(e)},data:function(a,b){return"undefined"!=typeof b?(this.each(function(c,d){d.setAttribute("data-"+a,b)}),this):this[0].getAttribute("data-"+a)},attr:function(a,b){return"undefined"!=typeof b?(this.each(function(c,d){d.setAttribute(a,b)}),this):this[0].getAttribute(a)},"class":function(a,b){return c.exists(b)?this.each(function(c,d){d.classList.toggle(a,b)}):this.each(function(b,c){c.classList.toggle(a)}),this},clear:function(){this.each(function(a,b){for(;b.firstChild;)b.removeChild(b.firstChild)})},trigger:function(a,b,d,e){d=c.exists(d)?d:!0,e=c.exists(e)?e:!0;var f=new CustomEvent(a,b,d,e);return this.each(function(a,b){b.dispatchEvent(f)}),this}},c.ready=function(a){document.addEventListener("DOMContentLoaded",a)},c.isElement=function(a){var b=!1;try{b=a instanceof HTMLElement}catch(c){b=a.nodeType&&1===a.nodeType}return b},c.exists=function(a){return null!==a&&"undefined"!=typeof a},c.byID=function(a){return c(document.getElementById(a))},c.triggerOn=function(a,b,d,e,f){e=c.exists(e)?e:!0,f=c.exists(f)?f:!0,a.dispatchEvent(new CustomEvent(b,d,e,f))},c.json={keys:function(a){var b,c=[];for(b in a)a.hasOwnProperty(b)&&c.push(b);return c},is:function(a){try{return JSON.parse(a),null!==a&&"undefined"!=typeof a}catch(b){return!1}},merge:function(a,b){if(this.exists(a)){if(this.exists(b)){var c;for(c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}return a}return b}},c.ajax=function(a){var b,c,d=new XMLHttpRequest,e={method:"GET",url:"",async:!0,user:null,password:null,responseType:"text",data:null,headers:[],callbacks:{}},f=function(a){return function(b){a(b.currentTarget.response,b)}};if(this.merge(e,a),d.responseType=e.responseType,this.exists(e.callbacks))for(b in e.callbacks)e.callbacks.hasOwnProperty(b)&&d.addEventListener(b,f(e.callbacks[b]));for(d.open(e.method,e.url,e.async,e.user,e.password),c=0;c<e.headers.length;c++)d.setRequestHeader(e.headers[c].header,e.headers[c].value);return d.send(e.data),d}}();
diff --git a/package.json b/package.json
index fffce53..39b95e8 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "tinydom",
-  "version": "1.0.3",
+  "version": "1.0.7",
   "description": "A simple DOM batch manipulation library",
   "main": "dist/tinydom.js",
   "directories": {
diff --git a/src/Json.js b/src/Json.js
index 8d9c600..c252855 100644
--- a/src/Json.js
+++ b/src/Json.js
@@ -1,4 +1,11 @@
 tinyDOM.json = {
+    /**
+     * Gets the keyset of an object
+     * @param   {Object} json The object whose keys are to be
+     *                      retrieved
+     * @returns {Array}  An array of Strings corresponding to
+     *                   the properties of an object
+     */
     keys: function(json) {
         var kys = [],
             indx;
@@ -9,6 +16,13 @@ tinyDOM.json = {
         }
         return kys;
     },
+    /**
+     * Determines if the parameter represents a valid json object
+     * @param   {String}  obj The string to be checked regarding its
+     *                      validity as a JSON object
+     * @returns {Boolean} Whether or not obj represents a valid json
+     *                    object
+     */
     is: function (obj) {
         try {
             JSON.parse(obj);
@@ -17,9 +31,22 @@ tinyDOM.json = {
             return false;
         }
     },
+    /**
+     * Takes two objects and adds the properties of the second to the
+     * first, with those of the second taking presedence in cases where
+     * both objects intersect
+     * @param   {Object} json1 The first object to combine
+     * @param   {Object} json2 The second object to combine
+     * @returns {Object} If json1 is undefined, returns json2. Otherwise returns
+     *                   json1. In cases where json2 is undefined, json1 will be
+     *                   unchanged, otherwise json1 will contain all the properties
+     *                   of json2.
+     */
     merge: function (json1, json2) {
-		if (!this.exists(json1) || !this.exists(json2)) {
-			return null;
+		if (!this.exists(json1)) {
+            return json2;
+        } else if (!this.exists(json2)) {
+			return json1;
 		} else {
             var prop;
 			for (prop in json2) {
-- 
GitLab