commander-spellbook
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -0,1 +1,9 @@ | ||
# 0.3.0 | ||
- Add `random` method | ||
- Add `findById` method | ||
- Support colloquial color names for color identity param | ||
- `search` | ||
- Support `=`, `>`, `<`, `>=`, `<=` operators for `coloridentity` | ||
# 0.2.0 | ||
@@ -2,0 +10,0 @@ |
import search from "./search"; | ||
import random from "./random"; | ||
import findById from "./find-by-id"; | ||
import { resetCache } from "./spellbook-api"; | ||
declare const _default: { | ||
search: typeof search; | ||
random: typeof random; | ||
findById: typeof findById; | ||
resetCache: typeof resetCache; | ||
}; | ||
export = _default; |
@@ -6,6 +6,10 @@ "use strict"; | ||
var search_1 = __importDefault(require("./search")); | ||
var random_1 = __importDefault(require("./random")); | ||
var find_by_id_1 = __importDefault(require("./find-by-id")); | ||
var spellbook_api_1 = require("./spellbook-api"); | ||
module.exports = { | ||
search: search_1.default, | ||
random: random_1.default, | ||
findById: find_by_id_1.default, | ||
resetCache: spellbook_api_1.resetCache, | ||
}; |
@@ -7,3 +7,5 @@ import type { ColorIdentityColors } from "../types"; | ||
private isColorless; | ||
hasColors(colors: ColorIdentityColors[]): boolean; | ||
isWithin(colors: ColorIdentityColors[]): boolean; | ||
is(colors: ColorIdentityColors[]): boolean; | ||
includes(colors: ColorIdentityColors[]): boolean; | ||
toString(): string; | ||
@@ -10,0 +12,0 @@ toMarkdown(): string; |
@@ -7,3 +7,3 @@ "use strict"; | ||
var scryfall_client_1 = __importDefault(require("scryfall-client")); | ||
var WUBRG_ORDER = ["c", "w", "u", "b", "r", "g"]; | ||
var WUBRG_ORDER = ["w", "u", "b", "r", "g"]; | ||
var ColorIdentity = /** @class */ (function () { | ||
@@ -15,2 +15,5 @@ function ColorIdentity(colors) { | ||
}); | ||
if (this.colors.length === 0) { | ||
this.colors.push("c"); | ||
} | ||
} | ||
@@ -20,10 +23,18 @@ ColorIdentity.prototype.isColorless = function () { | ||
}; | ||
ColorIdentity.prototype.hasColors = function (colors) { | ||
ColorIdentity.prototype.isWithin = function (colors) { | ||
if (this.isColorless()) { | ||
return true; | ||
} | ||
var allColors = this.colors.concat(colors); | ||
var colorSet = new Set(allColors); | ||
return colorSet.size === colors.length; | ||
return !this.colors.find(function (color) { return colors.indexOf(color) === -1; }); | ||
}; | ||
ColorIdentity.prototype.is = function (colors) { | ||
if (this.colors.length !== new Set(colors).size) { | ||
return false; | ||
} | ||
return this.isWithin(colors); | ||
}; | ||
ColorIdentity.prototype.includes = function (colors) { | ||
var _this = this; | ||
return !colors.find(function (color) { return _this.colors.indexOf(color) === -1; }); | ||
}; | ||
ColorIdentity.prototype.toString = function () { | ||
@@ -30,0 +41,0 @@ return this.rawString; |
@@ -54,3 +54,3 @@ "use strict"; | ||
cards = searchParams.cards; | ||
colorIdentity = searchParams.colorIdentity || []; | ||
colorIdentity = searchParams.colorIdentity.colors; | ||
if (colorIdentity) { | ||
@@ -79,3 +79,19 @@ colorIdentity = colorIdentity.map(function (color) { | ||
combos = combos.filter(function (combo) { | ||
return combo.colorIdentity.hasColors(colorIdentity); | ||
switch (searchParams.colorIdentity.method) { | ||
case "=": | ||
return combo.colorIdentity.is(colorIdentity); | ||
case ">": | ||
return (combo.colorIdentity.includes(colorIdentity) && | ||
!combo.colorIdentity.is(colorIdentity)); | ||
case ">=": | ||
return combo.colorIdentity.includes(colorIdentity); | ||
case "<": | ||
return (combo.colorIdentity.isWithin(colorIdentity) && | ||
!combo.colorIdentity.is(colorIdentity)); | ||
case "<=": | ||
case ":": | ||
return combo.colorIdentity.isWithin(colorIdentity); | ||
default: | ||
return true; | ||
} | ||
}); | ||
@@ -82,0 +98,0 @@ } |
@@ -40,4 +40,7 @@ import type CardGrouping from "./models/card-grouping"; | ||
id?: string; | ||
colorIdentity?: ColorIdentityColors[]; | ||
colorIdentity: { | ||
method: string; | ||
colors: ColorIdentityColors[]; | ||
}; | ||
errors: SearchError[]; | ||
}; |
{ | ||
"name": "commander-spellbook", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "A wrapper for parsing the commander spellbook api.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
165
README.md
@@ -23,51 +23,7 @@ ## Commander Spellbook | ||
Look up all the combos with the `search` method: | ||
## Overview | ||
```js | ||
spellbook.seach().then((combos) => { | ||
// loop over the array of combos | ||
}); | ||
``` | ||
The methods in this module typically resolve with an object or an array of objects representing the data of the combo(s). The object(s) typically have this shape: | ||
In addition, `search` takes an optional query string to filter the results. | ||
```js | ||
spellbook.seach("sydri scepter").then((combos) => { | ||
// all combos that include cards with the name sydri and scepter in them | ||
}); | ||
``` | ||
Full or partial card names can also be used. | ||
```js | ||
spellbook | ||
.seach("card:'Arjun, the Shifting Flame' card:\"Thought Reflection\"") | ||
.then((combos) => { | ||
// all combos that include cards with the name Arjun, the Shifting Flrame and Thought Reflection | ||
}); | ||
``` | ||
You can also query by color identity using `ci` or `coloridentity`. | ||
```js | ||
spellbook.seach("Kiki ci:wbr").then((combos) => { | ||
// all combos that include cards with the name Kiki and have a white/black/red color identity | ||
}); | ||
``` | ||
You can also query by the prequisites, steps and results in the combo. | ||
```js | ||
spellbook | ||
.seach( | ||
"prequisites:'all permanents' steps:'Untap all' results:'infinite' results:'mana'" | ||
) | ||
.then((combos) => { | ||
// all combos that include the prerequisites, steps and results | ||
}); | ||
``` | ||
The resulting object will be an array of combos that have this shape: | ||
```js | ||
{ | ||
@@ -94,95 +50,90 @@ commanderSpellbookId: number; | ||
## Search Options | ||
## findById | ||
### cards | ||
Look up a specific combo by the combos id | ||
Pass an array of card names (up to 10) to look for combos for those cards. | ||
```js | ||
spellbook.findById('123').then((combo) => { | ||
combo; // combo with commanderSpellbookId '123' | ||
}); | ||
``` | ||
When passing a `cards` array, at least one value must be passed. | ||
If a number is passed as the id, it will automatically be converted to a string: | ||
```js | ||
// find combos that include one card | ||
spellbook | ||
.search({ | ||
cards: ["Sydri, Galvanic Genius"], | ||
}) | ||
.then(function (combos) { | ||
// loop through combos | ||
}); | ||
spellbook.findById(123).then((combo) => { | ||
combo; // combo with commanderSpellbookId '123' | ||
}); | ||
``` | ||
// find combos that include more than 1 card | ||
spellbook | ||
.search({ | ||
cards: ["Thornbite Staff", "Basilisk Collar"], | ||
}) | ||
.then(function (combos) { | ||
// loop through combos | ||
}); | ||
If a combo with the specified id does not exist, the promise will reject. | ||
```js | ||
spellbook.findById('not-an-id').catch((err) => { | ||
err.message; // 'Combo with id "not-an-id" could not be found.' | ||
}); | ||
``` | ||
Partial matches also work: | ||
## Search | ||
Look up all the combos with the `search` method: | ||
```js | ||
// find combos that include Sydri using a short name | ||
spellbook | ||
.search({ | ||
cards: ["Sydri"], | ||
}) | ||
.then(function (combos) { | ||
// loop through combos | ||
}); | ||
spellbook.seach().then((combos) => { | ||
// loop over the array of combos | ||
}); | ||
``` | ||
// find combos that include Thornbite Staff and Basilisk Collar using a short name | ||
spellbook | ||
.search({ | ||
cards: ["Thorn Staff", "Bas Colla"], | ||
}) | ||
.then(function (combos) { | ||
// loop through combos | ||
}); | ||
In addition, `search` takes an optional query string to filter the results. | ||
```js | ||
spellbook.seach("sydri scepter").then((combos) => { | ||
// all combos that include cards with the name sydri and scepter in them | ||
}); | ||
``` | ||
Punctuation, capitalization and spaces are ignored: | ||
Full or partial card names can also be used. | ||
```js | ||
// find combos that include Alhammarret's Archive | ||
spellbook | ||
.search({ | ||
cards: ["mMaRrEts aR"], | ||
}) | ||
.then(function (combos) { | ||
// loop through combos | ||
.seach("card:'Arjun, the Shifting Flame' card:\"Thought Reflection\"") | ||
.then((combos) => { | ||
// all combos that include cards with the name Arjun, the Shifting Flrame and Thought Reflection | ||
}); | ||
``` | ||
### colorIdentity | ||
You can also query by color identity using `ci` or `coloridentity`. | ||
Pass either a string representing the color combination you're looking for: | ||
```js | ||
spellbook.seach("Kiki ci:wbr").then((combos) => { | ||
// all combos that include cards with the name Kiki and have a white/black/red color identity | ||
}); | ||
``` | ||
You can also query by the prequisites, steps and results in the combo. | ||
```js | ||
spellbook | ||
.search({ | ||
colorIdentity: "bug", | ||
}) | ||
.then(function (combos) { | ||
// loop through all combos in the sultai colors | ||
.seach( | ||
"prequisites:'all permanents' steps:'Untap all' results:'infinite' results:'mana'" | ||
) | ||
.then((combos) => { | ||
// all combos that include the prerequisites, steps and results | ||
}); | ||
``` | ||
Or an array of single digit strings representing the color combination: | ||
## Random | ||
Look up a random combo using the `random` method: | ||
```js | ||
spellbook | ||
.search({ | ||
colorIdentity: ["b", "u", "g"], | ||
}) | ||
.then(function (combos) { | ||
// loop through all combos in the sultai colors | ||
}); | ||
spellbook.seach().then((combo) => { | ||
combo; // a randomly chosen combo | ||
}); | ||
``` | ||
This is of course best used in conjunction with the `cards` option. | ||
## Models | ||
The methods provided in the module typically return a combo object with with some special classes. The special classes are documented here: | ||
### Card | ||
@@ -189,0 +140,0 @@ |
59467
31
1118
446