| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | /********************************************************************** | 
					
						
							|  |  |  | *  | 
					
						
							|  |  |  | * | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | * XXX shoule we add these from object to Object? | 
					
						
							|  |  |  | * 		- .parent(..) | 
					
						
							|  |  |  | * 		- .parentProperty(..) | 
					
						
							|  |  |  | * 		- .parentCall(..) | 
					
						
							|  |  |  | * 		- .parentOf(..) | 
					
						
							|  |  |  | * 		- .childOf(..) | 
					
						
							|  |  |  | * 		- .related(..) | 
					
						
							|  |  |  | * | 
					
						
							| 
									
										
										
										
											2020-10-06 01:32:33 +03:00
										 |  |  | **********************************************/  /* c8 ignore next 2 */ | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | ((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define) | 
					
						
							|  |  |  | (function(require){ var module={} // make module AMD/node compatible...
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require('object-run') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-06 03:09:44 +03:00
										 |  |  | var object = require('ig-object') | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*********************************************************************/ | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | // import stuff from object.js to Object...
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var toObject = function(...keys){ | 
					
						
							|  |  |  | 	keys.forEach(function(key){ | 
					
						
							|  |  |  | 		Object[key]  | 
					
						
							|  |  |  | 			|| (Object[key] = object[key]) }) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | toObject( | 
					
						
							|  |  |  | 	'deepKeys', | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | 	// XXX these should be called logically relative to Array.js and diff.js...
 | 
					
						
							|  |  |  | 	'match', | 
					
						
							|  |  |  | 	'matchPartial', | 
					
						
							| 
									
										
										
										
											2020-10-06 03:09:44 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | 	/* XXX not yet sure about these... | 
					
						
							|  |  |  | 	// XXX EXPERIMENTAL...
 | 
					
						
							|  |  |  | 	'parent', | 
					
						
							|  |  |  | 	'parentProperty', | 
					
						
							|  |  |  | 	'parentCall', | 
					
						
							| 
									
										
										
										
											2020-10-06 03:09:44 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | 	'parentOf', | 
					
						
							|  |  |  | 	'childOf', | 
					
						
							|  |  |  | 	'related', | 
					
						
							|  |  |  | 	//*/
 | 
					
						
							|  |  |  | ) | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | //---------------------------------------------------------------------
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-09 23:20:00 +03:00
										 |  |  | // Make a copy of an object...
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // This will:
 | 
					
						
							|  |  |  | // 	- create a new object linked to the same prototype chain as obj
 | 
					
						
							|  |  |  | // 	- copy obj own state
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // NOTE: this will copy prop values and not props...
 | 
					
						
							|  |  |  | Object.copy = function(obj, constructor){ | 
					
						
							|  |  |  | 	return Object.assign( | 
					
						
							|  |  |  | 		constructor == null ? | 
					
						
							|  |  |  | 			Object.create(obj.__proto__) | 
					
						
							|  |  |  | 			: constructor(), | 
					
						
							|  |  |  | 		obj) } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | // Make a full key set copy of an object...
 | 
					
						
							|  |  |  | //
 | 
					
						
							| 
									
										
										
										
											2020-10-09 23:20:00 +03:00
										 |  |  | // NOTE: this will copy prop values and not props...
 | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | // NOTE: this will not deep-copy the values...
 | 
					
						
							| 
									
										
										
										
											2020-10-09 23:20:00 +03:00
										 |  |  | Object.flatCopy = function(obj, constructor){ | 
					
						
							| 
									
										
										
										
											2020-10-06 03:09:44 +03:00
										 |  |  | 	return Object.deepKeys(obj) | 
					
						
							| 
									
										
										
										
											2020-10-09 23:20:00 +03:00
										 |  |  | 		.reduce( | 
					
						
							|  |  |  | 			function(res, key){ | 
					
						
							|  |  |  | 				res[key] = obj[key]  | 
					
						
							|  |  |  | 				return res }, | 
					
						
							|  |  |  | 			constructor == null ? | 
					
						
							|  |  |  | 				{} | 
					
						
							|  |  |  | 				: constructor()) } | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | // XXX for some reason neumric keys do not respect order...
 | 
					
						
							|  |  |  | // 		to reproduce:
 | 
					
						
							|  |  |  | // 			Object.keys({a:0, x:1, 10:2, 0:3, z:4, ' 1 ':5})
 | 
					
						
							|  |  |  | // 			// -> ["0", "10", "a", "x", "z", " 1 "]
 | 
					
						
							|  |  |  | // 		...this is the same across Chrome and Firefox...
 | 
					
						
							| 
									
										
										
										
											2020-10-07 16:46:59 +03:00
										 |  |  | Object.sort = function(obj, keys){ | 
					
						
							|  |  |  | 	keys = (typeof(keys) == 'function' | 
					
						
							|  |  |  | 			|| keys === undefined) ?  | 
					
						
							|  |  |  | 		[...Object.keys(obj)].sort(keys) | 
					
						
							|  |  |  | 		: keys | 
					
						
							|  |  |  | 	new Set([...keys, ...Object.keys(obj)]) | 
					
						
							|  |  |  | 		.forEach(function(k){ | 
					
						
							|  |  |  | 			if(k in obj){ | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | 				var v = Object.getOwnPropertyDescriptor(obj, k) | 
					
						
							| 
									
										
										
										
											2020-10-07 16:46:59 +03:00
										 |  |  | 				delete obj[k] | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | 				Object.defineProperty(obj, k, v) } }) | 
					
						
							| 
									
										
										
										
											2020-10-07 16:46:59 +03:00
										 |  |  | 	return obj } | 
					
						
							| 
									
										
										
										
											2020-10-09 05:55:53 +03:00
										 |  |  | Object.prototype.sort | 
					
						
							|  |  |  | 	|| Object.defineProperty(Object.prototype, 'sort', { | 
					
						
							|  |  |  | 		enumerable: false, | 
					
						
							|  |  |  | 		value: function(keys){ | 
					
						
							|  |  |  | 			return Object.sort(this, keys) }, }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-07 16:46:59 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 04:40:16 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /********************************************************************** | 
					
						
							|  |  |  | * vim:set ts=4 sw=4 :                               */ return module }) |