๐Ÿ‘๏ธ
5
fork

Configure Feed

Select the types of activity you want to include in your feed.

handle duplicate tags

+18 -13
+3 -2
src/lib/__tests__/deck-import.test.ts
··· 109 109 }); 110 110 }); 111 111 112 - it("handles multiple tags with spaces", () => { 112 + it("handles multiple tags with spaces (deduplicates)", () => { 113 113 const result = parseCardLine( 114 114 "1 Duskshell Crawler (J25) 653 #counter creatures #!counter creatures #!counter effects", 115 115 ); 116 + // Note: duplicate tags are deduplicated (first two are the same after stripping !) 116 117 expect(result).toEqual({ 117 118 quantity: 1, 118 119 name: "Duskshell Crawler", 119 120 setCode: "J25", 120 121 collectorNumber: "653", 121 - tags: ["counter creatures", "counter creatures", "counter effects"], 122 + tags: ["counter creatures", "counter effects"], 122 123 raw: "1 Duskshell Crawler (J25) 653 #counter creatures #!counter creatures #!counter effects", 123 124 }); 124 125 });
+2 -2
src/lib/deck-grouping.ts
··· 254 254 group.cards.push(card); 255 255 groups.set(type, group); 256 256 } else { 257 - // Has tags โ†’ add to each tag group 258 - for (const tag of card.tags) { 257 + // Has tags โ†’ add to each unique tag group (dedupe to handle malformed data) 258 + for (const tag of new Set(card.tags)) { 259 259 const group = groups.get(tag) ?? { cards: [], forTag: true }; 260 260 group.forTag = true; 261 261 group.cards.push(card);
+13 -9
src/lib/deck-import.ts
··· 59 59 const tagsPart = trimmed.slice(firstHashIndex); 60 60 remaining = trimmed.slice(0, firstHashIndex).trim(); 61 61 62 - // Split by # and process each tag 63 - tags = tagsPart 64 - .split("#") 65 - .map((t) => t.trim()) 66 - .filter((t) => t.length > 0) 67 - .map((t) => { 68 - // Remove optional ! prefix (Moxfield uses #! for "global" tags) 69 - return t.startsWith("!") ? t.slice(1).trim() : t; 70 - }); 62 + // Split by # and process each tag (dedupe to handle #foo #foo) 63 + tags = Array.from( 64 + new Set( 65 + tagsPart 66 + .split("#") 67 + .map((t) => t.trim()) 68 + .filter((t) => t.length > 0) 69 + .map((t) => { 70 + // Remove optional ! prefix (Moxfield uses #! for "global" tags) 71 + return t.startsWith("!") ? t.slice(1).trim() : t; 72 + }), 73 + ), 74 + ); 71 75 } 72 76 73 77 // Parse quantity (default to 1 if not present or invalid)