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

css-filter-converter

v1.0.109

Published

A tool used to generate css filter color property via hexadecimal or rgb color formats

Downloads

9,321

Readme

Description

CSS Filter Converter is a simple tool used for converting basic css color formats to and from css filter.

Installation

npm install css-filter-converter

If you want the capability to convert from filter to a basic color, please additionally install puppeteer by running the following command:

npm install puppeteer

How to use

import CssFilterConverter from 'css-filter-converter';

// converting from basic color to filter
const result = CssFilterConverter.hexToFilter('#69A1DE');

// converting from filter to basic color
CssFilterConverter.filterToHex('brightness(0) saturate(100%) invert(58%) sepia(55%) saturate(365%) hue-rotate(171deg) brightness(93%) contrast(98%)').then((result) => result);

const result = await CssFilterConverter.filterToHex('brightness(0) saturate(100%) invert(58%) sepia(55%) saturate(365%) hue-rotate(171deg) brightness(93%) contrast(98%)');

API

Color to filter

// hex
hexToFilter('#69A1DE');
hexToFilter('#69A');

// rgb
rgbToFilter('rgb(106, 161, 225)');
rgbToFilter('106 161 225');

// hsl
hslToFilter('hsl(212deg, 66%, 65%)');
hslToFilter('212 66 65');

// keyword
keywordToFilter('blue');
// Full list of valid keyword values can be viewed in the following link: https://github.com/colorjs/color-name/blob/master/index.js 

Options: | Name | Values | Default value | Description | | :---------: | :-: | :-: | :- | | sheen | true/false | true | Reinforces the strength of resultant filter color by prepending the following properties 'brightness(0) saturate(100%)'. Recommended to leave enabled for SVG images. |

hexToFilter('#69A1DE', { sheen: false });

Result object: | Property Name | Nested Property | Type | Description | | :---------: | :-: | :-: | :- | | color | - | string | Css filter value. | | loss | - | number | Every execution of color to filter conversion will result in a slightly different color value due to the randomization used in the filter value generation process. This will cause some results to be more further away from the input color than others, which is quantified by the loss value. | | error | message | string | This library does not throw runtime errors and instead populates the error key with an object containing a message property that describes the reason for the error occurance. |

const result = hexToFilter('#69A1DE');
// { color: 'brightness(0) saturate(100%) invert(58%) sepia(55%) saturate(365%) hue-rotate(171deg) brightness(93%) contrast(98%)', loss: 0.99, error: null }

Filter to color

const filterString = 'brightness(0) saturate(100%) invert(58%) sepia(55%) saturate(365%) hue-rotate(171deg) brightness(93%) contrast(98%)';

// hex
filterToHex(filterString);

// rgb
filterToRgb(filterString);

// hsl
filterToHsl(filterString);

// conversion from filter is asynchronous and the result can be accessed in one of the following ways:

const result = await filterToHex(filterString);

CssFilterConverter.filterToHex(filterString).then((result) => {});

Options: | Name | Values | Default value | Colors | Description | | :---------: | :-: | :-: | :-: | :- | | resultType | 'array'/'string' | 'array' | RGB/HSL | Returns either an array or a formatted string. |

const stringResult = await filterToRgb(filterString, { resultType: 'array' });
// { color: [125, 125, 125] }

const arrayResult = await filterToRgb(filterString, { resultType: 'string' });
// { color: 'rgb(125, 125, 125)' }

Result object: | Property Name | Nested Property | Type | Description | | :---------: | :-: | :-: | :- | | color | - | string/array | Color result. Value type is dependent on the color type or the 'resultType' option value. | | error | message | string | This library does not throw runtime errors and instead populates the error key with an object containing a message property that describes the reason for the error occurance. |

const result = await filterToHex(filterString);
// { color: '#6AA1E1', error: null }

Local setup

# Requirements: Node version 8+ and NPM version 6+

# Install node dependencies:
$ npm install

# Execute index.ts code directly:
$ npm run execute

# Transpile on save:
$ npm run watch

# Run tests:
$ npm run test

Contributions

Open source is built by the community for the community. All contributions to this project are welcome! Additionally, if you have any suggestions for enhancements, ideas on how to take the project further or have discovered a bug, do not hesitate to create a new issue ticket and we will look into it as soon as possible!