File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed
Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const tag = ( string , ...values ) => {
4+ console . dir ( { string, values } ) ;
5+ } ;
6+
7+ // Usage
8+
9+ const greeting = 'Hello' ;
10+ const person = { name : 'Marcus Aurelius' } ;
11+
12+ const text = tag `${ greeting } ${ person . name } !` ;
13+ console . dir ( { text } ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const esc = ( code , s ) => `\x1b[${ code } m${ s } \x1b[0m` ;
4+
5+ const tag = ( strings , ...values ) => {
6+ const result = [ strings [ 0 ] ] ;
7+ let i = 1 ;
8+ for ( const val of values ) {
9+ const str = strings [ i ++ ] ;
10+ result . push ( esc ( i + 1 , val ) , str ) ;
11+ }
12+ return result . join ( '' ) ;
13+ } ;
14+
15+ // Usage
16+
17+ const greeting = 'Ave' ;
18+ const person = { name : 'Marcus Aurelius' , position : 'Emperor' } ;
19+
20+ const text = tag `${ greeting } ${ person . position } ${ person . name } !` ;
21+ console . log ( text ) ;
You can’t perform that action at this time.
0 commit comments