You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					39 lines
				
				827 B
			
		
		
			
		
	
	
					39 lines
				
				827 B
			| 
								 
											3 years ago
										 
									 | 
							
								"use strict";
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								Object.defineProperty(exports, "__esModule", {
							 | 
						||
| 
								 | 
							
								  value: true
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								exports.pathToParts = void 0;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @memberof module:flat
							 | 
						||
| 
								 | 
							
								 * @alias PathToPartsOptions
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * @load ./path-to-parts.doc.md
							 | 
						||
| 
								 | 
							
								 * @param   {string}              propertyPath
							 | 
						||
| 
								 | 
							
								 * @param   {PathToPartsOptions}  options
							 | 
						||
| 
								 | 
							
								 * @returns  {PathParts}
							 | 
						||
| 
								 | 
							
								 *
							 | 
						||
| 
								 | 
							
								 * @memberof module:flat
							 | 
						||
| 
								 | 
							
								 * @alias pathToParts
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 | 
							
								const pathToParts = (propertyPath, options = {}) => {
							 | 
						||
| 
								 | 
							
								  let allParts = propertyPath.split('.');
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  if (options.skipArrayIndexes) {
							 | 
						||
| 
								 | 
							
								    // eslint-disable-next-line no-restricted-globals
							 | 
						||
| 
								 | 
							
								    allParts = allParts.filter(part => isNaN(+part));
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  return allParts.reduce((memo, part) => {
							 | 
						||
| 
								 | 
							
								    if (memo.length) {
							 | 
						||
| 
								 | 
							
								      return [...memo, [memo[memo.length - 1], part].join('.')];
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return [part];
							 | 
						||
| 
								 | 
							
								  }, []);
							 | 
						||
| 
								 | 
							
								};
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								exports.pathToParts = pathToParts;
							 |