UNPKG

@bimdos/icon

Version:

跨框架图标库,支持 React、Vue、Angular、AngularJS、小程序等多种使用方式

67 lines (57 loc) 1.56 kB
/** * Bimdos Icon Library - 主入口文件 * 提供通用的图标数据和工具函数 */ // 加载图标数据 const icons = require('./icons.json'); /** * 获取图标数据 * @param {string} name - 图标名称 * @returns {object|null} 图标数据 */ function getIcon(name) { return icons.find(icon => icon.name === name) || null; } /** * 获取所有图标名称 * @returns {string[]} 图标名称数组 */ function getIconNames() { return icons.map(icon => icon.name); } /** * 检查图标是否存在 * @param {string} name - 图标名称 * @returns {boolean} 是否存在 */ function hasIcon(name) { return icons.some(icon => icon.name === name); } /** * 生成 SVG 字符串 * @param {string} name - 图标名称 * @param {object} options - 配置选项 * @returns {string} SVG 字符串 */ function generateSvg(name, options = {}) { const icon = getIcon(name); if (!icon) { console.warn(`Icon "${name}" not found`); return ''; } const { size = 16, color = 'currentColor', className = '' } = options; return `<svg class="bimdos-icon ${className}" width="${size}" height="${size}" viewBox="0 0 24 24" fill="${color}"> <path d="${icon.path}"></path> </svg>`; } module.exports = { icons, getIcon, getIconNames, hasIcon, generateSvg, };