colorpedia 1.0.2 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Clearer/index.js +11 -9
- package/Darker/index.js +11 -9
- package/README.md +124 -4
- package/package.json +28 -25
package/Clearer/index.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
const convert = require("../Convert");
|
|
2
2
|
|
|
3
3
|
function calcPercent(value, percentage) {
|
|
4
|
-
return Math.ceil(value + value * (percentage / 100));
|
|
4
|
+
return Math.min(255, Math.ceil(value + value * (percentage / 100)));
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function hex(hex, percentage) {
|
|
8
8
|
if (!hex || !percentage) return null;
|
|
9
9
|
let { r, g, b } = convert.hexToRgb(hex);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
return convert.rgbToHex(
|
|
11
|
+
calcPercent(r, percentage),
|
|
12
|
+
calcPercent(g, percentage),
|
|
13
|
+
calcPercent(b, percentage)
|
|
14
|
+
);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
function rgb(r, g, b, percentage) {
|
|
17
18
|
if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
return {
|
|
20
|
+
r: calcPercent(r, percentage),
|
|
21
|
+
g: calcPercent(g, percentage),
|
|
22
|
+
b: calcPercent(b, percentage),
|
|
23
|
+
};
|
|
22
24
|
}
|
|
23
25
|
return null;
|
|
24
26
|
}
|
package/Darker/index.js
CHANGED
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
const convert = require("../Convert");
|
|
2
2
|
|
|
3
3
|
function calcPercent(value, percentage) {
|
|
4
|
-
return Math.floor(value - value * (percentage / 100));
|
|
4
|
+
return Math.max(0, Math.floor(value - value * (percentage / 100)));
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
function hex(hex, percentage) {
|
|
8
8
|
if (!hex || !percentage) return null;
|
|
9
9
|
let { r, g, b } = convert.hexToRgb(hex);
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
return convert.rgbToHex(
|
|
11
|
+
calcPercent(r, percentage),
|
|
12
|
+
calcPercent(g, percentage),
|
|
13
|
+
calcPercent(b, percentage)
|
|
14
|
+
);
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
function rgb(r, g, b, percentage) {
|
|
17
18
|
if (!isNaN(r) && !isNaN(g) && !isNaN(b)) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
return {
|
|
20
|
+
r: calcPercent(r, percentage),
|
|
21
|
+
g: calcPercent(g, percentage),
|
|
22
|
+
b: calcPercent(b, percentage),
|
|
23
|
+
};
|
|
22
24
|
}
|
|
23
25
|
return null;
|
|
24
26
|
}
|
package/README.md
CHANGED
|
@@ -1,19 +1,139 @@
|
|
|
1
1
|
## Installation
|
|
2
2
|
|
|
3
|
-
Install colorpedia with npm
|
|
3
|
+
#### Install colorpedia with npm
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
npm i --save colorpedia
|
|
7
7
|
```
|
|
8
8
|
|
|
9
|
+
#### Install colorpedia with yarn
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
yarn add colorpedia
|
|
13
|
+
```
|
|
14
|
+
|
|
9
15
|
## Usage/Examples
|
|
10
16
|
|
|
17
|
+
### Convert
|
|
18
|
+
|
|
11
19
|
- hexToRgb(hex: string): { r: number, g: number, b: number } | null
|
|
12
20
|
|
|
13
21
|
```javascript
|
|
14
|
-
import {
|
|
22
|
+
import { convert } from "colorpedia";
|
|
23
|
+
|
|
24
|
+
const { r, g, b } = convert.hexToRgb("#6c34f2"); // { r: 108, g: 52, b: 242 }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
**Convert** *hexadecimal* to *rgb*
|
|
28
|
+
|
|
29
|
+
- rgbToHex(r: number, g: number, b: number): hex: string | null
|
|
30
|
+
|
|
31
|
+
```javascript
|
|
32
|
+
import { convert } from "colorpedia";
|
|
33
|
+
|
|
34
|
+
const hex = convert.rgbToHex(108, 52, 242); // hex: "#6c34f2"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Convert** *rgb* color to *hexadecimal* color
|
|
38
|
+
|
|
39
|
+
### Clearer
|
|
40
|
+
|
|
41
|
+
- hex(hex: string, percentage: number): hex: string | null
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { clearer } from "colorpedia";
|
|
45
|
+
|
|
46
|
+
const hexClearer = clearer.hex("#6c34f2", 20); // hex: "#823fff"
|
|
47
|
+
const hexMoreClearer = clearer.hex("#6c34f2", 40); // hex: "#9849ff"
|
|
48
|
+
const hexEvenClearer = clearer.hex("#6c34f2", 60); // hex: "#ad54ff"
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
**Cleared** *hex* in 20, 40 and 60 percent
|
|
52
|
+
|
|
53
|
+
- rgb(r: number, g: number, b: number): { r: number, g: number, b: number} | null
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import { clearer } from "colorpedia";
|
|
57
|
+
|
|
58
|
+
const rgbClearer = clearer.rgb(108, 52, 242, 20); // { r: 130, g: 63, b: 255 }
|
|
59
|
+
const rgbMoreClearer = clearer.rgb(108, 52, 242, 40); // { r: 152, g: 73, b: 255 }
|
|
60
|
+
const rgbEvenClearer = clearer.rgb(108, 52, 242, 60); // { r: 173, g: 84, b: 255 }
|
|
61
|
+
|
|
62
|
+
const { r, g, b } = rgbClearer;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**Cleared** *rgb* in 20, 40 and 60 percent
|
|
66
|
+
|
|
67
|
+
### Darker
|
|
68
|
+
|
|
69
|
+
- hex(hex: string, percentage: number): hex: string | null
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import { darker } from "colorpedia";
|
|
73
|
+
|
|
74
|
+
const hexDarker = darker.hex("#6c34f2", 20); // hex: "#5629c1"
|
|
75
|
+
const hexMoreDarker = darker.hex("#6c34f2", 40); // hex: "#401f91"
|
|
76
|
+
const hexEvenDarker = darker.hex("#6c34f2", 60); // hex: "#2b1460"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
**Darker** *hex* in 20, 40 and 60 percent
|
|
80
|
+
|
|
81
|
+
- rgb(r: number, g: number, b: number): { r: number, g: number, b: number} | null
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
import { darker } from "colorpedia";
|
|
85
|
+
|
|
86
|
+
const rgbDarker = darker.rgb(108, 52, 242, 20); // { r: 86, g: 41, b: 193 }
|
|
87
|
+
const rgbMoreDarker = darker.rgb(108, 52, 242, 40); // { r: 64, g: 31, b: 145 }
|
|
88
|
+
const rgbEvenDarker = darker.rgb(108, 52, 242, 60); // { r: 43, g: 20, b: 96 }
|
|
89
|
+
|
|
90
|
+
const { r, g, b} = rgbDarker;
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Darker** *rgb* in 20, 40 and 60 percent
|
|
94
|
+
|
|
95
|
+
### Invert
|
|
96
|
+
|
|
97
|
+
- hex(hex: string): hex: string | null
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import { invert } from "colorpedia";
|
|
101
|
+
|
|
102
|
+
const hexInverted = invert.hex("#6c34f2"); // hex: "#93cb0d"
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
*hex* has been **Inverted**
|
|
106
|
+
|
|
107
|
+
- rgb(r: number, g: number, b: number): { r: number, g: number, b: number} | null
|
|
108
|
+
|
|
109
|
+
```javascript
|
|
110
|
+
import { invert } from "colorpedia";
|
|
111
|
+
|
|
112
|
+
const rgbInverted = invert.rgb(108, 52, 242, 20); // { r: 147, g: 203, b: 13 }
|
|
113
|
+
|
|
114
|
+
const { r, g, b} = rgbInverted;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
*rgb* has been **Inverted**
|
|
118
|
+
|
|
119
|
+
### Lightness
|
|
120
|
+
|
|
121
|
+
- hex(hex: string): lightness: number | null
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
import { lightness } from "colorpedia";
|
|
125
|
+
|
|
126
|
+
const hexLightness = lightness.hex("#6c34f2"); // lightness: 0.5764705882352941
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
Function has returned the **lighness** of *hex*
|
|
130
|
+
|
|
131
|
+
- rgb(r: number, g: number, b: number): { r: number, g: number, b: number} | null
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
import { lightness } from "colorpedia";
|
|
15
135
|
|
|
16
|
-
const
|
|
136
|
+
const rgbLightness = lightness.rgb(108, 52, 242, 20); // lightness: 0.5764705882352941
|
|
17
137
|
```
|
|
18
138
|
|
|
19
|
-
|
|
139
|
+
Function has returned the **lighness** of *rgb*
|
package/package.json
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "colorpedia",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Package useful to everything you want to do with colors.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
|
-
"repository": {
|
|
10
|
-
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
12
|
-
},
|
|
13
|
-
"keywords": [
|
|
14
|
-
"colors",
|
|
15
|
-
"convert",
|
|
16
|
-
"hex",
|
|
17
|
-
"rgb"
|
|
18
|
-
],
|
|
19
|
-
"author": "naul",
|
|
20
|
-
"license": "ISC",
|
|
21
|
-
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
23
|
-
},
|
|
24
|
-
"homepage": "https://github.com/
|
|
25
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "colorpedia",
|
|
3
|
+
"version": "1.0.5",
|
|
4
|
+
"description": "Package useful to everything you want to do with colors.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/NaulEpilef/colorpedia.git"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"colors",
|
|
15
|
+
"convert",
|
|
16
|
+
"hex",
|
|
17
|
+
"rgb"
|
|
18
|
+
],
|
|
19
|
+
"author": "naul",
|
|
20
|
+
"license": "ISC",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/NaulEpilef/colorpedia/issues"
|
|
23
|
+
},
|
|
24
|
+
"homepage": "https://github.com/NaulEpilef/colorpedia#readme",
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"colorpedia": "file:"
|
|
27
|
+
}
|
|
28
|
+
}
|