commander-spellbook
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -0,1 +1,6 @@ | ||
# 0.4.0 | ||
- Fix issue where `parseQuery` was using an old module, causing all searches to fail | ||
- `search` | ||
- Support numeric values for `coloridentity` | ||
# 0.3.0 | ||
@@ -2,0 +7,0 @@ |
@@ -7,2 +7,3 @@ import type { ColorIdentityColors } from "../types"; | ||
private isColorless; | ||
numberOfColors(): number; | ||
isWithin(colors: ColorIdentityColors[]): boolean; | ||
@@ -9,0 +10,0 @@ is(colors: ColorIdentityColors[]): boolean; |
@@ -21,2 +21,8 @@ "use strict"; | ||
}; | ||
ColorIdentity.prototype.numberOfColors = function () { | ||
if (this.isColorless()) { | ||
return 0; | ||
} | ||
return this.colors.length; | ||
}; | ||
ColorIdentity.prototype.isWithin = function (colors) { | ||
@@ -23,0 +29,0 @@ if (this.isColorless()) { |
@@ -10,11 +10,14 @@ "use strict"; | ||
function collectKeywordedQueries(params, query) { | ||
// captures keywords in the form key:value | ||
var simpleQueryGroups = query.match(/(-)?\b[\w_]+(:|=|>=|<=|<|>)[^'"\s]+\b/gi) || []; | ||
// captures keywords in the form key:"value inside double quotes' | ||
var queryGroupsWithDoubleQuotes = query.match(/(-)?\b[\w_]+(:|=|>=|<=|<|>)"[^"]+"/gi) || []; | ||
// captures keywords in the form key:'value inside single quotes' | ||
var queryGroupsWithSingleQuotes = query.match(/(-)?\b[\w_]+(:|=|>=|<=|<|>)'[^']+'/gi) || []; | ||
var queries = simpleQueryGroups | ||
.concat(queryGroupsWithDoubleQuotes) | ||
.concat(queryGroupsWithSingleQuotes); | ||
// this is pretty complex, thanks to @lejeunerenard for help with it | ||
// (-)? optional negative sign | ||
// \b(\w+) a word boundary and any number of word characters | ||
// (:|=|>=|<=|>|<) the operators we look for | ||
// (['"]?) an optional capture for either a single or double quote | ||
// ( an open capture group | ||
// (?:.(?!\4))+. any number of characters that do not match \4, the captured quote | ||
// | or | ||
// [^\s]+ any number of characters that are not spaces | ||
// ) the closing of the capture group | ||
// \4 the closing single or double quote | ||
var queries = query.match(/(-)?\b(\w+)(:|=|>=|<=|>|<)(['"]?)((?:.(?!\4))+.|[^\s]+)\4/gi) || []; | ||
queries.forEach(function (group) { | ||
@@ -40,4 +43,10 @@ var operator = (group.match(OPERATOR_REGEX) || [":"])[0]; | ||
case "coloridentity": | ||
params.colorIdentity.method = operator; | ||
params.colorIdentity.colors = parse_color_identity_1.default(value); | ||
if (Number(value) >= 0 && Number(value) < 6) { | ||
params.colorIdentity.sizeFilter.method = operator; | ||
params.colorIdentity.sizeFilter.value = Number(value); | ||
} | ||
else { | ||
params.colorIdentity.colorFilter.method = operator; | ||
params.colorIdentity.colorFilter.value = parse_color_identity_1.default(value); | ||
} | ||
break; | ||
@@ -107,4 +116,10 @@ case "card": | ||
colorIdentity: { | ||
method: "none", | ||
colors: [], | ||
colorFilter: { | ||
method: "none", | ||
value: [], | ||
}, | ||
sizeFilter: { | ||
method: "none", | ||
value: 5, | ||
}, | ||
}, | ||
@@ -111,0 +126,0 @@ prerequisites: { |
@@ -48,3 +48,3 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var searchParams, cards, colorIdentity, combos, matchingCombo; | ||
var searchParams, cards, colorIdentityFilter, combos, matchingCombo, sizeValue_1; | ||
return __generator(this, function (_a) { | ||
@@ -55,5 +55,5 @@ switch (_a.label) { | ||
cards = searchParams.cards; | ||
colorIdentity = searchParams.colorIdentity.colors; | ||
if (colorIdentity) { | ||
colorIdentity = colorIdentity.map(function (color) { | ||
colorIdentityFilter = searchParams.colorIdentity.colorFilter.value; | ||
if (colorIdentityFilter) { | ||
colorIdentityFilter = colorIdentityFilter.map(function (color) { | ||
return normalize_string_input_1.default(color); | ||
@@ -78,18 +78,18 @@ }); | ||
} | ||
if (colorIdentity.length > 0) { | ||
if (colorIdentityFilter.length > 0) { | ||
combos = combos.filter(function (combo) { | ||
switch (searchParams.colorIdentity.method) { | ||
switch (searchParams.colorIdentity.colorFilter.method) { | ||
case "=": | ||
return combo.colorIdentity.is(colorIdentity); | ||
return combo.colorIdentity.is(colorIdentityFilter); | ||
case ">": | ||
return (combo.colorIdentity.includes(colorIdentity) && | ||
!combo.colorIdentity.is(colorIdentity)); | ||
return (combo.colorIdentity.includes(colorIdentityFilter) && | ||
!combo.colorIdentity.is(colorIdentityFilter)); | ||
case ">=": | ||
return combo.colorIdentity.includes(colorIdentity); | ||
return combo.colorIdentity.includes(colorIdentityFilter); | ||
case "<": | ||
return (combo.colorIdentity.isWithin(colorIdentity) && | ||
!combo.colorIdentity.is(colorIdentity)); | ||
return (combo.colorIdentity.isWithin(colorIdentityFilter) && | ||
!combo.colorIdentity.is(colorIdentityFilter)); | ||
case "<=": | ||
case ":": | ||
return combo.colorIdentity.isWithin(colorIdentity); | ||
return combo.colorIdentity.isWithin(colorIdentityFilter); | ||
default: | ||
@@ -100,2 +100,23 @@ return true; | ||
} | ||
if (searchParams.colorIdentity.sizeFilter.method !== "none") { | ||
sizeValue_1 = searchParams.colorIdentity.sizeFilter.value; | ||
combos = combos.filter(function (combo) { | ||
var numberOfColors = combo.colorIdentity.numberOfColors(); | ||
switch (searchParams.colorIdentity.sizeFilter.method) { | ||
case ":": | ||
case "=": | ||
return numberOfColors === sizeValue_1; | ||
case ">": | ||
return numberOfColors > sizeValue_1; | ||
case ">=": | ||
return numberOfColors >= sizeValue_1; | ||
case "<": | ||
return numberOfColors < sizeValue_1; | ||
case "<=": | ||
return numberOfColors <= sizeValue_1; | ||
default: | ||
return true; | ||
} | ||
}); | ||
} | ||
if (searchParams.prerequisites.include.length > 0) { | ||
@@ -102,0 +123,0 @@ combos = combos.filter(function (combo) { |
@@ -41,6 +41,12 @@ import type CardGrouping from "./models/card-grouping"; | ||
colorIdentity: { | ||
method: string; | ||
colors: ColorIdentityColors[]; | ||
colorFilter: { | ||
method: string; | ||
value: ColorIdentityColors[]; | ||
}; | ||
sizeFilter: { | ||
method: string; | ||
value: number; | ||
}; | ||
}; | ||
errors: SearchError[]; | ||
}; |
{ | ||
"name": "commander-spellbook", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "A wrapper for parsing the commander spellbook api.", | ||
@@ -12,2 +12,3 @@ "main": "dist/index.js", | ||
"prebuild": "npm run pretty", | ||
"pretypescript": "rimraf dist", | ||
"typescript": "tsc --declaration --project tsconfig.production.json", | ||
@@ -53,2 +54,3 @@ "build": "webpack", | ||
"prettier": "^2.1.1", | ||
"rimraf": "^3.0.2", | ||
"style-loader": "^2.0.0", | ||
@@ -55,0 +57,0 @@ "tailwindcss": "^1.9.6", |
@@ -111,2 +111,18 @@ ## Commander Spellbook | ||
The `:`, `=`, `>`, `>=`, `<`, and `<=` operators are supported. | ||
```js | ||
spellbook.seach("Kiki ci=wbr").then((combos) => { | ||
// all combos that include cards with the name Kiki and have an identity of exactly white/black/red | ||
}); | ||
``` | ||
Using numbers are also supported: | ||
```js | ||
spellbook.seach("Kiki ci>2").then((combos) => { | ||
// all combos that include cards with the name Kiki and have 3 or more colors in her identity | ||
}); | ||
``` | ||
You can also query by the prequisites, steps and results in the combo. | ||
@@ -113,0 +129,0 @@ |
462
58070
24
29
1048