Skip to content

Commit b25f126

Browse files
committed
updates for colors, saturation and desaturation
1 parent 48e1cce commit b25f126

File tree

7 files changed

+50
-26
lines changed

7 files changed

+50
-26
lines changed

desaturate/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Color from "color";
2+
import ensureHexFormat from "../ensureHexFormat";
3+
4+
/**
5+
* Lightens a color.
6+
* @param color - The base color in hex format.
7+
* @param coefficient - The coefficient between 0 and 1 to determine how much to lighten the color.
8+
* @returns The lightened color in hex format.
9+
*/
10+
function desaturate(color: string, coefficient: number): string {
11+
const c = Color(color).desaturate(coefficient).hex();
12+
return ensureHexFormat(c);
13+
}
14+
15+
export default desaturate;

index.ts

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
import Color from 'color';
2-
import ensureHexFormat from "./ensureHexFormat";
1+
import ligthen from "./lighten";
2+
import darken from "./darken";
3+
import saturate from "./saturate";
4+
import desaturate from "./desaturate";
35

4-
/**
5-
* Darkens a color.
6-
* @param color - The base color in hex format.
7-
* @param coefficient - The coefficient between 0 and 1 to determine how much to darken the color.
8-
* @returns The darkened color in hex format.
9-
*/
10-
export function darken(color: string, coefficient: number): string {
11-
const c = Color(color).darken(coefficient).hex();
12-
return ensureHexFormat(c);
13-
}
14-
15-
/**
16-
* Lightens a color.
17-
* @param color - The base color in hex format.
18-
* @param coefficient - The coefficient between 0 and 1 to determine how much to lighten the color.
19-
* @returns The lightened color in hex format.
20-
*/
21-
export function lighten(color: string, coefficient: number): string {
22-
const c = Color(color).lighten(coefficient).hex();
23-
return ensureHexFormat(c);
24-
}
6+
export { ligthen, darken, saturate, desaturate, };

lighten/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import Color from "color";
22
import ensureHexFormat from "../ensureHexFormat";
33

4+
/**
5+
* Lightens a color.
6+
* @param color - The base color in hex format.
7+
* @param coefficient - The coefficient between 0 and 1 to determine how much to lighten the color.
8+
* @returns The lightened color in hex format.
9+
*/
410
function lighten(color: string, coefficient: number): string {
511
const c = Color(color).lighten(coefficient).hex();
612
return ensureHexFormat(c);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "color-manipulation-utils",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "Check contrast of colors HEX",
55
"main": "index.js",
66
"types": "index.d.ts",

saturate/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import Color from "color";
2+
import ensureHexFormat from "../ensureHexFormat";
3+
4+
/**
5+
* Lightens a color.
6+
* @param color - The base color in hex format.
7+
* @param coefficient - The coefficient between 0 and 1 to determine how much to lighten the color.
8+
* @returns The lightened color in hex format.
9+
*/
10+
function saturate(color: string, coefficient: number): string {
11+
const c = Color(color).saturate(coefficient).hex();
12+
return ensureHexFormat(c);
13+
}
14+
15+
export default saturate;

test/test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import { lighten, darken } from "../index";
1+
import { ligthen, darken, desaturate, saturate } from "../index";
22

3-
console.log(lighten('#7a0f0f', 0.2));
3+
console.log(ligthen('#7a0f0f', 0.2));
44
console.log(darken('#068806', 0.8));
5+
console.log(desaturate('#ffaf30', 0.8));
6+
console.log(saturate('#000fff', 0.8));

test/testDefault.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import lighten from "../lighten/index";
22
import darken from "../darken/index";
3+
import desaturate from "../desaturate";
4+
import saturate from "../saturate";
35

46
console.log(lighten('#7a0f0f', 0.2));
57
console.log(darken('#ffaf30', 0.2));
8+
console.log(desaturate('#30ff6b', 0.2));
9+
console.log(saturate('#ff30a5', 0.2));

0 commit comments

Comments
 (0)