Comments (10)
wrapAnsi16m
seems to be the culprit here. Should it throw an error if the fn
returns undefined or should the error be thrown inside of the color-conversion
library when it converts a keyword to rgb?
@Qix- I'm happy to do a PR to either project, but I felt like I should run it by you first.
from ansi-styles.
I think it should be an error in color-conversion
, but I'll let @Qix- make the final call.
from ansi-styles.
I think it's correct that color-convert
returns null
if the keyword doesn't exist - in which case, ansi-styles
should throw.
cc @danthegoodman - feel free :) It'd be super appreciated.
from ansi-styles.
I'm happy with the solution implemented for color.ansi16m.keyword
, since it will cleanly handle other functions if they decide to start returning null or undefined.
Unfortunately, the error handling for color.ansi256.keyword
and color.ansi.keyword
is specific to the keyword function. These functions caused the same ambiguous error deeper within the color-convert
library.
When I had only investigated the ansi16m
fix, I was in agreement with @Qix-, that the fix should be in this project. Now that i've seen the error get thrown from within there, I'm learning a bit more in line with @sindresorhus that the conversion library receive a patch instead.
from ansi-styles.
I think it's correct that color-convert returns null if the keyword doesn't exist
@Qix- I disagree. Incorrect input should throw, not silently return null`. That's what the user would expect, and how Node.js and browser APIs work too. Can you please reconsider?
from ansi-styles.
@sindresorhus My only hangup with it is that none of the other methods throw for incorrect input.
> const cc = require('color-convert')
undefined
> cc.rgb.hsl([1000, 522, 10])
[ 31, -198, 198 ]
color-convert
was only ever intended to house the math behind the conversions - nothing more. I still think consuming applications should wrap their own throw logic since there are usecases where merely checking if a keyword is valid is useful.
Unless, that is, you want to start advocating for exceptions to be used as flow control.
Something to keep in mind is that all it's really doing is ({...keywordToColorMap})[inputKeyword]
which just returns undefined
if the key doesn't exist. It's analogous to an object lookup.
from ansi-styles.
My only hangup with it is that none of the other methods throw for incorrect input.
They should throw too, though.
since there are usecases where merely checking if a keyword is valid is useful.
Then there should be a separate method to check whether a keyword is valid. Please make the common-case user-friendly.
Unless, that is, you want to start advocating for exceptions to be used as flow control.
This is not about flow control. It's about input validation and not silently accepting invalid input.
from ansi-styles.
So I should add input validation to every single conversion method?
from ansi-styles.
Yes
from ansi-styles.
Closing in favor of https://github.com/Qix-/color-convert/issues/72.
from ansi-styles.
Related Issues (20)
- blackBright is mentioned in README but is not implemented HOT 17
- NPM install error HOT 7
- Did the 2.2.0 release disappear? HOT 3
- Unable to install the package HOT 1
- missing module => 'color-convert' HOT 1
- Why the open/close API HOT 6
- No greenBright open and close HOT 1
- blackBright doesn't exist
- Uncaught SyntaxError: Use of const in strict mode. HOT 2
- Syntax error in IE11 due to arrow function currying HOT 4
- IE11 syntax error HOT 3
- Why is @types/color-name a production dependency? HOT 4
- Provide es5 lib output HOT 2
- Add support for overline HOT 6
- Can't import into TypeScript node project HOT 2
- Add support for superscript and subscript HOT 2
- Problem from version`5+` to Regex when using ReactNative Hermes engine HOT 1
- '[email protected]' is not in the npm registry. HOT 1
- Blinking text HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ansi-styles.