npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

rangarang

v2.1.1

Published

Chooses the best colors from a picture.

Downloads

3

Readme

🌈 Rangarang

Rangarang (Persian word for "Colorful") is a tiny library that chooses the best colors from a picture. It extracts a beautiful background color, and an accessible text color.

It is:

  • Very, very lightweight ⚡️
  • Fast 🤔
  • TypeScript-friendly ✅
  • Works in both Node.js and broswer environments 🌍
  • Accessible: The colors have a >= 4.5 contrast ratio when used together!

Usage

This library uses the pixel data of the image. In browsers, it's easy to gather the pixel data using a <canvas> element:

import rangarang, { getDataFromCanvas } from 'rangarang';

const img = document.querySelector('img');
img.onload = () => {
  const { background, text } = rangarang(getDataFromCanvas(img)));
  console.log(background, text) // prints two hexacodes
};

But in Node.js environments, it's a bit harder. This library does not have any functions to extract pixel data from an image in Node, but you can extract it using your favorite library and use it:

const rangarang = require('rangarang').default;
rangarang(somehowGetPixelData());

Documentation

rangarang

| Argument name | Type | Description | - | - | - | data | Uint8Array \| Uint8ClampedArray | Image's pixel data. | options | object? | Options. 👇 | options.skipPixels | number? | Number of pixels to skip in each iteration. Defaults to 0 | options.minLuminance | number? | The minimum luminance for an acceptable color. Defaults to 0.2 | options.maxLuminance | number? | The maximum luminance for an acceptable color. Defaults to 0.8 | options.minSaturation | number? | The maximum saturation for an acceptable color. Defaults to 0.1

getDataFromCanvas

| Argument name | Type | Description | - | - | - | image | HTMLImageElement | The source image. | size | number \| (originalWidth: number) => number | Number or function to determine the <canvas>'s size. Bigger number/output results in a faster and less precise operation. Defaults to x => Math.max(80, x / 16)

Development

You can visually test the code:

npm run serve
npm run build -- --watch

Then head to localhost:8080/examples/web.

Todos

  • [ ] Better support for Node.js environments
  • [x] Choose not only one color but more colors (secondary, background, etc.)
  • [x] Allow to modify the behaviour of the code
  • [x] Improve the performance
  • [ ] Write tests