mirror of
				https://github.com/musix-org/musix-oss
				synced 2025-10-31 14:41:36 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			676 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			676 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| module.exports = function walk (obj) {
 | |
|     if (!obj || typeof obj !== 'object') return obj;
 | |
|     if (isDate(obj) || isRegex(obj)) return obj;
 | |
|     if (Array.isArray(obj)) return obj.map(walk);
 | |
|     return Object.keys(obj).reduce(function (acc, key) {
 | |
|         var camel = key[0].toLowerCase() + key.slice(1).replace(/([A-Z]+)/g, function (m, x) {
 | |
|             return '_' + x.toLowerCase();
 | |
|         });
 | |
|         acc[camel] = walk(obj[key]);
 | |
|         return acc;
 | |
|     }, {});
 | |
| };
 | |
| 
 | |
| var isDate = function (obj) {
 | |
|     return Object.prototype.toString.call(obj) === '[object Date]';
 | |
| };
 | |
| 
 | |
| var isRegex = function (obj) {
 | |
|     return Object.prototype.toString.call(obj) === '[object RegExp]';
 | |
| };
 | 
