npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@scryfall/api-types

v1.0.0-alpha.4

Published

Type definitions for the Scryfall API

Downloads

390

Readme

Scryfall API types

This library documents the definitive comprehensive typings of the Scryfall API for use in Typescript & Javascript projects.

This library uses semver for versioning. These versions only describe this library, not the Scryfall API as a whole.

Installation

npm install @scryfall/api-types

Examples

Fetching a card

// CommonJS module syntax
const { ScryfallCard } = require("@scryfall/api-types");

// ES module syntax
import { ScryfallCard } from "@scryfall/api-types";

// Fetch a card
const response = await fetch("https://api.scryfall.com/cards/iko/275");
const godzilla: ScryfallCard.Any = await response.json();

Fetching the list of sets

// CommonJS module syntax
const { ScryfallList } = require("@scryfall/api-types");

// ES module syntax
import { ScryfallList } from "@scryfall/api-types";

// Fetch the list of all setss
const response = await fetch("https://api.scryfall.com/sets");
const sets: ScryfallList.Sets = await response.json();

Type narrowing on a card

import { ScryfallCard, ScryfallLayout } from "@scryfall/api-types";

// This card might be of any type.
// You cannot access `mysteryCard.card_faces`, because it might not have that property.
const mysteryCard: ScryfallCard.Any = getCard();

// You can narrow by layout:
if (mysteryCard.layout === ScryfallLayout.Transform) {
  // It's a transforming DFC!
  // You can access transform-specific fields in this scope, or assign it to a variable.
  const faces = anyCard.card_faces;
  const transform: ScryfallCard.Transform = mysteryCard;
}

// You can also narrow by property:
if ("card_faces" in anyCard) {
  // It's *some* kind of multi-faced card.
  // You can now access the card_faces property.
  // You'll need to do some further type narrowing to know more about what's in the card.
  const faces = anyCard.card_faces;
  const multifaced: ScryfallCard.AnyMultiFaced = anyCard;
} else {
  const sfc: ScryfallCard.AnySingleFaced = anyCard;
}

Usage

Each type and enum exported by this library corresponds to a Scryfall API object and its values.

Points of interest:

If the API provides an object, this library provides it as well. (If it doesn't, please tell us!)

All primary types and values are prefixed with Scryfall to avoid conflict with the standard library (e.g. Object, Error, Set) and to minimise conflict with your other libraries and dependencies (e.g. Color, LanguageCode). If we didn't have the prefix you'd be forced to append one yourself one on import, so we've defaulted to including it.

Enum fields are described both in terms of an enum and a set of strings in order to give you the option of interacting with that field with either one.