diff --git a/packages/utils/src/icon-set/convert-info.ts b/packages/utils/src/icon-set/convert-info.ts index 17ddb5c..69478da 100644 --- a/packages/utils/src/icon-set/convert-info.ts +++ b/packages/utils/src/icon-set/convert-info.ts @@ -31,6 +31,7 @@ export interface LegacyIconifyInfo { // Icon grid height?: number | number[]; displayHeight?: number; + samplesHeight?: number; // Category category?: string; @@ -178,20 +179,20 @@ export function convertIconSetInfo( } } - if ( - typeof source.displayHeight === 'number' || - typeof source.displayHeight === 'string' - ) { - // Convert from source.displayHeight - const num = parseInt(source.displayHeight as string); - if ( - num >= minDisplayHeight && - num <= maxDisplayHeight && - Math.round(num) === num - ) { - result.displayHeight = num; + ['samplesHeight', 'displayHeight'].forEach((prop) => { + const value = source[prop]; + if (typeof value === 'number' || typeof value === 'string') { + // Convert from source.displayHeight or source.samplesHeight + const num = parseInt(value as string); + if ( + num >= minDisplayHeight && + num <= maxDisplayHeight && + Math.round(num) === num + ) { + result.displayHeight = num; + } } - } + }); // Convert palette from string value if (typeof source.palette === 'string') { diff --git a/packages/utils/tests/convert-info-test.ts b/packages/utils/tests/convert-info-test.ts index 727ab7c..428bda1 100644 --- a/packages/utils/tests/convert-info-test.ts +++ b/packages/utils/tests/convert-info-test.ts @@ -239,6 +239,50 @@ describe('Testing convertIconSetInfo', () => { expect(result).toEqual(expected); }); + test('Testing CodIcon', () => { + // Test "info" field from mixed codicon.json + const raw = { + name: 'Codicons', + total: 383, + author: { + name: 'Microsoft Corporation', + url: 'https://github.com/microsoft/vscode-codicons', + }, + license: { + title: 'CC BY 4.0', + spdx: 'CC-BY-4.0', + url: 'https://raw.githubusercontent.com/microsoft/vscode-codicons/master/LICENSE', + }, + version: '0.0.23', + samples: ['account', 'bell-dot', 'new-file'], + samplesHeight: 16, + height: [16, 24], + category: 'General', + palette: false, + }; + const result = convertIconSetInfo(raw); + const expected: IconifyInfo = { + name: 'Codicons', + total: 383, + author: { + name: 'Microsoft Corporation', + url: 'https://github.com/microsoft/vscode-codicons', + }, + license: { + title: 'CC BY 4.0', + spdx: 'CC-BY-4.0', + url: 'https://raw.githubusercontent.com/microsoft/vscode-codicons/master/LICENSE', + }, + version: '0.0.23', + samples: ['account', 'bell-dot', 'new-file'], + displayHeight: 16, + height: [16, 24], + category: 'General', + palette: false, + }; + expect(result).toEqual(expected); + }); + test('Already converted item', () => { const item: IconifyInfo = { name: 'Font Awesome 4',