Skip to content

Commit 56a80c4

Browse files
committed
expanded card and layout documentation
1 parent 626138d commit 56a80c4

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/objects/Card/Card.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,35 @@ type Layout<T extends ScryfallLayout> = Pick<ScryfallCardFields.Core.All, "layou
1010
/**
1111
* A collection of types representing Scryfall cards of each possible layout.
1212
*
13+
*
14+
* An individual type exists for each possible layout: {@link ScryfallCard.Normal}, {@link ScryfallCard.Transform}, etc.
15+
*
16+
* Then various groups exist to help describe cards of indeterminate layout:
17+
* - {@link ScryfallCard.Any} describes any card at all. Think of it as like `any` but for cards.
18+
* - {@link ScryfallCard.AnySingleFaced} describes any card with one face and no `card_faces` property, e.g. {@link ScryfallCard.Normal Normal} or {@link ScryfallCard.Saga Saga}.
19+
* - {@link ScryfallCard.AnyMultiFaced} describes any card with multiple faces. It may be a split card with both "faces" on the front, or a double-sided card with faces on the front and back of the card. It also collects the next two groups on this list.
20+
* - {@link ScryfallCard.AnySingleSidedSplit} describes any card with multiple faces where both faces are on the front, e.g. {@link ScryfallCard.Adventure Adventure}, {@link ScryfallCard.Flip Flip}, or {@link ScryfallCard.Split Split}.
21+
* - {@link ScryfallCard.AnyDoubleSidedSplit} describes any card with multiple faces where the faces are on the front and back of the card, e.g. {@link ScryfallCard.Transform Transform}, {@link ScryfallCard.ModalDfc ModalDfc}, or {@link ScryfallCard.ReversibleCard ReversibleCard}.
22+
*
23+
* We recommend starting from `ScryfallCard.Any` to describe generic API responses, and you will need to do type narrowing to access more specific fields.
24+
*
25+
* @example // Type narrowing by layout
26+
* const mysteryCard: ScryfallCard.Any = getCard();
27+
*
28+
* if (mysteryCard.layout === ScryfallLayout.Transform) {
29+
* const transform: ScryfallCard.Transform = mysteryCard;
30+
* }
31+
*
32+
* @example // Type narrowing by property
33+
* const mysteryCard: ScryfallCard.Any = getCard();
34+
*
35+
* if ("card_faces" in mysteryCard) {
36+
* const mfc: ScryfallCard.AnyMultiFaced = mysteryCard;
37+
* } else {
38+
* const sfc: ScryfallCard.AnySingleFaced = mysteryCard;
39+
* }
40+
*
41+
*
1342
* @see {@link https://scryfall.com/docs/api/cards}
1443
* @see {@link https://scryfall.com/docs/api/layouts}
1544
*/

src/objects/Card/values/Layout.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/**
2+
* The set of card layouts.
3+
*/
14
export enum ScryfallLayout {
25
/** A standard Magic card with one face */
36
Normal = "normal",
@@ -49,7 +52,13 @@ export enum ScryfallLayout {
4952

5053
export type ScryfallLayoutLike = ScryfallLayout | `${ScryfallLayout}`;
5154

55+
/**
56+
* Groupings of layouts.
57+
*/
5258
export namespace ScryfallLayoutGroup {
59+
/**
60+
* A type describing all layouts that represent a single-faced card, i.e. one with no card_faces property.
61+
*/
5362
export type SingleFaceType =
5463
| ScryfallLayout.Normal
5564
| ScryfallLayout.Meld
@@ -67,6 +76,9 @@ export namespace ScryfallLayoutGroup {
6776
| ScryfallLayout.Augment
6877
| ScryfallLayout.Host;
6978

79+
/**
80+
* A type describing all layouts that represent a multi-faced card, i.e. one with a card_faces property.
81+
*/
7082
export type MultiFaceType =
7183
| ScryfallLayout.Split
7284
| ScryfallLayout.Flip
@@ -77,8 +89,14 @@ export namespace ScryfallLayoutGroup {
7789
| ScryfallLayout.ArtSeries
7890
| ScryfallLayout.ReversibleCard;
7991

92+
/**
93+
* A card describing all layouts that represent a multi-faced card where both faces are on the front.
94+
*/
8095
export type SingleSidedSplitType = ScryfallLayout.Split | ScryfallLayout.Flip | ScryfallLayout.Adventure;
8196

97+
/**
98+
* A card describing all layouts that represent a multi-faced card where the faces are on the front and back of the card.
99+
*/
82100
export type DoubleSidedSplitType =
83101
| ScryfallLayout.Transform
84102
| ScryfallLayout.ModalDfc

0 commit comments

Comments
 (0)