UNPKG

babel-plugin-console

Version:

Babel plugin with additional console helper functions

46 lines (38 loc) 1.15 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); const buildGroupCollapsed = template => title => level => { const indentation = indentWith(level, '| ', '▼ '); return template(` if (typeof window !== 'undefined') { console.groupCollapsed(title); } else { console.log('${indentation}', title); } `)({ title }); }; const buildGroupEnd = template => title => template(` if (typeof window !== 'undefined') { console.groupEnd(title); } `)({ title }); const buildLog = template => (...args) => level => { if (level == 0) { return template('console.log(args);')({ args }); } const indentation = indentWith(level, '| ', '| '); return template(` if (typeof window !== 'undefined') { console.log(args); } else { console.log('${indentation}', args); } `)({ args }); }; const indentWith = (level, str, initial) => Array.from({ length: level }).reduce(acc => `${str}${acc}`, initial); exports.default = template => ({ buildGroupCollapsed: buildGroupCollapsed(template), buildGroupEnd: buildGroupEnd(template), buildLog: buildLog(template) });