|
| 1 | +import { Minimatch } from "minimatch"; |
| 2 | +import { manifest, type Manifest } from "./plenticons"; |
| 3 | + |
| 4 | +export type Synonyms = Record<string, string[]>; |
| 5 | + |
| 6 | +function makeSynonyms(manifest: Manifest, spec: [string | string[], string | string[]][]): Synonyms { |
| 7 | + const result: Synonyms = {} |
| 8 | + const iconNames = Object.entries(manifest.icons) |
| 9 | + .flatMap(([category, icons]) => icons.map(icon => `${category}/${icon}`)) |
| 10 | + |
| 11 | + for (const entry of spec) { |
| 12 | + const patterns = typeof entry[0] == "string" ? [entry[0]] : entry[0]; |
| 13 | + const synonyms = typeof entry[1] == "string" ? [entry[1]] : entry[1]; |
| 14 | + |
| 15 | + for (const pattern of patterns) { |
| 16 | + // Find matching icons |
| 17 | + const matcher = new Minimatch(pattern); |
| 18 | + const matches = iconNames.filter(it => matcher.match(it)) |
| 19 | + |
| 20 | + // Warn if pattern doesn't match - probably spec error |
| 21 | + if (matches.length == 0) |
| 22 | + console.warn(`Pattern "${pattern}" didn't match any icons!`) |
| 23 | + |
| 24 | + // Add synonyms to each icon |
| 25 | + for (const icon of matches) { |
| 26 | + result[icon] = [...(result[icon] ?? []), ...synonyms] |
| 27 | + } |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + return result |
| 32 | +} |
| 33 | + |
| 34 | +export const synonyms = makeSynonyms(manifest, [ |
| 35 | + // 2D |
| 36 | + ["2d/checkmark", [ "tick", "tickmark", "ok", "done", "yes" ]], |
| 37 | + ["2d/circle", [ "ok", "round" ]], |
| 38 | + ["2d/cross", [ "no", "deny", "ban", "cancel" ]], |
| 39 | + ["2d/square", [ "cube", "box" ]], |
| 40 | + |
| 41 | + ["2d/triangle*", ["cone"]], |
| 42 | + ["*/die*", [ "dice", "random", "chance", "throwing" ]], |
| 43 | + ["2d/*-chevron-*", [ "arrow", "direction" ]], |
| 44 | + |
| 45 | + ["2d/plus", [ "add" ]], |
| 46 | + ["2d/spark*", [ "star" ]], |
| 47 | + |
| 48 | + // 3D |
| 49 | + ["3d/cone", [ "triangle" ]], |
| 50 | + ["3d/cube", [ "square", "box" ]], |
| 51 | + ["3d/sphere", [ "circle", "round" ]], |
| 52 | + |
| 53 | + // Creatures |
| 54 | + ["creatures/bug", [ "insect", "roach", "tick" ]], |
| 55 | + ["creatures/demon", [ "monster", "enemy", "foe", "evil" ]], |
| 56 | + ["creatures/eye-closed", [ "invisible", "blind", "shut" ]], |
| 57 | + [["creatures/eye-hollow", "creatures/eye"], [ "see", "watch", "visible", "open" ]], |
| 58 | + |
| 59 | + ["creatures/heart*", [ "life", "lives", "health", "love" ]], |
| 60 | + |
| 61 | + ["creatures/person", [ "human", "man", "woman", "guy", "gal", "boy", "girl" ]], |
| 62 | + |
| 63 | + // Objects |
| 64 | + ["objects/ammo", [ "shells" ]], |
| 65 | + ["objects/axe", [ "hatchet", "timber", "lumber", "wood" ]], |
| 66 | + ["objects/bell", [ "notification", "alert" ]], |
| 67 | + [["objects/bill", "objects/coins"], [ "money", "currency", "dollars", "euros" ]], |
| 68 | + ["objects/cd", [ "dvd" ]], |
| 69 | + ["objects/chain", [ "link", "anchor", "reference" ]], |
| 70 | + ["objects/chest", [ "box", "treasure", "booty" ]], |
| 71 | + ["objects/clock", [ "watch", "time" ]], |
| 72 | + ["objects/floppy", [ "save" ]], |
| 73 | + ["objects/globe", [ "planet", "earth", "global", "internet", "web", "www" ]], |
| 74 | + ["objects/gun", [ "weapon", "arm" ]], |
| 75 | + ["objects/hammer", [ "build" ]], |
| 76 | + ["objects/hourglass", [ "time" ]], |
| 77 | + ["objects/key", [ "password", "open", "access" ]], |
| 78 | + ["objects/lightbulb", [ "idea", "new", "create" ]], |
| 79 | + ["objects/lightning", [ "fast", "speed", "measure", "benchmark" ]], |
| 80 | + ["objects/magnifying-glass", [ "search", "find" ]], |
| 81 | + ["objects/pickaxe", [ "mine", "mining" ]], |
| 82 | + ["objects/shield", [ "protect", "armor", "safe", "security" ]], |
| 83 | + ["objects/stopwatch", [ "time", "measure", "benchmark", "speed", "fast" ]], |
| 84 | + ["objects/sword*", [ "fight", "army", "war", "battle", "force" ]], |
| 85 | + ["objects/trashcan", [ "delete", "clear", "remove", "erase", "recycle", "bin" ]], |
| 86 | + |
| 87 | + [["objects/vial", "objects/*-flask"], ["vial", "flask", "bottle"]], |
| 88 | + ["objects/conical-flask", ["experiment", "chemistry", "chemical"]], |
| 89 | + |
| 90 | + // Symbols |
| 91 | + ["symbols/crosshair", [ "aim" ]], |
| 92 | + ["symbols/jump-to", [ "go to", "goto" ]], |
| 93 | + ["symbols/refresh", [ "reload" ]], |
| 94 | + ["symbols/todo", [ "list" ]] |
| 95 | +]) |
0 commit comments