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;
`,
});
05-11 16:27