2
0
mirror of https://github.com/iconify/iconify.git synced 2024-09-19 16:59:02 +00:00

Utils update: convert samplesHeight from legacy info format

This commit is contained in:
Vjacheslav Trushkin 2021-10-05 16:19:18 +03:00
parent f8d9f4bc00
commit 501594764e
2 changed files with 58 additions and 13 deletions

View File

@ -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') {

View File

@ -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',