convertIconSetInfo()
此函数属于 Iconify Utils 包。
函数 convertIconSetInfo() 用于转换并验证图标集信息。
一些旧的图标集可能采用旧版格式的信息,这些格式是在 Iconify 项目迁移到 TypeScript 之前创建的。此函数将同时接受旧版和新版格式,对其进行转换和验证,并返回正确的 IconifyInfo 数据。
用法
该函数包含以下参数:
- data,unknown。图标集信息,可以是旧版对象或 IconifyInfo。
- expectedPrefix,string。可选。如果设置了该参数,且源对象的 prefix 属性值与之不同,函数将抛出错误。当旧版信息可能不正确时,可使用此参数。
函数返回值:
- 成功时返回 IconifyInfo 对象。
- 出错时返回 null。
示例
usage.ts
ts
import { convertIconSetInfo } from '@iconify/utils';
// Original data
const data = {
name: 'Remix Icon',
total: 2271,
author: 'Remix Design',
url: 'https://github.com/Remix-Design/RemixIcon',
license: 'Apache 2.0',
licenseURL: 'https://github.com/Remix-Design/RemixIcon/blob/master/License',
height: 24,
samples: ['lock-2-line', 'mark-pen-fill', 'moon-line'],
palette: 'Colorless',
category: 'General',
};
// Convert it
const converted = convertIconSetInfo(data);
// Log result
console.log(converted);Result:
json
{
"name": "Remix Icon",
"total": 2271,
"author": {
"name": "Remix Design",
"url": "https://github.com/Remix-Design/RemixIcon"
},
"license": {
"title": "Apache 2.0",
"url": "https://github.com/Remix-Design/RemixIcon/blob/master/License"
},
"samples": ["lock-2-line", "mark-pen-fill", "moon-line"],
"height": 24,
"displayHeight": 24,
"category": "General",
"palette": false
}