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

@ion-cloud/ink

v1.0.0

Published

A tiny javascript color manipulation and translation library

Downloads

2

Readme

ink

A tiny javascript color manipulation and translation library

Setup

Getting started is as easy as npm i --save @ion-cloud/ink and then merely importing the library with import ink from '@ion-cloud/ink';.

Please see code example here.

Ink Demo

Ink is a tiny color manipulation or translation library with robust validation and error handling that shines in places where you can't trust the input color or random generation and games. Here are a few of it's main capabilities:

  • translate between color spaces: hex, cmyk, rgb, rgba, hsl, hsla, hsva, hsv, hsba or hsb
  • apply weights to r(ed),g(green),b(lue),l(ightness) or s(aturation)
  • apply a minimum or maximum lightness threshold on a color
  • coerce a color to a certain lightness percent
  • apply a minimum or maximum saturation threshold on a color
  • coerce a color to a certain saturation percent
  • apply an alpha value
  • output to javascript object {r,g,b,a}

Main functions

The structure of the call is as follows:

ink(colorString,optionsObject);

colorString may be 6 character hex

ink('#ffffff') // outputs 'rgba(255,255,255,1)'

colorString may be 3 character hex

ink('#fff') // outputs 'rgba(255,255,255,1)'

colorString may be rgba

ink('rgba(255,255,255,1)') // outputs 'rgba(255,255,255,1)'

colorString may be rgb

ink('rgb(255,255,255)') // outputs 'rgba(255,255,255,1)'

colorString may be hsla (where percents are between 0 and 1)

ink('hsla(0,1,1,0.5)') // outputs 'rgba(255,255,255,0.5)'

colorString may be hsl (where percents are between 0 and 1)

ink('hsl(0,1,1)') // outputs 'rgba(255,255,255,1)'

optionsObject may contain a format attribute with one of the following values: 'hex', 'cmyk', 'rgb', 'rgba', 'hsl', 'hsla', 'hsva', 'hsv', 'hsba', 'hsb', 'object' If opacity manipulation occurs and an output is chosen that doesn't support opacity, any opacity inputs will be ignored.

ink('hsla(0,1,1,0.3)',{format: 'hex'}) // outputs '#ffffff'
ink('#fff',{format: 'object'}) // outputs {r:255,g:255,b:255,a:1}

optionsObject may contain color weights of values between 0 and 1

ink('#fff',{r: 0.5, g:1, b:0.5}) // outputs 'rgba(127,255,127,1)'

optionsObject may contain saturation or lightness weights

ink('#955',{l: 0.5, s:-0.2,format: 'hex'}) //outputs '#f7f6f6'

optionsObject may contain an alpha value between 0 and 1

ink('#fff',{a: 0.5}) // outputs 'rgba(255,255,255,0.5)'

optionsObject may contain minLightness value between 0 and 1 it will ensure the result is at least as bright as this percent

ink('#333',{minLightness: 0.3}) // outputs 'rgba(91,91,91,1)'

optionsObject may contain maxLightness value between 0 and 1 it will ensure the result is no brighter than this percent

ink('#fff',{maxLightness: 0.8}) // outputs 'rgba(202,202,202,1)'

optionsObject may contain lightness value between 0 and 1 this will override any min or max lightness values sent in if they exists

ink('#fff',{lightness: 0.8}) // outputs 'rgba(202,202,202,1)'

optionsObject may contain minSaturation value between 0 and 1 it will ensure the result is at least as saturated as this percent if the color type input wasn't a hsl(a) value and there wasn't a hue property passed in and the color is a shade of gray then the hue will be 0 by default (red). hue is a value between 0 and 360 and represents degrees

ink('#878787',{minSaturation: 0.32}) // outputs 'rgba(174,97,97,1)'
ink('#878787',{minSaturation: 0.32, hue: 105}) // outputs 'rgba(116,174,97,1)'
ink('#50AF50',{minSaturation: 0.61}) // outputs 'rgba(50,205,50,1)'

optionsObject may contain maxSaturation value between 0 and 1 it will ensure the result is no more saturated than this percent if the color type input wasn't a hsl(a) value and there wasn't a hue property passed in and the color is a shade of gray then the hue will be 0 by default (red). hue is a value between 0 and 360 and represents degrees

ink('#0f0',{maxSaturation: 0.5}) // outputs 'rgba(191,64,64,1)'

optionsObject may contain saturation value between 0 and 1 this will override any min or max saturation values sent in if they exist

ink('#64CE5A',{saturation: 0.17,format: 'hex'}) // outputs '#85A682';

Helper functions

You can use any color string as a source and then specify the output. Merely import the helper function specifically.

import {convert2rgba} from 'ion-cloud';
  • convert2rgba(colorString)
  • convert2rgb(colorString)
  • convert2hsba(colorString)
  • convert2hsva(colorString)
  • convert2hsb(colorString)
  • convert2hsv(colorString)
  • convert2hlsa(colorString)
  • convert2hsl(colorString)
  • convert2hex(colorString)