bgrins / TinyColor

Fast, small color manipulation and conversion for JavaScript
https://bgrins.github.io/TinyColor/
MIT License
5.05k stars 438 forks source link

Update v2 public API to support node, ts, and umd #181

Closed bgrins closed 6 years ago

bgrins commented 6 years ago

@scttcper this is based on top of https://github.com/bgrins/TinyColor/pull/178. I had to do some trickery to get var TinyColor = require("./public_api") as well as import TinyColor from "./public_api" to work (see public_api.ts). It was based partly on this comment: https://github.com/Microsoft/TypeScript/issues/2719#issuecomment-289129684. I added a test to make sure this also works in node.

I also added a trivial HTML page to test out the umd bundle - although I'm wondering if we should just make the demo use the UMD bundle as a script tag instead of processing it through rollup (I don't feel too strong about that).

bgrins commented 6 years ago

Looks like a couple of lint changes would be needed if you think this approach makes sense.

bgrins commented 6 years ago

This also changes things so you the only thing that gets exported is the TinyColor class. So if you want access to the static methods you destructure them from that object, rather than importing them directly. We could probably also export that via public_api, but I'm thinking it's simpler to provide only one API access point for those (as a static on the class, regardless of whether you are loading lib from node, ts, umd).

bgrins commented 6 years ago

One more thing - calling tinycolor("red") actually does work from the UMD bundle but doesn't from node / ts. I don't know why.. I'm leaning towards just dropping that feature and requiring a migration frmo v1.

codecov-io commented 6 years ago

Codecov Report

Merging #181 into v2 will increase coverage by 0.02%. The diff coverage is 95.23%.

Impacted file tree graph

@@            Coverage Diff            @@
##              v2     #181      +/-   ##
=========================================
+ Coverage   98.4%   98.43%   +0.02%     
=========================================
  Files         10       10              
  Lines        628      637       +9     
  Branches     150      151       +1     
=========================================
+ Hits         618      627       +9     
  Misses        10       10
Impacted Files Coverage Δ
src/public_api.ts 100% <100%> (ø) :arrow_up:
src/index.ts 97.43% <93.75%> (-0.31%) :arrow_down:
src/random.ts 97.27% <0%> (+0.9%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d6d8e04...371109a. Read the comment docs.

scttcper commented 6 years ago

This looks good! 👍