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

primary-color

v1.1.5

Published

This project is simply just used for getting the primary color of an image in nodejs. Please note this is a **Native Node Module**

Downloads

9

Readme

primary-color-v2

This project is simply just used for getting the primary color of an image in nodejs. Please note this is a Native Node Module

How to build your Node Module

prerequisites

  • C++ build tools for your platform (you have to anyways install them while you install rust or nodejs)
  • nodejs
  • rust (only required for manual building)
  • python
  • node-gyp (can be installed with npm i -g node-gyp)

we have to methods for building, a python script (coming soon), or manual building

Method 1. installer script

just run npm i in the root dir of this project

Method 2. Manual Building (assumes linux or macOS)

for this method we need some additional prerequisites which are optional tho.

  • cbindgen (not required for manual building but can be useful);

this tutorial expects that you use a shell

  1. Clone the repo
  2. open up ur terminal
  3. in the root directory of the project: cd primary-color && cargo build --release

please note that the file name can be different on different OSes, on macos for example "libprimary_image_color.a" or on windows "libprimary_image_color.lib" 4. cd .. && mkdir lib && mv primary-color/target/release/libprimary_image_color.a lib 5. node-gyp configure && node-gyp build

Note for windows

once you have completed the building, you need to move the "primary_image_color.dll" file from the primary-color/target/release folder into the build/Release folder

Test it out!

you can test it out with npm test in the root directory (make sure that you have built everything tho :D)

how does it even work?

well well well This project uses multiple technologies those are

  • Rust
  • C++

you can imagine it like a vpn

C++ is used to get the inputs from javascript and return values to javascript, I also decided to use C++ for converting certain stuff etc etc.

Rust on the other hand is where the core, aka the heart of this project lays. I decided to use Rust for the processing of images, and calculating the primary color.

This project uses various techniques to make the usage as simple as possible. for example:

if you want to process multiple images, no problem, just create an array in javascript like this

    let result = addon.primaryColorByImageUrl(
    [
        "https://cdn.discordapp.com/banners/774409449476980746/f67cd20df77e4c15de55a5da0c92bc4c.png?size=1024&format=webp&quality=lossless&width=0&height=256",
        "344",
        "@3232",
        "https://i.pinimg.com/736x/30/0c/30/300c3027c4eec274de2a15bacfc7755f.jpg", "https://i.pinimg.com/736x/dd/11/77/dd1177ae42e5ffcc5572ab9d861b1ef2.jpg"
    ]);

more examples can be found in test/index.js