support merge of objects
This commit is contained in:
		
							parent
							
								
									1e8db3dee4
								
							
						
					
					
						commit
						901ad921c7
					
				
					 1 changed files with 6 additions and 2 deletions
				
			
		|  | @ -44,7 +44,7 @@ nested.dictionary = class dictionary { | ||||||
|      @param {object} value the value to be used |      @param {object} value the value to be used | ||||||
|      @return {object} the data |      @return {object} the data | ||||||
|      */ |      */ | ||||||
|      static set(data, path, value) { |      static set(data, path, value, options = {}) { | ||||||
|           let DATA = data, PATH = path, VALUE = value; |           let DATA = data, PATH = path, VALUE = value; | ||||||
| 
 | 
 | ||||||
|           // Convert path into an array if not yet set.
 |           // Convert path into an array if not yet set.
 | ||||||
|  | @ -58,8 +58,12 @@ nested.dictionary = class dictionary { | ||||||
|           if (PATH[`target`].length > 0) { |           if (PATH[`target`].length > 0) { | ||||||
|                (DATA[PATH[`current`]] == null) ? DATA[PATH[`current`]] = {} : false; |                (DATA[PATH[`current`]] == null) ? DATA[PATH[`current`]] = {} : false; | ||||||
|                DATA[PATH[`current`]] = nested.dictionary.set(DATA[PATH[`current`]], PATH[`target`], VALUE); |                DATA[PATH[`current`]] = nested.dictionary.set(DATA[PATH[`current`]], PATH[`target`], VALUE); | ||||||
|  |           } else { | ||||||
|  |                if ((typeof DATA[PATH[`current`]]).includes(`obj`) && (typeof VALUE).includes(`obj`) && !Array.isArray(DATA[PATH[`current`]]) && !Array.isArray(VALUE) && DATA[PATH[`current`]] && VALUE && ((options && (typeof options).includes(`obj`)) ? (options[`strict`] || options[`override`]) : true)) { | ||||||
|  |                     Object.assign(DATA[PATH[`current`]], VALUE); | ||||||
|                } else { |                } else { | ||||||
|                     DATA[PATH[`current`]] = VALUE; |                     DATA[PATH[`current`]] = VALUE; | ||||||
|  |                }; | ||||||
|           } |           } | ||||||
| 
 | 
 | ||||||
|           // Return the value.
 |           // Return the value.
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue