* feat: __testEditable allows editable region tests It's not entirely isolated, but it makes it possible to select only the element with id 'editable-only' which is built solely from code inside the editable region. * fix(client): missing editableContents -> '' Previously it was added as the string 'undefined' * fix: more informative error messages * fix: DRY, correct and test getLines
		
			
				
	
	
		
			17 lines
		
	
	
		
			375 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			17 lines
		
	
	
		
			375 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
const { isEmpty } = require('lodash');
 | 
						|
 | 
						|
// TODO: secure with tests
 | 
						|
function getLines(contents, range) {
 | 
						|
  if (isEmpty(range)) {
 | 
						|
    return '';
 | 
						|
  }
 | 
						|
  const lines = contents.split('\n');
 | 
						|
  const editableLines =
 | 
						|
    isEmpty(lines) || range[1] <= range[0]
 | 
						|
      ? []
 | 
						|
      : lines.slice(range[0], range[1] - 1);
 | 
						|
  return editableLines.join('\n');
 | 
						|
}
 | 
						|
 | 
						|
exports.getLines = getLines;
 |