Start sharing components as a team!Share components as a team!Join Bit to build your applications faster.Get Started Free

make-debugger

v0.86.0arrow_drop_down
v0.86.0
STATUS
Passing
DOWNLOADS
3,826
LICENSE
MIT
VISIBILITY
Public
PUBLISHED
9 months ago
SIZE
27 KB
Create a namespaced debug function.
1 contributor
Use make-debugger in your project ?
Copied
npm i @bit/semantic-org.semantic-ui-react.utils.make-debugger
Set Bit as a scoped registryLearn more
npm config set '@bit:registry' https://node.bit.dev
makeDebugger.js
36 Lines(14 sloc)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import debug from 'debug'
import isBrowser from './isBrowser'

if (isBrowser() && process.env.NODE_ENV !== 'production' && process.env.NODE_ENV !== 'test') {
  // Heads Up!
  // https://github.com/visionmedia/debug/pull/331
  //
  // debug now clears storage on load, grab the debug settings before require('debug').
  // We try/catch here as Safari throws on localStorage access in private mode or with cookies disabled.
  let DEBUG
  try {
    DEBUG = window.localStorage.debug
  } catch (e) {
    /* eslint-disable no-console */
    console.error('Semantic-UI-React could not enable debug.')
    console.error(e)
    /* eslint-enable no-console */
  }

  // enable what ever settings we got from storage
  debug.enable(DEBUG)
}

/**
 * Create a namespaced debug function.
 * @param {String} namespace Usually a component name.
 * @example
 * import { makeDebugger } from 'src/lib'
 * const debug = makeDebugger('namespace')
 *
 * debug('Some message')
 * @returns {Function}
 */
const makeDebugger = namespace => debug(`semanticUIReact:${namespace}`)

export default makeDebugger