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

c3-module

v1.1.1

Published

A JavaScript library for color name modeling.

Downloads

17

Readme

C3

C3 (Categorical Color Components) is a JavaScript library for modeling color naming data. It can be used to create a variety of applications, including improved color selection, image editing, or palette analysis tools.

C3 also includes backend components (written in Java) for processing raw color naming data and producing a compact model of color naming. The resulting JSON model file is loaded by the client C3 library.

This is a fork of C3 that makes it possible to use the library as a ES6 module (eg. so you can use import { load } from "c3-module").

It can be installed by running npm i c3-module.

Example usage:

import * as c3 from 'c3-module';

// You can use the c3 object as shown in the examples now.
// Example: find and print 3 red colors
const redIndex = c3.terms.findIndex(e => e == "red");
const colorIndexes = c3.termsRelatedColors(redIndex, 3);
colorIndexes.forEach(ci => console.log(c3.color[ci.index].css("rgb"))); 
// rgb(220, 0, 15)
// rgb(198, 0, 0)
// rgb(198, 0, 14)

// Example: find and print 3 terms related to "red"
const termIndexes = c3.termsRelatedTerms(redIndex, 3);
termIndexes.forEach(ti => console.log(c3.terms[ti.index])) 
// red
// brightred
// bloodred

A difference between this fork and the original c3 library is how you access data and functions. c3.terms and c3.colors are the same, but functions like c3.terms.relatedColors are now c3.termsRelatedColors to avoid overloading built in JavaScript.

Another difference is that instead of keeping track of colors using d3-colors, this library use chroma-js which means you access color information as described in their documentation.

Finally, the full size of the compiled script is about 2 MB, primarely because the data file is now embedded into the script. This is done to make it easier to use the library without hosting the data, and avoids having to wait for the data to load during runtime.

Development Setup

The easiest way to work with the library is to have a local project that includes this project as a local dependency, eg. by running npm i /path/to/c3-module and then use it as in the example.

Compile using npx tsup src/index.ts or with type declarations npx tsup src/index.ts --dts.

If the compiler complains about Cannot find module ..., try installing typescript globally and link it.

npm i typescript -g
npm link typescript