1.0.109 • Published 1 year ago

css-filter-converter v1.0.109

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

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!

1.0.109

1 year ago

1.0.101

2 years ago

1.0.100

2 years ago

1.0.107

2 years ago

1.0.106

2 years ago

1.0.108

2 years ago

1.0.103

2 years ago

1.0.102

2 years ago

1.0.105

2 years ago

1.0.104

2 years ago

1.0.95

2 years ago

1.0.94

2 years ago

1.0.99

2 years ago

1.0.98

2 years ago

1.0.96

2 years ago

1.0.93

2 years ago

1.0.92

2 years ago

1.0.91

2 years ago

1.0.90

2 years ago

1.0.89

2 years ago

1.0.88

2 years ago

1.0.87

2 years ago

1.0.86

2 years ago

1.0.85

2 years ago

1.0.84

2 years ago

1.0.83

2 years ago

1.0.82

2 years ago

1.0.81

2 years ago

1.0.80

2 years ago

1.0.79

2 years ago

1.0.78

2 years ago

1.0.77

2 years ago

1.0.76

2 years ago

1.0.75

2 years ago

1.0.74

2 years ago

1.0.73

2 years ago

1.0.72

2 years ago

1.0.71

2 years ago

1.0.70

2 years ago

1.0.69

2 years ago

1.0.68

2 years ago

1.0.67

2 years ago

1.0.66

2 years ago

1.0.65

2 years ago

1.0.64

2 years ago

1.0.63

2 years ago

1.0.62

2 years ago

1.0.61

2 years ago

1.0.60

2 years ago

1.0.59

2 years ago

1.0.58

2 years ago

1.0.57

2 years ago

1.0.56

2 years ago

1.0.55

2 years ago

1.0.54

2 years ago

1.0.53

2 years ago

1.0.52

2 years ago

1.0.51

2 years ago

1.0.50

2 years ago

1.0.49

2 years ago

1.0.48

2 years ago

1.0.47

2 years ago

1.0.46

2 years ago

1.0.45

2 years ago

1.0.44

2 years ago

1.0.43

2 years ago

1.0.42

2 years ago

1.0.41

2 years ago

1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.36

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago