mirror of
https://github.com/iconify/iconify.git
synced 2025-01-12 09:51:25 +00:00
Update Utils: fix few bugs, add default option to rotateFromString
This commit is contained in:
parent
7ba8c01e66
commit
2160e2a2f5
@ -2,7 +2,7 @@
|
||||
"name": "@iconify/utils",
|
||||
"description": "Common functions for working with Iconify icon sets used by various packages.",
|
||||
"author": "Vjacheslav Trushkin",
|
||||
"version": "1.0.16",
|
||||
"version": "1.0.17",
|
||||
"license": "MIT",
|
||||
"bugs": "https://github.com/iconify/iconify/issues",
|
||||
"homepage": "https://iconify.design/",
|
||||
|
@ -152,9 +152,11 @@ function fromFunction(value: string): Color | null {
|
||||
let g = numbers[1];
|
||||
let b = numbers[2];
|
||||
if (hasPercengage) {
|
||||
r = r / 2.55;
|
||||
g = g / 2.55;
|
||||
b = b / 2.55;
|
||||
// Not the same as `r *= 2.55;` because of how floating math works in js, so do not change this!
|
||||
// With this code, 50% results in 127.5, with *=2.55 result is 127.49999999...
|
||||
r = (r * 255) / 100;
|
||||
g = (g * 255) / 100;
|
||||
b = (b * 255) / 100;
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Get rotation value
|
||||
*/
|
||||
export function rotateFromString(value: string): number {
|
||||
export function rotateFromString(value: string, defaultValue = 0): number {
|
||||
const units = value.replace(/^-?[0-9.]*/, '');
|
||||
|
||||
function cleanup(value: number): number {
|
||||
@ -36,5 +36,5 @@ export function rotateFromString(value: string): number {
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
return defaultValue;
|
||||
}
|
||||
|
@ -285,6 +285,15 @@ describe('Colors', () => {
|
||||
})
|
||||
).toBe('rgba(10, 25, 30, 0.5)');
|
||||
|
||||
// Percentage in color
|
||||
expect(stringToColor('rgba(100%, 50%, 20%)')).toEqual({
|
||||
type: 'rgb',
|
||||
r: 255,
|
||||
g: 127.5,
|
||||
b: 51,
|
||||
alpha: 1,
|
||||
});
|
||||
|
||||
// Percentage in alpha
|
||||
expect(stringToColor('rgba(10, 20, 31, 50%)')).toEqual({
|
||||
type: 'rgb',
|
||||
|
Loading…
Reference in New Issue
Block a user