0.3.2 • Published 4 years ago

@ricokahler/parse-to-rgba v0.3.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

Parse to RGBA

Converts any color to RGBA using canvas.

Installation

npm install --save @ricokahler/parse-to-rgba

Why canvas?

The browser already has the ability to parse colors via canvas. Other color libs use javascript to parse and transform colors to RGBA.

The result? Significancy smaller bundle sizes:

More than 20x smaller!

Why not canvas?

Booting up canvas is slower than parsing via javascript.

On my 2019 16" MacBook Pro:

  • Canvas: 58,588 ops/sec
  • JavaScript: 3,335,123 ops/sec

See here

Note: the canvas ops/sec metric does not include the creation of the canvas context.

However, the numbers above aren't the full story. The javascript implementation I'm referencing (polished) has a ~10kB bundle size. That extra codes takes significantly more time to parse and download.

Node vs Browser environments

This lib will work in both browser and node environments. In a node environment it will use the package canvas instead of the browser's native canvas.

Note: For node/SSR environments, you will need to install the package canvas

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago

0.0.0

4 years ago