eight-colors
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -1,1 +0,1 @@ | ||
!function(o,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("eight-colors",[],e):"object"==typeof exports?exports["eight-colors"]=e():o["eight-colors"]=e()}(self,(()=>{return o={578:o=>{const e={},r=(o,e,r)=>`[${o}m${e}[${r}m`,t=["black","red","green","yellow","blue","magenta","cyan","white"];t.forEach(((o,t)=>{e[o]=o=>r(`3${t}`,o,"39")})),e.bg={},t.forEach(((o,t)=>{e.bg[o]=o=>r(`4${t}`,o,"49")})),e.br={},t.forEach(((o,t)=>{e.br[o]=o=>r(`9${t}`,o,"39")})),e.br.bg={},t.forEach(((o,t)=>{e.br.bg[o]=o=>r(`10${t}`,o,"49")})),e.reset=o=>r("0",o,"0"),e.bold=o=>r("1",o,"21"),e.faint=o=>r("2",o,"22"),e.italic=o=>r("3",o,"23"),e.underline=o=>r("4",o,"24"),e.inverse=o=>r("7",o,"27"),e.hidden=o=>r("8",o,"28"),e.strike=o=>r("9",o,"29"),e.remove=o=>`${o}`.replace(/\033\[(\d+)m/g,""),e.log=function(){console.log.apply(console,arguments)},e.logColor=function(){let o=Array.from(arguments);const r=o.pop(),t=e[r];return"function"==typeof t?o=o.map((o=>t(o))):o.push(r),e.log.apply(e,o),o.join(" ")},t.forEach((o=>{const r=`log${o.charAt(0).toUpperCase()}${o.slice(1)}`;e[r]=function(){const r=Array.from(arguments);return r.push(o),e.logColor.apply(e,r)}})),o.exports=e},148:(o,e,r)=>{const t=r(578);o.exports=t}},e={},function r(t){var n=e[t];if(void 0!==n)return n.exports;var c=e[t]={exports:{}};return o[t](c,c.exports,r),c.exports}(148);var o,e})); | ||
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define("eight-colors",[],o):"object"==typeof exports?exports["eight-colors"]=o():e["eight-colors"]=o()}(self,(()=>{return e={578:e=>{const o={},r=(e,o,r)=>`[${e}m${o}[${r}m`,t=["black","red","green","yellow","blue","magenta","cyan","white"];t.forEach(((e,t)=>{o[e]=e=>r(`3${t}`,e,"39")})),o.bg={},t.forEach(((e,t)=>{o.bg[e]=e=>r(`4${t}`,e,"49")})),o.br={},t.forEach(((e,t)=>{o.br[e]=e=>r(`9${t}`,e,"39")})),o.br.bg={},t.forEach(((e,t)=>{o.br.bg[e]=e=>r(`10${t}`,e,"49")})),o.reset=e=>r("0",e,"0"),o.bold=e=>r("1",e,"21"),o.faint=e=>r("2",e,"22"),o.italic=e=>r("3",e,"23"),o.underline=e=>r("4",e,"24"),o.inverse=e=>r("7",e,"27"),o.hidden=e=>r("8",e,"28"),o.strike=e=>r("9",e,"29"),o.remove=e=>`${e}`.replace(/\033\[(\d+)m/g,""),o.log=function(e){console.log(e)},t.forEach((e=>{const r=`log${e.charAt(0).toUpperCase()}${e.slice(1)}`;o[r]=function(){const r=Array.from(arguments),t=(0,o[e])(o.remove(r.join(" ")));return o.log(t),t}})),e.exports=o},148:(e,o,r)=>{const t=r(578);e.exports=t}},o={},function r(t){var n=o[t];if(void 0!==n)return n.exports;var c=o[t]={exports:{}};return e[t](c,c.exports,r),c.exports}(148);var e,o})); |
@@ -5,3 +5,3 @@ /** | ||
export type ColorHandler = (str: string) => string | ||
type ColorHandler = (str: string) => string | ||
@@ -18,10 +18,10 @@ export const black: ColorHandler; | ||
type BG = { | ||
black, | ||
red, | ||
green, | ||
yellow, | ||
blue, | ||
magenta, | ||
cyan, | ||
white | ||
black: ColorHandler; | ||
red: ColorHandler; | ||
green: ColorHandler; | ||
yellow: ColorHandler; | ||
blue: ColorHandler; | ||
magenta: ColorHandler; | ||
cyan: ColorHandler; | ||
white: ColorHandler; | ||
} | ||
@@ -32,10 +32,10 @@ | ||
type BR = { | ||
black, | ||
red, | ||
green, | ||
yellow, | ||
blue, | ||
magenta, | ||
cyan, | ||
white, | ||
black: ColorHandler; | ||
red: ColorHandler; | ||
green: ColorHandler; | ||
yellow: ColorHandler; | ||
blue: ColorHandler; | ||
magenta: ColorHandler; | ||
cyan: ColorHandler; | ||
white: ColorHandler; | ||
@@ -60,9 +60,7 @@ bg: BG | ||
// console log | ||
export function log(...args: string[]): void; | ||
type LogHandler = (str: string) => void; | ||
export const log: LogHandler; | ||
export type ColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white'; | ||
export function logColor<T extends string[]>(...args: [...T, ColorName]): string; | ||
type ColorLogHandler = (...args: any[]) => string; | ||
export type ColorLogHandler = (...args: string[]) => string; | ||
export const logBlack: ColorLogHandler; | ||
@@ -75,2 +73,42 @@ export const logRed: ColorLogHandler; | ||
export const logCyan: ColorLogHandler; | ||
export const logWhite: ColorLogHandler; | ||
export const logWhite: ColorLogHandler; | ||
type EightColors = { | ||
black: ColorHandler; | ||
red: ColorHandler; | ||
green: ColorHandler; | ||
yellow: ColorHandler; | ||
blue: ColorHandler; | ||
magenta: ColorHandler; | ||
cyan: ColorHandler; | ||
white: ColorHandler; | ||
bg: BG, | ||
br: BR, | ||
reset: ColorHandler; | ||
bold: ColorHandler; | ||
faint: ColorHandler; | ||
italic: ColorHandler; | ||
underline: ColorHandler; | ||
inverse: ColorHandler; | ||
hidden: ColorHandler; | ||
strike: ColorHandler; | ||
remove: ColorHandler; | ||
log: LogHandler, | ||
logBlack: ColorLogHandler, | ||
logRed: ColorLogHandler, | ||
logGreen: ColorLogHandler, | ||
logYellow: ColorLogHandler, | ||
logBlue: ColorLogHandler, | ||
logMagenta: ColorLogHandler, | ||
logCyan: ColorLogHandler, | ||
logWhite: ColorLogHandler, | ||
} | ||
declare const EC: EightColors | ||
export default EC; |
@@ -78,19 +78,6 @@ const EC = {}; | ||
// log hook | ||
EC.log = function() { | ||
console.log.apply(console, arguments); | ||
EC.log = function(str) { | ||
console.log(str); | ||
}; | ||
EC.logColor = function() { | ||
let args = Array.from(arguments); | ||
const color = args.pop(); | ||
const fn = EC[color]; | ||
if (typeof fn === 'function') { | ||
args = args.map((it) => fn(it)); | ||
} else { | ||
args.push(color); | ||
} | ||
EC.log.apply(EC, args); | ||
return args.join(' '); | ||
}; | ||
list.forEach((color) => { | ||
@@ -100,4 +87,8 @@ const api = `log${color.charAt(0).toUpperCase()}${color.slice(1)}`; | ||
const args = Array.from(arguments); | ||
args.push(color); | ||
return EC.logColor.apply(EC, args); | ||
const handler = EC[color]; | ||
// merge to string first, browser do NOT support apply arguments | ||
// and remove previous color | ||
const str = handler(EC.remove(args.join(' '))); | ||
EC.log(str); | ||
return str; | ||
}; | ||
@@ -104,0 +95,0 @@ }); |
{ | ||
"name": "eight-colors", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "Eight colors for the console", | ||
@@ -20,3 +20,3 @@ "main": "./lib/index.js", | ||
"scripts": { | ||
"test": "npm run link && node ./scripts/test.cjs && node ./scripts/test.mjs", | ||
"test": "node ./scripts/test.cjs && node ./scripts/test.mjs", | ||
"link": "sf link ./ -f", | ||
@@ -23,0 +23,0 @@ "build": "sf lint && sf b -p", |
@@ -46,3 +46,3 @@ # Eight Colors | ||
// log color | ||
const res = EC.logColor('string1', 'string2', 'red'); | ||
const res = EC.logRed('string1', 'string2'); | ||
console.assert(EC.remove(res) === 'string1 string2'); | ||
@@ -113,4 +113,2 @@ | ||
EC.log(str) | ||
EC.logColor(str, ColorName) | ||
EC.logBlack(str) | ||
@@ -145,2 +143,5 @@ EC.logRed(str) | ||
* 1.2.0 | ||
- remove useless logColor | ||
* 1.1.1 | ||
@@ -147,0 +148,0 @@ - fixed types |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11197
173
159