Reference · Collections and piles: pure helpers
parseCollectionfunction
Check a collection and make it the shape the element draws: an array of cards, or an object with a cards array. A card without an id is numbered by its place.
Import it
import { parseCollection } from "@johnmorrisdotca/fuda-cards/collection";
Definition
function parseCollection(input: unknown): CollectionCard[]
Parameters
| Name | Type | Description |
|---|---|---|
input | unknown | An array of items, or |
Returns
CollectionCard[]
A new array of cards; the input is not changed.
Examples
import { parseCollection } from "@johnmorrisdotca/fuda-cards/collection";
console.log(parseCollection([{ name: "Card", image: "front.jpg" }])); // [ { id: '0', name: 'Card', image: 'front.jpg' } ]
try {
parseCollection([{ name: "Card" }]);
} catch (error) {
console.log((error as Error).message); // Card 1 needs a name and image URL.
}[ { id: '0', name: 'Card', image: 'front.jpg' } ]
Card 1 needs a name and image URL.What it prints (run when this page was built)