Skip to content
This repository was archived by the owner on Jun 15, 2019. It is now read-only.

Commit db5ae28

Browse files
committed
refactor(log): debug package was added and substituted with console.debugs
1 parent 7a818e4 commit db5ae28

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

package-lock.json

Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
"devDependencies": {
4848
"@babel/core": "^7.4.4",
4949
"@babel/preset-env": "^7.4.4",
50+
"@types/debug": "^4.1.4",
5051
"@types/jest": "^24.0.12",
5152
"babel-jest": "^24.8.0",
5253
"commitizen": "^3.1.1",
@@ -72,7 +73,9 @@
7273
"tslint-config-standard": "^8.0.1",
7374
"typescript": "^3.4.3"
7475
},
75-
"dependencies": {},
76+
"dependencies": {
77+
"debug": "^4.1.1"
78+
},
7679
"config": {
7780
"commitizen": {
7881
"path": "./node_modules/cz-conventional-changelog"

rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const dependentOutput = {
5151
input: input,
5252
output: {
5353
format: 'umd', file: pkg.main, name: libVarName, sourcemap: true, exports: 'named',
54-
globals: {}
54+
globals: {debug: 'Debug'}
5555
},
5656
watch: watch,
5757
plugins: commonPlugins.concat([

src/TextWrap.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
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

Comments
 (0)