1
0
Fork 0
simpleicons/index.ts

44 lines
931 B
TypeScript

import * as icons from 'simple-icons';
let structs = "";
let map = "";
for (const [name, icon] of Object.entries(icons)) {
const varName = "SI" + icon.slug.charAt(0).toUpperCase() + icon.slug.slice(1);
structs += varName + ` = Icon{
Title: "${icon.title}",
Slug: "${icon.slug}",
Hex: "${icon.hex}",
Path: "${icon.path}",
}
`
map += `"${icon.slug}": ${varName},
`
}
let tmpl = `package simpleicons
import "fmt"
// Icon is a SimpleIcon
type Icon struct {
Title string
Slug string
Hex string
Path string
}
// SVG returns a complete SVG for the Icon
func (i Icon) SVG() string {
return fmt.Sprintf(` + "`" + `<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>%s</title><path d="%s"/></svg>` + "`" + `, i.Title, i.Path)
}
var (
${structs}
Icons = map[string]Icon{
${map}
}
)
`
const path = "./simpleicons.go";
await Bun.write(path, tmpl);