@fils/color 0.0.1 → 0.0.4

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/lib/utils.d.ts CHANGED
@@ -16,6 +16,7 @@ export type HSLColor = {
16
16
  export declare function componentToHex(c: number): string;
17
17
  export declare function rgbToHex(color: RGBColor): string;
18
18
  export declare function hexToRgb(hex: string): RGBColor;
19
+ export declare function hexToHsb(hex: string): HSBColor;
19
20
  export declare function rgbToHsl(color: RGBColor): HSLColor;
20
21
  export declare function hslToRgb(color: HSLColor): RGBColor;
21
22
  export declare function hslToHex(color: HSLColor): string;
@@ -24,3 +25,4 @@ export declare function hsbToRgb(color: HSBColor): RGBColor;
24
25
  export declare function hsbToHex(color: HSBColor): string;
25
26
  export declare function rgbToString(color: RGBColor): string;
26
27
  export declare function hsbToString(color: HSBColor): string;
28
+ export declare function fixHex(color: string): string;
package/lib/utils.js CHANGED
@@ -13,6 +13,9 @@ export function hexToRgb(hex) {
13
13
  b: parseInt(result[3], 16)
14
14
  } : { r: 0, g: 0, b: 0 };
15
15
  }
16
+ export function hexToHsb(hex) {
17
+ return rgbToHsb(hexToRgb(hex));
18
+ }
16
19
  export function rgbToHsl(color) {
17
20
  const r = color.r / 255, g = color.g / 255, b = color.b / 255;
18
21
  const max = Math.max(r, g, b);
@@ -127,3 +130,47 @@ export function rgbToString(color) {
127
130
  export function hsbToString(color) {
128
131
  return `H: ${color.h}, S: ${color.s}, B: ${color.b}`;
129
132
  }
133
+ export function fixHex(color) {
134
+ let fixedColor = color;
135
+ if (fixedColor.substring(0, 1) !== "#") {
136
+ fixedColor = "#" + fixedColor;
137
+ }
138
+ fixedColor = fixedColor.toUpperCase();
139
+ fixedColor = fixedColor.substring(0, 7);
140
+ if (fixedColor.length === 4) {
141
+ fixedColor = "#" + fixedColor[1] + fixedColor[1] + fixedColor[2] + fixedColor[2] + fixedColor[3] + fixedColor[3];
142
+ }
143
+ while (fixedColor.length < 7) {
144
+ fixedColor += "F";
145
+ }
146
+ fixedColor = fixedColor.replace(/[^A-F0-9]/g, (c) => {
147
+ switch (c) {
148
+ case "#":
149
+ return "#";
150
+ case "G":
151
+ case "H":
152
+ case "I":
153
+ case "J":
154
+ case "K":
155
+ case "L":
156
+ case "M":
157
+ case "N":
158
+ case "O":
159
+ case "P":
160
+ case "Q":
161
+ case "R":
162
+ case "S":
163
+ case "T":
164
+ case "U":
165
+ case "V":
166
+ case "W":
167
+ case "X":
168
+ case "Y":
169
+ case "Z":
170
+ return "F";
171
+ default:
172
+ return "0";
173
+ }
174
+ });
175
+ return fixedColor;
176
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fils/color",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "description": "Color Package written in TypeScript",
5
5
  "main": "lib/main.js",
6
6
  "repository": "git@github.com:fil-studio/fils.git",
@@ -9,6 +9,7 @@
9
9
  "license": "Apache-2.0",
10
10
  "private": false,
11
11
  "scripts": {
12
+ "publish": "yarn build && npm publish --access public",
12
13
  "prepare": "yarn build",
13
14
  "build": "tsc --build tsconfig.color.json"
14
15
  },