1- import { initiateObject } from "./utilities" ;
1+ import Debug from 'debug'
2+
3+ import { initiateObject } from './utilities' ;
4+
5+ const logAnyChar = Debug ( 'AC' )
6+ const logFastCheck = Debug ( 'FC' )
7+ const logWhiteSpace = Debug ( 'WS' )
8+ const logBreakLine = Debug ( 'BL' )
9+ const logMainLoop = Debug ( 'ML' )
210
311/**
412 * @author [S. Mahdi Mir-Ismaili](https://mirismaili.github.io)
@@ -33,9 +41,8 @@ export default class TextWrap implements WrapStyle {
3341 ++ i
3442 ) {
3543 c = text [ i ]
36- vLen += c === '\t' ?
37- tabLength - vLen % tabLength : 1
38- //console.debug(`A: ${c} / ${vLen}`);
44+ vLen += c === '\t' ? tabLength - vLen % tabLength : 1
45+ logAnyChar ( `${ c } / ${ vLen } ` ) ;
3946
4047 // tslint:disable-next-line:label-position
4148 searchBreakLine: {
@@ -45,7 +52,7 @@ export default class TextWrap implements WrapStyle {
4552
4653 // tslint:disable-next-line:label-position
4754 searchWhiteSpace: {
48- if ( vLen > this . wrapOn ) { //console.debug('X: ' + fastCheck)
55+ if ( vLen > this . wrapOn ) { //logFastCheck( fastCheck)
4956 if ( fastCheck ||
5057 // The 2nd condition will always be true if the 1st is true. Actually, it is the main condition
5158 // we need to check, but we know in most cases (~ 100%) the 1st is true.
@@ -54,10 +61,10 @@ export default class TextWrap implements WrapStyle {
5461 // tslint:disable-next-line:no-conditional-assignment
5562 && ( fastCheck = true )
5663 ) {
57- //console.debug('Y: ' + ( marker - start > indentsNVLen) )
64+ logFastCheck ( marker - start > indentsNVLen )
5865 if ( isNotBreakable ) continue mainLoop
5966
60- //console.debug('Z ')
67+ logFastCheck ( ' ')
6168 fastCheck = false
6269 } else if ( isNotBreakable )
6370 break searchWhiteSpace
@@ -69,28 +76,29 @@ export default class TextWrap implements WrapStyle {
6976 marker = i + 1 // Store the value of i
7077 vLen0 = vLen // Store the value of vLen
7178 continue mainLoop
72- } //------------------------------------------/searchWhiteSpace
79+ } //---------------------------------------------------------------------- /searchWhiteSpace
7380
7481 // noinspection UnreachableCodeJS
7582 markers . push ( marker )
7683 wrappedText += text . slice ( from , marker ) + '\n' + indentsN
77- //console.debug(`L: [${from}, ${marker}) - ${vLen} - ${indentsNVLen + (vLen - vLen0)}\n${text.slice(from, marker)}`);
78- vLen = indentsNVLen + ( vLen - vLen0 )
84+ const nextVLen = indentsNVLen + ( vLen - vLen0 )
85+ logWhiteSpace ( `[${ from } , ${ marker } ) / vLen: ${ vLen } / nextVLen: ${ nextVLen } \n${ text . slice ( from , marker ) } ` ) ;
86+ vLen = nextVLen
7987 vLen0 = indentsNVLen
8088 start = marker // Set to start of the next line
8189 from = marker // Store the value of marker
8290 fastCheck = false
8391 continue mainLoop
84- } //------------------------------------------/searchBreakLine
92+ } //---------------------------------------------------------------------- /searchBreakLine
8593
86- //console.debug('NN');
8794 // noinspection UnreachableCodeJS
95+ logBreakLine ( '' ) ;
8896 start = i // Set to start of the next line
8997 vLen0 = 0 // Reset vLen0
9098 vLen = 0 // Reset vLen
91- } // /mainLoop
99+ } //---------------------------------------------------------------------- /mainLoop
92100
93- //console.debug(`OK: ${from}\n${wrappedText}`);
101+ logMainLoop ( `from: ${ from } \n${ wrappedText } `) ;
94102
95103 return {
96104 markers : markers ,
0 commit comments