@etsoo/shared 1.1.16 → 1.1.17
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__/EColor.ts +7 -0
- package/lib/cjs/types/EColor.d.ts +2 -2
- package/lib/cjs/types/EColor.js +15 -6
- package/lib/mjs/types/EColor.d.ts +2 -2
- package/lib/mjs/types/EColor.js +15 -6
- package/package.json +3 -3
- package/src/types/EColor.ts +15 -5
package/__tests__/EColor.ts
CHANGED
|
@@ -16,3 +16,10 @@ test('Tests for getColors', () => {
|
|
|
16
16
|
const colors = EColor.getColors(undefined, 128);
|
|
17
17
|
expect(colors.length).toBe(8);
|
|
18
18
|
});
|
|
19
|
+
|
|
20
|
+
test('Tests for toRGBColor', () => {
|
|
21
|
+
const color = new EColor(0, 0, 0);
|
|
22
|
+
expect(color.toRGBColor()).toBe('RGB(0, 0, 0)');
|
|
23
|
+
expect(color.toRGBColor(0.1)).toBe('RGBA(0, 0, 0, 0.1)');
|
|
24
|
+
expect(color.alpha).toBeUndefined();
|
|
25
|
+
});
|
|
@@ -98,8 +98,8 @@ export declare class EColor {
|
|
|
98
98
|
toLabValue(): [number, number, number];
|
|
99
99
|
/**
|
|
100
100
|
* To RGB color string
|
|
101
|
-
* @param
|
|
101
|
+
* @param alpha Alpha value, false means ignore it
|
|
102
102
|
* @returns RGB color string
|
|
103
103
|
*/
|
|
104
|
-
toRGBColor(
|
|
104
|
+
toRGBColor(alpha?: boolean | number): string;
|
|
105
105
|
}
|
package/lib/cjs/types/EColor.js
CHANGED
|
@@ -250,15 +250,24 @@ class EColor {
|
|
|
250
250
|
}
|
|
251
251
|
/**
|
|
252
252
|
* To RGB color string
|
|
253
|
-
* @param
|
|
253
|
+
* @param alpha Alpha value, false means ignore it
|
|
254
254
|
* @returns RGB color string
|
|
255
255
|
*/
|
|
256
|
-
toRGBColor(
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
toRGBColor(alpha) {
|
|
257
|
+
// Decide
|
|
258
|
+
let includeAlpha, alphaValue = this.alpha;
|
|
259
|
+
if (typeof alpha === 'number') {
|
|
260
|
+
alphaValue = alpha;
|
|
261
|
+
includeAlpha = true;
|
|
262
|
+
}
|
|
263
|
+
else if (alpha == null) {
|
|
264
|
+
includeAlpha = this.alpha != null;
|
|
265
|
+
}
|
|
266
|
+
else {
|
|
267
|
+
includeAlpha = alpha;
|
|
268
|
+
}
|
|
260
269
|
if (includeAlpha)
|
|
261
|
-
return `RGBA(${this.r}, ${this.g}, ${this.b}, ${
|
|
270
|
+
return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue !== null && alphaValue !== void 0 ? alphaValue : 1})`;
|
|
262
271
|
return `RGB(${this.r}, ${this.g}, ${this.b})`;
|
|
263
272
|
}
|
|
264
273
|
}
|
|
@@ -98,8 +98,8 @@ export declare class EColor {
|
|
|
98
98
|
toLabValue(): [number, number, number];
|
|
99
99
|
/**
|
|
100
100
|
* To RGB color string
|
|
101
|
-
* @param
|
|
101
|
+
* @param alpha Alpha value, false means ignore it
|
|
102
102
|
* @returns RGB color string
|
|
103
103
|
*/
|
|
104
|
-
toRGBColor(
|
|
104
|
+
toRGBColor(alpha?: boolean | number): string;
|
|
105
105
|
}
|
package/lib/mjs/types/EColor.js
CHANGED
|
@@ -247,15 +247,24 @@ export class EColor {
|
|
|
247
247
|
}
|
|
248
248
|
/**
|
|
249
249
|
* To RGB color string
|
|
250
|
-
* @param
|
|
250
|
+
* @param alpha Alpha value, false means ignore it
|
|
251
251
|
* @returns RGB color string
|
|
252
252
|
*/
|
|
253
|
-
toRGBColor(
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
253
|
+
toRGBColor(alpha) {
|
|
254
|
+
// Decide
|
|
255
|
+
let includeAlpha, alphaValue = this.alpha;
|
|
256
|
+
if (typeof alpha === 'number') {
|
|
257
|
+
alphaValue = alpha;
|
|
258
|
+
includeAlpha = true;
|
|
259
|
+
}
|
|
260
|
+
else if (alpha == null) {
|
|
261
|
+
includeAlpha = this.alpha != null;
|
|
262
|
+
}
|
|
263
|
+
else {
|
|
264
|
+
includeAlpha = alpha;
|
|
265
|
+
}
|
|
257
266
|
if (includeAlpha)
|
|
258
|
-
return `RGBA(${this.r}, ${this.g}, ${this.b}, ${
|
|
267
|
+
return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue !== null && alphaValue !== void 0 ? alphaValue : 1})`;
|
|
259
268
|
return `RGB(${this.r}, ${this.g}, ${this.b})`;
|
|
260
269
|
}
|
|
261
270
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/shared",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.17",
|
|
4
4
|
"description": "TypeScript shared utilities and functions",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -55,8 +55,8 @@
|
|
|
55
55
|
"dependencies": {},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/jest": "^27.4.1",
|
|
58
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
59
|
-
"@typescript-eslint/parser": "^5.
|
|
58
|
+
"@typescript-eslint/eslint-plugin": "^5.14.0",
|
|
59
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
60
60
|
"eslint": "^8.10.0",
|
|
61
61
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
62
62
|
"eslint-plugin-import": "^2.25.4",
|
package/src/types/EColor.ts
CHANGED
|
@@ -309,15 +309,25 @@ export class EColor {
|
|
|
309
309
|
|
|
310
310
|
/**
|
|
311
311
|
* To RGB color string
|
|
312
|
-
* @param
|
|
312
|
+
* @param alpha Alpha value, false means ignore it
|
|
313
313
|
* @returns RGB color string
|
|
314
314
|
*/
|
|
315
|
-
toRGBColor(
|
|
316
|
-
//
|
|
317
|
-
includeAlpha
|
|
315
|
+
toRGBColor(alpha?: boolean | number) {
|
|
316
|
+
// Decide
|
|
317
|
+
let includeAlpha: boolean,
|
|
318
|
+
alphaValue: number | undefined = this.alpha;
|
|
319
|
+
|
|
320
|
+
if (typeof alpha === 'number') {
|
|
321
|
+
alphaValue = alpha;
|
|
322
|
+
includeAlpha = true;
|
|
323
|
+
} else if (alpha == null) {
|
|
324
|
+
includeAlpha = this.alpha != null;
|
|
325
|
+
} else {
|
|
326
|
+
includeAlpha = alpha;
|
|
327
|
+
}
|
|
318
328
|
|
|
319
329
|
if (includeAlpha)
|
|
320
|
-
return `RGBA(${this.r}, ${this.g}, ${this.b}, ${
|
|
330
|
+
return `RGBA(${this.r}, ${this.g}, ${this.b}, ${alphaValue ?? 1})`;
|
|
321
331
|
|
|
322
332
|
return `RGB(${this.r}, ${this.g}, ${this.b})`;
|
|
323
333
|
}
|