From 4490d02be7a6d060a779459f771a3ff0649e299d Mon Sep 17 00:00:00 2001 From: Vjacheslav Trushkin Date: Thu, 27 May 2021 19:52:31 +0300 Subject: [PATCH] Fix getIconData in Iconify Utils --- packages/utils/package-lock.json | 4 +- packages/utils/package.json | 2 +- packages/utils/src/icon-set/get-icon.ts | 19 +++++++++- packages/utils/tests/get-icon-test.ts | 49 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 5 deletions(-) diff --git a/packages/utils/package-lock.json b/packages/utils/package-lock.json index 9925156..c95d796 100644 --- a/packages/utils/package-lock.json +++ b/packages/utils/package-lock.json @@ -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" diff --git a/packages/utils/package.json b/packages/utils/package.json index 673e2ac..cd20291 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -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/", diff --git a/packages/utils/src/icon-set/get-icon.ts b/packages/utils/src/icon-set/get-icon.ts index 34575ee..bd73e77 100644 --- a/packages/utils/src/icon-set/get-icon.ts +++ b/packages/utils/src/icon-set/get-icon.ts @@ -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)[key] = + data[key as keyof IconifyOptional]; + } + } + } + + // Return icon return result && full ? fullIcon(result) : result; } diff --git a/packages/utils/tests/get-icon-test.ts b/packages/utils/tests/get-icon-test.ts index c07bc3c..2d2397d 100644 --- a/packages/utils/tests/get-icon-test.ts +++ b/packages/utils/tests/get-icon-test.ts @@ -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: '', + }, + }, + width: 24, + height: 24, + }, + 'bar', + false + ); + expect(result1).to.be.eql({ + body: '', + width: 24, + height: 24, + }); + + // Full icon + const result2 = getIconData( + { + prefix: 'foo', + icons: { + bar: { + body: '', + }, + }, + width: 24, + height: 24, + }, + 'bar', + true + ); + expect(result2).to.be.eql({ + body: '', + left: 0, + top: 0, + width: 24, + height: 24, + rotate: 0, + vFlip: false, + hFlip: false, + }); + }); });