All files / src/utils lucideIcons.js

7.69% Statements 1/13
0% Branches 0/16
0% Functions 0/2
10% Lines 1/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30    1x                                                      
import * as LucideIcons from '@lucide/vue'
 
let iconMap = null
 
function loadIcons() {
  if (iconMap) return
  const map = {}
  for (const [key, component] of Object.entries(LucideIcons)) {
    if (
      key !== 'default' &&
      key !== 'createLucideIcon' &&
      typeof key === 'string' &&
      key.charAt(0) === key.charAt(0).toUpperCase()
    ) {
      map[key] = component
    }
  }
  iconMap = map
}
 
/**
 * 同步获取图标组件,传入 null/空字符串时返回 null。
 * @param {string | null | undefined} name lucide 图标名(首字母大写),如 "LayoutGrid"
 */
export function getIcon(name) {
  if (!iconMap) loadIcons()
  if (!name || !iconMap) return null
  return iconMap[name] || null
}