@@ -27,9 +27,7 @@ const takeWhileReverse = (array, predicate, start) => {
2727 return out ;
2828} ;
2929
30- /**
31- * Checks if the character at position i in string is a normal character a.k.a a non control character.
32- * */
30+ // Check if the character at position `i` in string is a normal character (non-control character)
3331const isNormalCharacter = ( string , i ) => {
3432 const char = string [ i ] ;
3533 const backslash = '\\' ;
@@ -45,10 +43,8 @@ const isNormalCharacter = (string, i) => {
4543
4644const collectStyles = data => data ? collectStyles ( data . parent ) . concat ( data . styles ) : [ 'reset' ] ;
4745
48- /**
49- * Computes the style for a given data based on it's style and the style of it's parent. Also accounts for !style styles
50- * which remove a style from the list if present.
51- * */
46+ // Compute the style for a given data based on its style and the style of its parent.
47+ // Also accounts for `!style` styles which remove a style from the list if present.
5248const sumStyles = data => {
5349 const negateRegex = / ^ ~ .+ / ;
5450 let out = [ ] ;
@@ -65,13 +61,10 @@ const sumStyles = data => {
6561 return out ;
6662} ;
6763
68- /**
69- * Takes a string and parses it into a tree of data objects which inherit styles from their parent.
70- * */
64+ // Take a string and parse it into a tree of data objects which inherit styles from their parent
7165function parse ( string ) {
7266 const root = data ( null ) ;
7367 let pushingStyle = false ;
74-
7568 let current = root ;
7669
7770 for ( let i = 0 ; i < string . length ; i ++ ) {
@@ -88,7 +81,7 @@ function parse(string) {
8881 } ;
8982
9083 if ( pushingStyle ) {
91- if ( ' \t' . indexOf ( char ) > - 1 ) {
84+ if ( ' \t' . includes ( char ) ) {
9285 pushingStyle = false ;
9386 } else if ( char === '\n' ) {
9487 pushingStyle = false ;
@@ -111,16 +104,14 @@ function parse(string) {
111104 }
112105
113106 if ( current !== root ) {
114- throw new Error ( 'literal template has an unclosed block' ) ;
107+ throw new Error ( 'Template literal has an unclosed block' ) ;
115108 }
116109
117110 return root ;
118111}
119112
120- /**
121- * Takes a tree of data objects and flattens it to a list of data objects with the inherited and negations styles
122- * accounted for.
123- * */
113+ // Take a tree of data objects and flatten it to a list of data
114+ // objects with the inherited and negations styles accounted for
124115function flatten ( data ) {
125116 let flat = [ ] ;
126117
@@ -140,13 +131,11 @@ function flatten(data) {
140131
141132function assertStyle ( chalk , style ) {
142133 if ( ! chalk [ style ] ) {
143- throw new Error ( `invalid Chalk style: ${ style } ` ) ;
134+ throw new Error ( `Invalid Chalk style: ${ style } ` ) ;
144135 }
145136}
146137
147- /**
148- * Checks if a given style is valid and parses style functions.
149- * */
138+ // Check if a given style is valid and parse style functions
150139function parseStyle ( chalk , style ) {
151140 const fnMatch = style . match ( / ^ \s * ( \w + ) \s * \( \s * ( [ ^ ) ] * ) \s * \) \s * / ) ;
152141 if ( ! fnMatch ) {
@@ -162,9 +151,7 @@ function parseStyle(chalk, style) {
162151 return chalk [ name ] . apply ( chalk , args ) ;
163152}
164153
165- /**
166- * Performs the actual styling of the string, essentially lifted from cli.js.
167- * */
154+ // Perform the actual styling of the string
168155function style ( chalk , flat ) {
169156 return flat . map ( data => {
170157 const fn = data . styles . reduce ( parseStyle , chalk ) ;
0 commit comments