minor refactroing...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-06-02 15:59:54 +03:00
parent 5fbf206347
commit fd250a8025
2 changed files with 15 additions and 15 deletions

View File

@ -804,7 +804,7 @@ Align _code_ to shortest leading white-space
``` ```
normalizeIndent(<text>) normalizeIndent(<text>)
normalizeIndent(<text>, <tab-size>) normalizeIndent(<text>, <tab-size>)
normalizeIndent(<text>, <tab-size>, <keep-tabs>) normalizeIndent(<text>, <tab-size>, <leading-tabs>)
-> <text> -> <text>
``` ```
@ -813,7 +813,7 @@ to make source printing in console more pleasant to read.
`tab_size` defaults to `object.TAB_SIZE` `tab_size` defaults to `object.TAB_SIZE`
`keep_indent` defaults to `object.KEEP_INDENT` `leading_tabs` defaults to `object.LEADING_TABS`
A shorthand to `normalizeIndent(..)` optimized for text rather than code A shorthand to `normalizeIndent(..)` optimized for text rather than code
@ -822,7 +822,7 @@ normalizeTextIndent(..)
-> <text> -> <text>
``` ```
This ignores `object.KEEP_INDENT` and `keep_indent` is 0 by default. This ignores `object.LEADING_TABS` and `leading_tabs` is 0 by default.
### `match(..)` ### `match(..)`

View File

@ -25,8 +25,8 @@
var TAB_SIZE = var TAB_SIZE =
module.TAB_SIZE = 4 module.TAB_SIZE = 4
var KEEP_INDENT = var LEADING_TABS =
module.KEEP_INDENT = 1 module.LEADING_TABS = 1
// Normalize code indent... // Normalize code indent...
@ -42,8 +42,8 @@ module.KEEP_INDENT = 1
// This will ignore the indent of the first line. // This will ignore the indent of the first line.
// //
// If the last line is indented higher or equal to the rest of the text // If the last line is indented higher or equal to the rest of the text
// we will user keep_indent (defaults to KEEP_INDENT) to indent the rest // we will user leading_tabs (defaults to LEADING_TABS) to indent the
// of the text. // rest of the text.
// This will indent the following styles correctnly: // This will indent the following styles correctnly:
// //
// |function(a, b){ |function(a, b){ // |function(a, b){ |function(a, b){
@ -56,13 +56,13 @@ module.KEEP_INDENT = 1
// ...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, keep_indent){ function(text, tab_size, leading_tabs){
tab_size = tab_size == null ? tab_size = tab_size == null ?
TAB_SIZE TAB_SIZE
: tab_size : tab_size
keep_indent = (keep_indent == null ? leading_tabs = (leading_tabs == null ?
KEEP_INDENT LEADING_TABS
: keep_indent) : leading_tabs)
* tab_size * tab_size
// prepare text... // prepare text...
var tab = ' '.repeat(tab_size) var tab = ' '.repeat(tab_size)
@ -78,9 +78,9 @@ function(text, tab_size, keep_indent){
// ignore 0 indent of first line... // ignore 0 indent of first line...
|| (i == 0 && indent == 0) ? || (i == 0 && indent == 0) ?
l l
// last line -- ignore keep_indent if lower indent... // last line -- ignore leading_tabs if lower indent...
: i == lines.length-1 && indent > l ? : i == lines.length-1 && indent > l ?
Math.max(l-keep_indent, 0) Math.max(l-leading_tabs, 0)
// initial state... // initial state...
: l < 0 ? : l < 0 ?
indent indent
@ -99,8 +99,8 @@ function(text, tab_size, keep_indent){
// shorthand more suted for text... // shorthand more suted for text...
var normalizeTextIndent = var normalizeTextIndent =
module.normalizeTextIndent = module.normalizeTextIndent =
function(text, tab_size, keep_indent){ function(text, tab_size, leading_tabs){
return module.normalizeIndent(text, tab_size, keep_indent || 0) } return module.normalizeIndent(text, tab_size, leading_tabs || 0) }
// Match two objects... // Match two objects...