Skip to content

Commit

Permalink
feat: disable styling on Node environment
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien Motte committed Oct 18, 2017
1 parent cea93d1 commit 94b7207
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Logger.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { camelToKebab } from './utils'
import { camelToKebab, isBrowser } from './utils'

/**
* Logger class.
Expand Down Expand Up @@ -331,8 +331,20 @@ class Logger {
finalMsgs.push(this._parseMsgTags(after).join(' '))
}

finalMsgs = finalMsgs.join(' ')

if (!isBrowser()) {
finalMsgs = finalMsgs.replace(/%c/g, '')
}

// Arguments
const args = [finalMsgs.join(' '), ...globalStyles, ...othersMsgs]
let args = [finalMsgs]

if (isBrowser()) {
args.push(...globalStyles, ...othersMsgs)
} else {
args.push(...othersMsgs)
}

// Check console
if (typeof console === 'undefined') {
Expand Down
9 changes: 9 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ export function camelToKebab (str) {
export function capitalize (str) {
return str.charAt(0).toUpperCase() + str.slice(1)
}

/**
* Check browser or Node environment.
*
* @returns {Boolean} True if running in browser, false otherwise.
*/
export function isBrowser () {
return !(typeof process !== 'undefined' && process.title === 'node')
}

0 comments on commit 94b7207

Please sign in to comment.