mirror of
				https://github.com/flynx/object.js.git
				synced 2025-10-30 19:10:11 +00:00 
			
		
		
		
	minor revision of text formatting tools...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
		
							parent
							
								
									f54090dcac
								
							
						
					
					
						commit
						b53ecc5448
					
				
							
								
								
									
										43
									
								
								object.js
									
									
									
									
									
								
							
							
						
						
									
										43
									
								
								object.js
									
									
									
									
									
								
							| @ -90,18 +90,26 @@ module.LEADING_TABS = 1 | |||||||
| // 		exception -- normalizeIndent(..)  will break code written 
 | // 		exception -- normalizeIndent(..)  will break code written 
 | ||||||
| // 		in Whitespace.
 | // 		in Whitespace.
 | ||||||
| //
 | //
 | ||||||
|  | // XXX BUG?
 | ||||||
|  | // 			`a					`a						`a
 | ||||||
|  | // 			|    b			->	|b			expected?	|    b
 | ||||||
|  | // 			|        c`			|    c`					|        c`
 | ||||||
|  | // 		while:
 | ||||||
|  | // 			`a					`a
 | ||||||
|  | // 			|    b			->	|    b		as expected.
 | ||||||
|  | // 			|    c`				|    c`
 | ||||||
|  | // 		this leads to functions like the following to get messed up:
 | ||||||
|  | // 			|function(a){
 | ||||||
|  | // 			|	return a
 | ||||||
|  | // 			|		|| 'moo' }
 | ||||||
|  | //
 | ||||||
| // XXX is this the right place for this???
 | // XXX is this the right place for this???
 | ||||||
| // 		...when moving take care that ImageGrid's core.doc uses this...
 | // 		...when moving take care that ImageGrid's core.doc uses this...
 | ||||||
| var normalizeIndent = | var normalizeIndent = | ||||||
| module.normalizeIndent = | module.normalizeIndent = | ||||||
| function(text, tab_size, leading_tabs){ | function(text, {tab_size=module.TAB_SIZE, leading_tabs=module.LEADING_TABS, pad_tabs=0}={}){ | ||||||
| 	tab_size = tab_size == null ?  | 	leading_tabs *= tab_size | ||||||
| 		module.TAB_SIZE  | 	var padding = ' '.repeat(pad_tabs*tab_size) | ||||||
| 		: tab_size |  | ||||||
| 	leading_tabs = (leading_tabs == null ?  |  | ||||||
| 			module.LEADING_TABS  |  | ||||||
| 			: leading_tabs)  |  | ||||||
| 		* tab_size |  | ||||||
| 	// prepare text...
 | 	// prepare text...
 | ||||||
| 	var tab = ' '.repeat(tab_size || 0) | 	var tab = ' '.repeat(tab_size || 0) | ||||||
| 	text = tab != '' ? | 	text = tab != '' ? | ||||||
| @ -140,20 +148,21 @@ function(text, tab_size, leading_tabs){ | |||||||
| 				// min...
 | 				// min...
 | ||||||
| 				: Math.min(l, indent) }, -1) || 0 | 				: Math.min(l, indent) }, -1) || 0 | ||||||
| 	// normalize...
 | 	// normalize...
 | ||||||
| 	return lines | 	return padding  | ||||||
| 		.map(function(line, i){ | 		+lines | ||||||
| 			return i == 0 ?  | 			.map(function(line, i){ | ||||||
| 				line | 				return i == 0 ?  | ||||||
| 				: line.slice(l) }) | 					line | ||||||
| 		.join('\n') | 					: line.slice(l) }) | ||||||
| 		.trim() } | 			.join('\n'+ padding) | ||||||
|  | 			.trim() } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // shorthand more suted for text...
 | // shorthand more suted for text...
 | ||||||
| var normalizeTextIndent = | var normalizeTextIndent = | ||||||
| module.normalizeTextIndent = | module.normalizeTextIndent = | ||||||
| function(text, tab_size, leading_tabs){ | function(text, opts={leading_tabs: 0}){ | ||||||
| 	return module.normalizeIndent(text, tab_size, leading_tabs || 0) } | 	return module.normalizeIndent(text, opts) } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| // template string tag versions of the above...
 | // template string tag versions of the above...
 | ||||||
|  | |||||||
| @ -1,6 +1,6 @@ | |||||||
| { | { | ||||||
|   "name": "ig-object", |   "name": "ig-object", | ||||||
|   "version": "5.4.12", |   "version": "5.4.13", | ||||||
|   "description": "", |   "description": "", | ||||||
|   "main": "object.js", |   "main": "object.js", | ||||||
|   "scripts": { |   "scripts": { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user