@etsoo/shared 1.1.25 → 1.1.26
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/__tests__/ColorUtils.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { EColor } from '../src/types/EColor';
|
|
2
2
|
import { ColorUtils } from '../src/ColorUtils';
|
|
3
3
|
|
|
4
|
+
test('Tests for format', () => {
|
|
5
|
+
expect(EColor.format('transparent')).toBe('transparent');
|
|
6
|
+
expect(EColor.format('RED')).toBe('red');
|
|
7
|
+
expect(EColor.format('RGB(226, 24, 33)', true)).toBe('#e21821');
|
|
8
|
+
expect(EColor.format('RGB(226, 24, 33)')).toBe('RGB(226, 24, 33)');
|
|
9
|
+
});
|
|
10
|
+
|
|
4
11
|
test('Tests for parse', () => {
|
|
5
12
|
// Arrange & act
|
|
6
13
|
const colorShort = EColor.parse('#000');
|
|
@@ -13,6 +13,13 @@ export declare class EColor {
|
|
|
13
13
|
* @returns Adjusted value
|
|
14
14
|
*/
|
|
15
15
|
static adjust(value: number, adjust?: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Format color
|
|
18
|
+
* @param input Input color text
|
|
19
|
+
* @param hexColor Format as Hex color
|
|
20
|
+
* @returns Result
|
|
21
|
+
*/
|
|
22
|
+
static format(input: string | undefined | null, hexColor?: boolean): string | undefined;
|
|
16
23
|
/**
|
|
17
24
|
* HEX string to integer value
|
|
18
25
|
* @param hex HEX string
|
package/lib/cjs/types/EColor.js
CHANGED
|
@@ -32,6 +32,24 @@ class EColor {
|
|
|
32
32
|
return value % 255;
|
|
33
33
|
return value;
|
|
34
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Format color
|
|
37
|
+
* @param input Input color text
|
|
38
|
+
* @param hexColor Format as Hex color
|
|
39
|
+
* @returns Result
|
|
40
|
+
*/
|
|
41
|
+
static format(input, hexColor) {
|
|
42
|
+
// Null
|
|
43
|
+
if (input == null)
|
|
44
|
+
return undefined;
|
|
45
|
+
// Like transparent, black, red
|
|
46
|
+
if (/^[a-zA-Z]+$/gi.test(input))
|
|
47
|
+
return input.toLowerCase();
|
|
48
|
+
const color = EColor.parse(input);
|
|
49
|
+
if (color == null)
|
|
50
|
+
return undefined;
|
|
51
|
+
return hexColor ? color.toHEXColor() : color.toRGBColor();
|
|
52
|
+
}
|
|
35
53
|
/**
|
|
36
54
|
* HEX string to integer value
|
|
37
55
|
* @param hex HEX string
|
|
@@ -13,6 +13,13 @@ export declare class EColor {
|
|
|
13
13
|
* @returns Adjusted value
|
|
14
14
|
*/
|
|
15
15
|
static adjust(value: number, adjust?: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Format color
|
|
18
|
+
* @param input Input color text
|
|
19
|
+
* @param hexColor Format as Hex color
|
|
20
|
+
* @returns Result
|
|
21
|
+
*/
|
|
22
|
+
static format(input: string | undefined | null, hexColor?: boolean): string | undefined;
|
|
16
23
|
/**
|
|
17
24
|
* HEX string to integer value
|
|
18
25
|
* @param hex HEX string
|
package/lib/mjs/types/EColor.js
CHANGED
|
@@ -29,6 +29,24 @@ export class EColor {
|
|
|
29
29
|
return value % 255;
|
|
30
30
|
return value;
|
|
31
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Format color
|
|
34
|
+
* @param input Input color text
|
|
35
|
+
* @param hexColor Format as Hex color
|
|
36
|
+
* @returns Result
|
|
37
|
+
*/
|
|
38
|
+
static format(input, hexColor) {
|
|
39
|
+
// Null
|
|
40
|
+
if (input == null)
|
|
41
|
+
return undefined;
|
|
42
|
+
// Like transparent, black, red
|
|
43
|
+
if (/^[a-zA-Z]+$/gi.test(input))
|
|
44
|
+
return input.toLowerCase();
|
|
45
|
+
const color = EColor.parse(input);
|
|
46
|
+
if (color == null)
|
|
47
|
+
return undefined;
|
|
48
|
+
return hexColor ? color.toHEXColor() : color.toRGBColor();
|
|
49
|
+
}
|
|
32
50
|
/**
|
|
33
51
|
* HEX string to integer value
|
|
34
52
|
* @param hex HEX string
|
package/package.json
CHANGED
package/src/types/EColor.ts
CHANGED
|
@@ -15,6 +15,25 @@ export class EColor {
|
|
|
15
15
|
return value;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Format color
|
|
20
|
+
* @param input Input color text
|
|
21
|
+
* @param hexColor Format as Hex color
|
|
22
|
+
* @returns Result
|
|
23
|
+
*/
|
|
24
|
+
static format(input: string | undefined | null, hexColor?: boolean) {
|
|
25
|
+
// Null
|
|
26
|
+
if (input == null) return undefined;
|
|
27
|
+
|
|
28
|
+
// Like transparent, black, red
|
|
29
|
+
if (/^[a-zA-Z]+$/gi.test(input)) return input.toLowerCase();
|
|
30
|
+
|
|
31
|
+
const color = EColor.parse(input);
|
|
32
|
+
if (color == null) return undefined;
|
|
33
|
+
|
|
34
|
+
return hexColor ? color.toHEXColor() : color.toRGBColor();
|
|
35
|
+
}
|
|
36
|
+
|
|
18
37
|
/**
|
|
19
38
|
* HEX string to integer value
|
|
20
39
|
* @param hex HEX string
|