Skip to content

Commit f8605dc

Browse files
committed
refactor(options): cleaner code structure
1 parent 36a1b6d commit f8605dc

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

src/index.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
11
/* eslint-disable no-param-reassign */
22
/* eslint no-console: off */
33
import _ from 'lodash'
4+
<<<<<<< HEAD
5+
import chalk from 'chalk'
6+
// import chalkExt from './chalkExt'
7+
=======
48

59
import chalkExt from './chalkExt'
10+
>>>>>>> 1871a68 (* feat: pass options to Logger instance)
611

12+
// TODO: use static props -> update babel!
713
class Logger {
814

9-
// use static props -> update babel!
1015
defaults = {
11-
prefix: '[StackR23]',
12-
debug: {color: 'cyan', prefix: 'DEBUG'},
13-
error: {color: 'red', prefix: 'ERROR'},
14-
success: {color: 'green', prefix: 'SUCCESS'}
16+
prefix: '{bold.yellow [StackR23] }',
17+
log: {style: 'reset', prefix: 'bold.yellow LOG - '},
18+
debug: {style: 'cyan', prefix: '{bold.cyan DEBUG: }'},
19+
error: {style: 'red', prefix: '{bold.red ERROR: }'},
20+
success: {style: 'green', prefix: '{bold.green SUCCESS: }'}
1521
}
1622

1723
constructor(options) {
18-
console.log('options :>> ', options)
19-
2024
this.options = _.merge(this.defaults, options)
2125
console.log('this.defaults :>> ', this.defaults)
2226
console.log('this.options :>> ', this.options)
2327
}
2428

25-
log(str, typePrefix, styleType, styleString) {
26-
if (arguments.length === 1) {
27-
console.log(chalkExt`{${this.options.prefixColor}.bold ${this.options.prefix}} ${str}`)
29+
log(str, type = 'log', styleCustom) {
30+
const {prefix, [type]: typeOptions} = this.options
2831

32+
<<<<<<< HEAD
2933
return true
3034
}
3135

32-
if (arguments.length === 2) {
33-
const type = typePrefix
34-
const {color, prefix} = this.options[type] //
36+
const {style, prefix} = this.options
37+
const typeOptions = this.options[type]
3538

36-
typePrefix = prefix || type
37-
// styleType = colorType || color
38-
styleString = color
39+
=======
40+
if (arguments.length === 1) {
41+
console.log(chalkExt`${prefix}${str}`)
42+
return
3943
}
4044

45+
>>>>>>> 1871a68 (* feat: pass options to Logger instance)
4146
console.log(
42-
// ${styleType}
43-
chalkExt`{{bold ${this.options.prefix} ${typePrefix}:} {${styleString} ${str}}`
47+
(prefix ? chalkExt`${prefix}` : '') +
48+
(typeOptions.prefix ? chalkExt`${typeOptions.prefix}` : '') +
49+
chalkExt`{${typeOptions.style} ${str}}`
4450
)
45-
46-
return true
4751
}
4852

49-
dir = arg => console.dir(...arg)
50-
5153
debug = str => this.log(str, 'debug')
52-
53-
error = str => this.log(str, 'error') //, `${this.options.errorColor}Bright.bgBlack`, this.options.errorColor)
54-
55-
success = str => this.log(str, 'success') //, `${this.options.successColor}Bright`, this.options.successColor)
54+
error = str => this.log(str, 'error')
55+
success = str => this.log(str, 'success')
5656
}
5757

58+
export {Logger}
5859
export default new Logger()

0 commit comments

Comments
 (0)