2
0
mirror of https://github.com/iconify/iconify.git synced 2025-01-06 07:20:40 +00:00

Fix getIconData in Iconify Utils

This commit is contained in:
Vjacheslav Trushkin 2021-05-27 19:52:31 +03:00
parent 992e02d896
commit 4490d02be7
4 changed files with 69 additions and 5 deletions

View File

@ -1,12 +1,12 @@
{
"name": "@iconify/utils",
"version": "1.0.3",
"version": "1.0.4",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "@iconify/utils",
"version": "1.0.3",
"version": "1.0.4",
"license": "MIT",
"dependencies": {
"@iconify/types": "^1.0.6"

View File

@ -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.3",
"version": "1.0.4",
"license": "MIT",
"bugs": "https://github.com/iconify/iconify/issues",
"homepage": "https://iconify.design/",

View File

@ -1,5 +1,5 @@
import type { IconifyJSON } from '@iconify/types';
import { fullIcon, IconifyIcon, FullIconifyIcon } from '../icon';
import type { IconifyJSON, IconifyOptional } from '@iconify/types';
import { fullIcon, IconifyIcon, FullIconifyIcon, iconDefaults } from '../icon';
import { mergeIconData } from '../icon/merge';
/**
@ -50,5 +50,20 @@ export function getIconData(
}
const result = getIcon(name, 0);
// Add default properties
if (result) {
for (const key in iconDefaults) {
if (
result[key as keyof IconifyOptional] === void 0 &&
data[key as keyof IconifyOptional] !== void 0
) {
(result as unknown as Record<string, unknown>)[key] =
data[key as keyof IconifyOptional];
}
}
}
// Return icon
return result && full ? fullIcon(result) : result;
}

View File

@ -48,4 +48,53 @@ describe('Testing getting icon data', () => {
hFlip: false,
});
});
it('Minified icon set', () => {
// Short icon
const result1 = getIconData(
{
prefix: 'foo',
icons: {
bar: {
body: '<g />',
},
},
width: 24,
height: 24,
},
'bar',
false
);
expect(result1).to.be.eql({
body: '<g />',
width: 24,
height: 24,
});
// Full icon
const result2 = getIconData(
{
prefix: 'foo',
icons: {
bar: {
body: '<g />',
},
},
width: 24,
height: 24,
},
'bar',
true
);
expect(result2).to.be.eql({
body: '<g />',
left: 0,
top: 0,
width: 24,
height: 24,
rotate: 0,
vFlip: false,
hFlip: false,
});
});
});