• Stars
    star
    149
  • Rank 248,619 (Top 5 %)
  • Language
    CoffeeScript
  • License
    Do What The F*ck ...
  • Created over 12 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

JavaScript interface for the Gatherer card database

Tutor

Build Status

Gatherer is the canonical source for Magic: The Gathering card details. While useful, it lacks an interface for retrieving this data programmatically. The lack of an API makes creating Magic-related applications unnecessarily difficult.

Tutor is a simple JavaScript interface for Gatherer.

API

tutor.card

tutor.card(id, callback(err, card))
tutor.card(name, callback(err, card))
tutor.card(details, callback(err, card))

The first and second forms are shorthand for tutor.card({id: id}, ...) and tutor.card({name: name}, ...) respectively. The callback is passed an object representing the specified card. Version-specific metadata such as flavor text and rarity are included for cards specified by id. Attributes not applicable to the card type (e.g. lands have no mana cost) or not present (e.g. certain creatures have no rules text) are omitted.

tutor.card 'Demonic Tutor', (err, card) ->
  console.log card.name
  # => "Demonic Tutor"
  console.log card.mana_cost
  # => "{1}{B}"
  console.log card.text
  # => "Search your library for a card, put that card into your hand, then shuffle your library."

Split cards

Because the two sides of a split card share a Gatherer id, it's necessary to provide the name of the desired side:

tutor.card id: 27165, name: 'Fire', (err, card) ->
  console.log card.name
  # => "Fire"

tutor.card id: 27165, name: 'Ice', (err, card) ->
  console.log card.name
  # => "Ice"

Retrieving either side of a split card by name is straightforward:

tutor.card 'Fire', (err, card) ->
  console.log card.name
  # => "Fire"

tutor.card 'Ice', (err, card) ->
  console.log card.name
  # => "Ice"

Flip cards

Retrieving the top half of a flip card by id is straightforward:

tutor.card 247175, (err, card) ->
  console.log card.name
  # => "Nezumi Graverobber"

Either half of a flip card can be retrieved explicitly by setting which to "a" (for the upper half) or "b" (for the lower half):

tutor.card id: 247175, which: 'b', (err, card) ->
  console.log card.name
  # => "Nighteyes the Desecrator"

When retrieving a flip card by name rather than id, one may simply provide the name of the desired half:

tutor.card 'Nighteyes the Desecrator', (err, card) ->
  console.log card.name
  # => "Nighteyes the Desecrator"

Double-faced cards

Either face of a double-faced card can be retrieved by id:

tutor.card 262675, (err, card) ->
  console.log card.name
  # => "Afflicted Deserter"

tutor.card 262698, (err, card) ->
  console.log card.name
  # => "Werewolf Ransacker"

Or by name:

tutor.card 'Afflicted Deserter', (err, card) ->
  console.log card.name
  # => "Afflicted Deserter"

tutor.card 'Werewolf Ransacker', (err, card) ->
  console.log card.name
  # => "Werewolf Ransacker"

tutor.set

tutor.set(name, callback(err, set))

Scrape cards from the set specified by name. For example:

tutor.set 'Homelands', (err, cards) ->
  console.log cards.length
  # => 115
  console.log Object.keys(cards[0]).sort()
  # => [
  #   "converted_mana_cost",
  #   "expansion",
  #   "gatherer_url",
  #   "image_url",
  #   "mana_cost",
  #   "name",
  #   "power",
  #   "rarity",
  #   "subtypes",
  #   "supertypes",
  #   "text",
  #   "toughness",
  #   "types",
  #   "versions"
  # ]

tutor.formats

tutor.formats(callback(err, formatNames))

Provides the names of all the game's formats:

tutor.formats (err, formatNames) ->
  console.log formatNames
  # => [
  #   "Brawl",
  #   "Commander",
  #   "Legacy",
  #   "Modern",
  #   "Pauper",
  #   "Standard",
  #   "Vintage"
  # ]

tutor.sets

tutor.sets(callback(err, setNames))

Provides the names of all the game's sets:

tutor.sets (err, setNames) ->
  console.log setNames
  # => [
  #   "Aether Revolt"
  #   "Alara Reborn",
  #   ...
  #   "Zendikar",
  #   "Zendikar Expeditions"
  # ]

tutor.types

tutor.types(callback(err, types))

Provides the names of all the game's types:

tutor.types (err, types) ->
  console.log types
  # => [
  #   "Artifact",
  #   "Basic",
  #   ...
  #   "World",
  #   "You'll"
  # ]

CLI

npm install tutor --global will make the tutor command available globally.

$ tutor card 'Demonic Tutor'
Demonic Tutor {1}{B} Search your library for a card, put that card into your hand, then shuffle your library.

$ tutor card 'Demonic Tutor' --format json | jq '{name,mana_cost,types,text}'
{
  "name": "Demonic Tutor",
  "mana_cost": "{1}{B}",
  "types": [
    "Sorcery"
  ],
  "text": "Search your library for a card, put that card into your hand, then shuffle your library."
}

$ tutor card 666 --format json | jq '{name,mana_cost,types,text}'
{
  "name": "Lich",
  "mana_cost": "{B}{B}{B}{B}",
  "types": [
    "Enchantment"
  ],
  "text": "As Lich enters the battlefield, you lose life equal to your life total.\n\nYou don't lose the game for having 0 or less life.\n\nIf you would gain life, draw that many cards instead.\n\nWhenever you're dealt damage, sacrifice that many nontoken permanents. If you can't, you lose the game.\n\nWhen Lich is put into a graveyard from the battlefield, you lose the game."
}

$ tutor set Alliances | head -n 2
Aesthir Glider {3} 2/1 Flying Aesthir Glider can't block.
Agent of Stromgald {R} 1/1 {R}: Add {B}.

Example of using the CLI from other applications:

Link to Wiki

Running the tests

$ make --jobs="$(nproc)" fixtures
$ make test
$ make testcli

More Repositories

1

Base64.js

Polyfill for browsers that don't provide window.btoa and window.atob
JavaScript
489
star
2

string-format

JavaScript string formatting inspired by Python’s `str.format()`
JavaScript
332
star
3

doctest

Doctests for JavaScript (and CoffeeScript)
JavaScript
165
star
4

xyz

Publish npm packages with fewer screw-ups
Shell
101
star
5

transcribe

πŸ“ Generate Markdown documentation from code comments
JavaScript
79
star
6

an.hour.ago

A small utility which enables wonderfully expressive date and time manipulation in JavaScript
CoffeeScript
69
star
7

nucleotides

The building blocks of JavaScript programs
JavaScript
32
star
8

airwaves

Broadcast on a dedicated frequency
CoffeeScript
25
star
9

mathmethods

A tiny script which makes methods of the `Math` object available to numbers by adding properties to `Number.prototype`
CoffeeScript
17
star
10

orthogonal

DSL for describing simple vector graphics
CoffeeScript
14
star
11

CANON

Canonical object notation
JavaScript
12
star
12

jQuery.localize

⌚ jQuery plugin for localizing dates and times via the `datetime` attribute of the HTML5 `<time>` element
JavaScript
8
star
13

hex2xterm

🌈 Convert hexadecimal colour codes to xterm colour codes
JavaScript
3
star
14

fp-workshop

FP workshop presented at HolidayCheck in Munich on 2016-12-14
JavaScript
3
star
15

remember-bower

🐦 Never forget to update dependencies in bower.json again
JavaScript
2
star
16

cube

Magic: The Gathering Cube
HTML
2
star
17

deedpoll

πŸ“„ Flag incorrectly named identifiers in JavaScript programs
Shell
2
star
18

contenteditable

A jQuery utility which adds useful behaviour to `contenteditable` text
CoffeeScript
2
star
19

rich

JavaScript’s missing stdlib
1
star
20

davidchambersdesign.com

1
star
21

Homelands-Constructed

Lists from a terrific Homelands Constructed tournament held in Auckland on 27/12/2011
1
star
22

got-lambda

Repository used during Got.Ξ» presentation on 1 September 2016
JavaScript
1
star