colors-option
Advanced tools
Comparing version 4.5.0 to 5.0.0
@@ -14,24 +14,24 @@ import{Chalk}from"chalk"; | ||
export default function colorsOption(opts){ | ||
const colorsOption=(opts)=>{ | ||
const{colors,stream,chalkOpts}=getOpts(opts); | ||
const level=getLevel(colors,stream); | ||
const chalk=new Chalk({...chalkOpts,level}); | ||
return chalk; | ||
} | ||
return chalk | ||
}; | ||
const getLevel=function(colors,stream){ | ||
export default colorsOption; | ||
const getLevel=(colors,stream)=>{ | ||
if(colors===false){ | ||
return 0; | ||
return 0 | ||
} | ||
const terminalLevel=getTerminalLevel(stream); | ||
return colors===undefined?terminalLevel:Math.max(terminalLevel,1); | ||
return colors===undefined?terminalLevel:Math.max(terminalLevel,1) | ||
}; | ||
const getTerminalLevel=function(stream){ | ||
return stream.isTTY?DEPTH_TO_LEVEL[stream.getColorDepth()]:0; | ||
}; | ||
const getTerminalLevel=(stream)=> | ||
stream.isTTY?DEPTH_TO_LEVEL[stream.getColorDepth()]:0; | ||
const DEPTH_TO_LEVEL={1:0,4:1,8:2,24:3}; | ||
//# sourceMappingURL=main.js.map | ||
const DEPTH_TO_LEVEL={1:0,4:1,8:2,24:3}; |
@@ -7,3 +7,3 @@ import{stdout}from"node:process"; | ||
export const getOpts=function(opts={}){ | ||
export const getOpts=(opts={})=>{ | ||
validateBasicOpts(opts); | ||
@@ -13,22 +13,21 @@ const{colors,stream=stdout,...chalkOpts}=opts; | ||
validateStream(stream); | ||
return{colors,stream,chalkOpts}; | ||
return{colors,stream,chalkOpts} | ||
}; | ||
const validateBasicOpts=function(opts){ | ||
const validateBasicOpts=(opts)=>{ | ||
if(!isPlainObj(opts)){ | ||
throw new TypeError(`Options must be a plain object: ${opts}`); | ||
throw new TypeError(`Options must be a plain object: ${opts}`) | ||
} | ||
}; | ||
const validateColors=function(colors){ | ||
const validateColors=(colors)=>{ | ||
if(colors!==undefined&&typeof colors!=="boolean"){ | ||
throw new TypeError(`"colors" option must be a boolean: ${colors}`); | ||
throw new TypeError(`"colors" option must be a boolean: ${colors}`) | ||
} | ||
}; | ||
const validateStream=function(stream){ | ||
const validateStream=(stream)=>{ | ||
if(!(stream instanceof Stream)){ | ||
throw new TypeError(`"stream" option must be a stream: ${stream}`); | ||
throw new TypeError(`"stream" option must be a stream: ${stream}`) | ||
} | ||
}; | ||
//# sourceMappingURL=options.js.map | ||
}; |
{ | ||
"name": "colors-option", | ||
"version": "4.5.0", | ||
"version": "5.0.0", | ||
"type": "module", | ||
"exports": { | ||
"types": "./build/types/main.d.ts", | ||
"types": "./build/src/main.d.ts", | ||
"default": "./build/src/main.js" | ||
}, | ||
"main": "./build/src/main.js", | ||
"types": "./build/types/main.d.ts", | ||
"types": "./build/src/main.d.ts", | ||
"files": [ | ||
"build/src/**/*.{js,json}", | ||
"build/types/**/*.d.ts" | ||
"build/src/**/*.{js,json,d.ts}", | ||
"!build/src/**/*.test.js", | ||
"!build/src/{helpers,fixtures}" | ||
], | ||
@@ -50,17 +51,16 @@ "sideEffects": false, | ||
"directories": { | ||
"lib": "src", | ||
"test": "test" | ||
"lib": "src" | ||
}, | ||
"dependencies": { | ||
"chalk": "^5.0.1", | ||
"chalk": "^5.2.0", | ||
"is-plain-obj": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"@ehmicky/dev-tasks": "^1.0.102", | ||
"@types/node": "^18.0.6", | ||
"test-each": "^5.5.0" | ||
"@ehmicky/dev-tasks": "^2.0.80", | ||
"@types/node": "^18.15.3", | ||
"test-each": "^5.7.1" | ||
}, | ||
"engines": { | ||
"node": ">=14.18.0" | ||
"node": ">=16.17.0" | ||
} | ||
} |
[![Node](https://img.shields.io/badge/-Node.js-808080?logo=node.js&colorA=404040&logoColor=66cc33)](https://www.npmjs.com/package/colors-option) | ||
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/types/main.d.ts) | ||
[![TypeScript](https://img.shields.io/badge/-Typed-808080?logo=typescript&colorA=404040&logoColor=0096ff)](/src/main.d.ts) | ||
[![Codecov](https://img.shields.io/badge/-Tested%20100%25-808080?logo=codecov&colorA=404040)](https://codecov.io/gh/ehmicky/colors-option) | ||
[![Twitter](https://img.shields.io/badge/-Twitter-808080.svg?logo=twitter&colorA=404040)](https://twitter.com/intent/follow?screen_name=ehmicky) | ||
[![Mastodon](https://img.shields.io/badge/-Mastodon-808080.svg?logo=mastodon&colorA=404040&logoColor=9590F9)](https://fosstodon.org/@ehmicky) | ||
[![Medium](https://img.shields.io/badge/-Medium-808080.svg?logo=medium&colorA=404040)](https://medium.com/@ehmicky) | ||
@@ -22,3 +22,3 @@ | ||
const exampleLibrary = function ({ colors, ...otherLibraryOptions }) { | ||
const exampleLibrary = ({ colors, ...otherLibraryOptions }) => { | ||
const chalk = colorsOption({ colors }) | ||
@@ -35,6 +35,9 @@ console.log(chalk.red('example')) | ||
This package works in Node.js >=14.18.0. It is an ES module and must be loaded | ||
using | ||
This package works in Node.js >=16.17.0. | ||
This is an ES module. It must be loaded using | ||
[an `import` or `import()` statement](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), | ||
not `require()`. | ||
not `require()`. If TypeScript is used, it must be configured to | ||
[output ES modules](https://www.typescriptlang.org/docs/handbook/esm-node.html), | ||
not CommonJS. | ||
@@ -126,3 +129,3 @@ # API | ||
<tr> | ||
<td align="center"><a href="https://twitter.com/ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/colors-option/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/colors-option/commits?author=ehmicky" title="Documentation">📖</a></td> | ||
<td align="center"><a href="https://fosstodon.org/@ehmicky"><img src="https://avatars2.githubusercontent.com/u/8136211?v=4?s=100" width="100px;" alt=""/><br /><sub><b>ehmicky</b></sub></a><br /><a href="https://github.com/ehmicky/colors-option/commits?author=ehmicky" title="Code">💻</a> <a href="#design-ehmicky" title="Design">🎨</a> <a href="#ideas-ehmicky" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/ehmicky/colors-option/commits?author=ehmicky" title="Documentation">📖</a></td> | ||
</tr> | ||
@@ -129,0 +132,0 @@ </table> |
9659
136
77
Updatedchalk@^5.2.0