commander-spellbook
Advanced tools
Comparing version 0.10.0 to 0.11.0
@@ -0,1 +1,14 @@ | ||
# 0.11.0 | ||
- Add `autocomplete` method | ||
- `search` | ||
- Add `sort` and `order` properties to search results | ||
- Remove extraneous new lines in combo data | ||
_Breaking Changes_ | ||
- Validate operators for `sort` and `order` to only allow `:` and `=` | ||
- Remove `number-of` aliases for `sort` options | ||
# 0.10.0 | ||
@@ -2,0 +15,0 @@ |
@@ -0,1 +1,2 @@ | ||
import autocomplete from "./autocomplete"; | ||
import search from "./search"; | ||
@@ -8,2 +9,3 @@ import random from "./random"; | ||
declare const _default: { | ||
autocomplete: typeof autocomplete; | ||
search: typeof search; | ||
@@ -10,0 +12,0 @@ random: typeof random; |
@@ -5,2 +5,3 @@ "use strict"; | ||
}; | ||
var autocomplete_1 = __importDefault(require("./autocomplete")); | ||
var search_1 = __importDefault(require("./search")); | ||
@@ -13,2 +14,3 @@ var random_1 = __importDefault(require("./random")); | ||
module.exports = { | ||
autocomplete: autocomplete_1.default, | ||
search: search_1.default, | ||
@@ -15,0 +17,0 @@ random: random_1.default, |
@@ -31,3 +31,6 @@ "use strict"; | ||
if (items) { | ||
var entries = items.split(/\.\s?/).filter(function (entry) { return entry; }); | ||
var entries = items | ||
.split(/\.\s?/) | ||
.map(function (entry) { return entry.replace(/\r?\n|\r/g, "").trim(); }) | ||
.filter(function (entry) { return entry; }); | ||
list.rawString = items; | ||
@@ -34,0 +37,0 @@ list.push.apply(list, entries); |
@@ -100,6 +100,6 @@ "use strict"; | ||
case "sort": | ||
parse_sort_1.default(params, value); | ||
parse_sort_1.default(params, operator, value); | ||
break; | ||
case "order": | ||
parse_order_1.default(params, value); | ||
parse_order_1.default(params, operator, value); | ||
break; | ||
@@ -106,0 +106,0 @@ default: |
import type { SearchParameters } from "../types"; | ||
export default function parseSort(params: SearchParameters, value: string): void; | ||
export default function parseOrder(params: SearchParameters, operator: string, value: string): void; |
@@ -7,3 +7,4 @@ "use strict"; | ||
var normalize_string_input_1 = __importDefault(require("../normalize-string-input")); | ||
function parseSort(params, value) { | ||
var SUPPORTED_OPERATORS = [":", "="]; | ||
function parseOrder(params, operator, value) { | ||
if (params.order) { | ||
@@ -17,2 +18,10 @@ params.errors.push({ | ||
} | ||
if (!SUPPORTED_OPERATORS.includes(operator)) { | ||
params.errors.push({ | ||
key: "order", | ||
value: value, | ||
message: "Order does not support the \"" + operator + "\" operator.", | ||
}); | ||
return; | ||
} | ||
value = normalize_string_input_1.default(value); | ||
@@ -39,2 +48,2 @@ switch (value) { | ||
} | ||
exports.default = parseSort; | ||
exports.default = parseOrder; |
import type { SearchParameters } from "../types"; | ||
export default function parseSort(params: SearchParameters, value: string): void; | ||
export default function parseSort(params: SearchParameters, operator: string, value: string): void; |
@@ -7,3 +7,4 @@ "use strict"; | ||
var normalize_string_input_1 = __importDefault(require("../normalize-string-input")); | ||
function parseSort(params, value) { | ||
var SUPPORTED_OPERATORS = [":", "="]; | ||
function parseSort(params, operator, value) { | ||
if (params.sort) { | ||
@@ -17,19 +18,17 @@ params.errors.push({ | ||
} | ||
if (!SUPPORTED_OPERATORS.includes(operator)) { | ||
params.errors.push({ | ||
key: "sort", | ||
value: value, | ||
message: "Sort does not support the \"" + operator + "\" operator.", | ||
}); | ||
return; | ||
} | ||
value = normalize_string_input_1.default(value); | ||
switch (value) { | ||
case "prerequisites": | ||
case "steps": | ||
case "results": | ||
case "numberofresults": | ||
value = "number-of-results"; | ||
break; | ||
case "steps": | ||
case "numberofsteps": | ||
value = "number-of-steps"; | ||
break; | ||
case "prerequisites": | ||
case "numberofprerequisites": | ||
value = "number-of-prerequisites"; | ||
break; | ||
case "cards": | ||
case "numberofcards": | ||
value = "number-of-cards"; | ||
// make no changes to value | ||
break; | ||
@@ -36,0 +35,0 @@ case "ci": |
@@ -66,2 +66,4 @@ "use strict"; | ||
errors: errors, | ||
sort: sort, | ||
order: order, | ||
combos: [], | ||
@@ -82,2 +84,4 @@ message: "No valid search parameters submitted", | ||
errors: errors, | ||
sort: sort, | ||
order: order, | ||
combos: combos, | ||
@@ -84,0 +88,0 @@ message: create_message_1.default(combos, searchParams), |
@@ -7,4 +7,3 @@ "use strict"; | ||
var color_combo_order_1 = __importDefault(require("./color-combo-order")); | ||
function handleSortingForNumberOfElements(firstCombo, secondCombo, by) { | ||
var prop = by.split("number-of-")[1]; | ||
function handleSortingForNumberOfElements(firstCombo, secondCombo, prop) { | ||
var isEqual = firstCombo[prop].length === secondCombo[prop].length; | ||
@@ -27,3 +26,3 @@ var firstRemainsFirst = firstCombo[prop].length > secondCombo[prop].length; | ||
if (isEqual) { | ||
return handleSortingForNumberOfElements(firstCombo, secondCombo, "number-of-cards"); | ||
return handleSortingForNumberOfElements(firstCombo, secondCombo, "cards"); | ||
} | ||
@@ -48,6 +47,6 @@ return { | ||
break; | ||
case "number-of-cards": | ||
case "number-of-prerequisites": | ||
case "number-of-steps": | ||
case "number-of-results": | ||
case "cards": | ||
case "prerequisites": | ||
case "steps": | ||
case "results": | ||
meta = handleSortingForNumberOfElements(firstCombo, secondCombo, by); | ||
@@ -54,0 +53,0 @@ break; |
@@ -18,2 +18,4 @@ import type CardGrouping from "./models/card-grouping"; | ||
errors: SearchError[]; | ||
sort: string; | ||
order: string; | ||
message: string; | ||
@@ -20,0 +22,0 @@ }; |
{ | ||
"name": "commander-spellbook", | ||
"version": "0.10.0", | ||
"version": "0.11.0", | ||
"description": "A wrapper for parsing the commander spellbook api.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -163,2 +163,48 @@ ## Commander Spellbook | ||
The way the combos were sorted and ordered can be found on the `sort` and `order` properties. By default, `sort` will be `colors` and `order` will be `ascending`. | ||
```js | ||
spellbook.search("Aetherflux").then((result) => { | ||
result.sort; // colors | ||
result.order; // ascending | ||
}); | ||
``` | ||
You can override the default `sort` and `order`: | ||
```js | ||
spellbook.search("Aetherflux sort:results order:descending").then((result) => { | ||
result.sort; // results | ||
result.order; // descending | ||
}); | ||
``` | ||
## Autocomplete | ||
Look up possible values for card names, results, or colors | ||
```js | ||
spellbook.autocomplete("cards", "dream").then((cards) => { | ||
cards; // cards that contain the word dream in them | ||
cards[0].value; // normalized (lowercased, punctuation removed) version of the name | ||
cards[0].label; // regular version of the name | ||
}); | ||
``` | ||
```js | ||
spellbook.autocomplete("results", "infinite").then((results) => { | ||
results; // results that contain the word infinite in them | ||
results[0].value; // normalized (lowercased, punctuation removed) version of the result | ||
results[0].label; // regular version of the result | ||
}); | ||
``` | ||
```js | ||
spellbook.autocomplete("colors", "wu").then((colors) => { | ||
colors; // color combos that contain blue and white in them | ||
colors[0].value; // azorius | ||
colors[0].label; // Azorius :manaw::manau: | ||
}); | ||
``` | ||
## Random | ||
@@ -165,0 +211,0 @@ |
95836
63
2064
421