d
k
p
l
u
s

ultra-console


console.__proto__.styleText = function (option) {

  if (!option) {
    console.groupCollapsed('请输入option');
    console.table({
      text: '文本',
      style: '样式',
    });
    console.table({
      text: '字符串数组',
      style: '样式字符串数组',
    });
    console.groupEnd('请输入option');
    return;
  }

  if (!option || !option.text || !option.style) {
    return;
  }

  if (typeof option.text === 'string' && typeof option.style === 'string') {
    console.log(`%c${option.text}`, option.style);
  }

  if (Array.isArray(option.text) && Array.isArray(option.style)) {

    let txt = '';
  
    option.text.forEach((text) => {
      txt += `%c${text}`;
    });
  
    console.log(txt, ...option.style)
  }
}
console.log(`%chello%cworld`,`
  color: #fff;
  background: #000;
`,`
  color: #fff;
  background: blue;
`);

console.styleText({
  text: ['hello','world','hi'],
  style: [`
    color: #fff;
    background: #000;
    padding: 5px;
  `,`
    color: #fff;
    background: blue;
    padding: 5px;
  `,`
    color: #fff;
    background: green;
    padding: 5px;
  `],
});

console.styleText({
  text: 'hello',
  style: `
    color: #fff;
    background: blue;
    padding: 5px;
  `,
});
posted @ 2018-11-05 11:40  dkplus  阅读(157)  评论(0编辑  收藏  举报