mirror of
https://github.com/iconify/iconify.git
synced 2024-11-09 23:00:56 +00:00
Utils update: convert samplesHeight from legacy info format
This commit is contained in:
parent
f8d9f4bc00
commit
501594764e
@ -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') {
|
||||
|
@ -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',
|
||||
|
Loading…
Reference in New Issue
Block a user