@sigil-sifter/magic 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +95 -0
- package/package.json +30 -0
- package/src/core/MagicCard.js +250 -0
- package/src/core/helpers.js +6 -0
- package/src/core/index.js +3 -0
- package/src/data/abilityWords.js +66 -0
- package/src/data/colors.js +15 -0
- package/src/data/gameFormats.js +25 -0
- package/src/data/games.js +5 -0
- package/src/data/guilds.js +33 -0
- package/src/data/languages.js +30 -0
- package/src/data/rarities.js +25 -0
- package/src/expressions/ArrayLengthExpression.js +15 -0
- package/src/expressions/ColorExpression.js +40 -0
- package/src/expressions/DevotionExpression.js +56 -0
- package/src/expressions/EvenOddExpression.js +43 -0
- package/src/expressions/ExactStringExpression.js +11 -0
- package/src/expressions/FormatExpression.js +19 -0
- package/src/expressions/GameExpression.js +19 -0
- package/src/expressions/KeywordAbilityExpression.js +33 -0
- package/src/expressions/LanguageExpression.js +34 -0
- package/src/expressions/ManaExpression.js +36 -0
- package/src/expressions/PowTouExpression.js +41 -0
- package/src/expressions/ProducesExpression.js +35 -0
- package/src/expressions/RarityExpression.js +30 -0
- package/src/expressions/has/IndicatorExpression.js +11 -0
- package/src/expressions/has/WatermarkExpression.js +11 -0
- package/src/expressions/is/BoosterExpression.js +11 -0
- package/src/expressions/is/DFCExpression.js +11 -0
- package/src/expressions/is/EtchedExpression.js +11 -0
- package/src/expressions/is/FlipExpression.js +11 -0
- package/src/expressions/is/FoilExpression.js +11 -0
- package/src/expressions/is/FrenchVanillaExpression.js +11 -0
- package/src/expressions/is/FullArtExpression.js +11 -0
- package/src/expressions/is/GlossyExpression.js +11 -0
- package/src/expressions/is/HistoricExpression.js +11 -0
- package/src/expressions/is/HybridExpression.js +11 -0
- package/src/expressions/is/LevelerExpression.js +11 -0
- package/src/expressions/is/MDFCExpression.js +11 -0
- package/src/expressions/is/MeldExpression.js +11 -0
- package/src/expressions/is/ModalExpression.js +11 -0
- package/src/expressions/is/NonFoilExpression.js +11 -0
- package/src/expressions/is/PartyExpression.js +11 -0
- package/src/expressions/is/PermanentExpression.js +11 -0
- package/src/expressions/is/PhyrexianExpression.js +11 -0
- package/src/expressions/is/PromoExpression.js +11 -0
- package/src/expressions/is/ReprintExpression.js +11 -0
- package/src/expressions/is/ReservedExpression.js +11 -0
- package/src/expressions/is/SpellExpression.js +11 -0
- package/src/expressions/is/SplitExpression.js +11 -0
- package/src/expressions/is/SpotlightExpression.js +11 -0
- package/src/expressions/is/TextlessExpression.js +11 -0
- package/src/expressions/is/TransformExpression.js +11 -0
- package/src/expressions/is/UniversesBeyondExpression.js +11 -0
- package/src/expressions/is/VanillaExpression.js +11 -0
- package/src/expressions/is/index.js +59 -0
- package/src/extensions/ColorExtension.js +22 -0
- package/src/extensions/FormatExtension.js +15 -0
- package/src/extensions/GameExtension.js +15 -0
- package/src/extensions/KeywordExtension.js +11 -0
- package/src/extensions/LanguageExtension.js +15 -0
- package/src/extensions/RarityExtension.js +20 -0
- package/src/extensions/SetExtension.js +13 -0
- package/src/index.js +36 -0
- package/src/keywords/AbilityKeyword.js +16 -0
- package/src/keywords/ArtistKeyword.js +11 -0
- package/src/keywords/BannedKeyword.js +21 -0
- package/src/keywords/BorderKeyword.js +21 -0
- package/src/keywords/CardTypeKeyword.js +11 -0
- package/src/keywords/CollectorNumberKeyword.js +16 -0
- package/src/keywords/ColorIdentityKeyword.js +11 -0
- package/src/keywords/ColorKeyword.js +17 -0
- package/src/keywords/DevotionKeyword.js +21 -0
- package/src/keywords/FlavorTextKeyword.js +11 -0
- package/src/keywords/FormatKeyword.js +21 -0
- package/src/keywords/FrameKeyword.js +22 -0
- package/src/keywords/GameKeyword.js +21 -0
- package/src/keywords/HasKeyword.js +13 -0
- package/src/keywords/IsKeyword.js +17 -0
- package/src/keywords/LanguageKeyword.js +16 -0
- package/src/keywords/LoyaltyKeyword.js +16 -0
- package/src/keywords/ManaCostKeyword.js +20 -0
- package/src/keywords/ManaValueKeyword.js +17 -0
- package/src/keywords/NameKeyword.js +11 -0
- package/src/keywords/NotKeyword.js +21 -0
- package/src/keywords/PowerKeyword.js +29 -0
- package/src/keywords/ProducesKeyword.js +16 -0
- package/src/keywords/RarityKeyword.js +16 -0
- package/src/keywords/RestrictedKeyword.js +21 -0
- package/src/keywords/RulesTextKeyword.js +11 -0
- package/src/keywords/SetKeyword.js +21 -0
- package/src/keywords/SetTypeKeyword.js +21 -0
- package/src/keywords/StampKeyword.js +21 -0
- package/src/keywords/ToughnessKeyword.js +29 -0
- package/src/keywords/WatermarkKeyword.js +16 -0
- package/src/keywords/index.js +65 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {SearchSyntaxError} from 'sigil-sifter/core';
|
|
2
|
+
import ManaExpression from './ManaExpression.js';
|
|
3
|
+
|
|
4
|
+
const allowedSymbolTypes = [
|
|
5
|
+
'coloredMana',
|
|
6
|
+
'twoColorHybridMana',
|
|
7
|
+
'threeColorHybridMana',
|
|
8
|
+
'fourColorHybridMana',
|
|
9
|
+
'fiveColorHybridMana'
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
function isAllowedColor(prevSymbol, sym) {
|
|
13
|
+
const inputValue = sym.colors.sort().join('/');
|
|
14
|
+
if (prevSymbol.length)
|
|
15
|
+
return prevSymbol[0] === inputValue;
|
|
16
|
+
prevSymbol.push(inputValue);
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default class DevotionExpression extends ManaExpression {
|
|
21
|
+
constructor(sifter, match, str) {
|
|
22
|
+
super(sifter, match, str);
|
|
23
|
+
let prevSymbol = [];
|
|
24
|
+
const invalidInput = this.searchManaCost.symbols.some(sym => {
|
|
25
|
+
return !allowedSymbolTypes.includes(sym.type)
|
|
26
|
+
|| !isAllowedColor(prevSymbol, sym);
|
|
27
|
+
});
|
|
28
|
+
if (invalidInput)
|
|
29
|
+
throw new SearchSyntaxError(
|
|
30
|
+
'Devotion can only match single color and hybrid mana',
|
|
31
|
+
match[0]
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
includes(val) {
|
|
36
|
+
return this.greaterThan(val) || this.equals(val);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
equals(val) {
|
|
40
|
+
return this.searchManaCost.colors.some(c => {
|
|
41
|
+
return val.getDevotionTo(c) === this.searchManaCost.getDevotionTo(c);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
greaterThan(val) {
|
|
46
|
+
return this.searchManaCost.colors.some(c => {
|
|
47
|
+
return val.getDevotionTo(c) > this.searchManaCost.getDevotionTo(c);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
lessThan(val) {
|
|
52
|
+
return this.searchManaCost.colors.every(c => {
|
|
53
|
+
return val.getDevotionTo(c) < this.searchManaCost.getDevotionTo(c);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SearchSyntaxError } from 'sigil-sifter/core';
|
|
2
|
+
import { Expression } from 'sigil-sifter/expressions';
|
|
3
|
+
|
|
4
|
+
export default class EvenOddExpression extends Expression {
|
|
5
|
+
static match(sifter, str) {
|
|
6
|
+
return str.match(/^(even|odd)/i);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static parse(sifter, match, str) {
|
|
10
|
+
return new EvenOddExpression(sifter, match, str);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(sifter, match, str) {
|
|
14
|
+
super(sifter, match, str);
|
|
15
|
+
const isOdd = match[1].toLowerCase() === 'odd';
|
|
16
|
+
this.expectedRemainder = isOdd ? 1 : 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
includes(val) {
|
|
20
|
+
return (val % 2) === this.expectedRemainder;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
equals(val) {
|
|
24
|
+
throw new SearchSyntaxError(
|
|
25
|
+
'Equality operators are not supported for even/odd ' +
|
|
26
|
+
'expressions, use the includes operator (\':\') instead.'
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
greaterThan(val) {
|
|
31
|
+
throw new SearchSyntaxError(
|
|
32
|
+
'Comparison operators are not supported for even/odd ' +
|
|
33
|
+
'expressions, use the includes operator (\':\') instead.'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
lessThan(val) {
|
|
38
|
+
throw new SearchSyntaxError(
|
|
39
|
+
'Comparison operators are not supported for even/odd ' +
|
|
40
|
+
'expressions, use the includes operator (\':\') instead.'
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
2
|
+
|
|
3
|
+
export default class ExactStringExpression extends StringExpression {
|
|
4
|
+
includes(value) {
|
|
5
|
+
return this.equals(value);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
equals(value) {
|
|
9
|
+
return value.toLowerCase() === this.value;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SearchSyntaxError } from 'sigil-sifter/core';
|
|
2
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
3
|
+
|
|
4
|
+
export default class FormatExpression extends StringExpression {
|
|
5
|
+
constructor(sifter, match, str) {
|
|
6
|
+
super(sifter, match, str);
|
|
7
|
+
this.format = sifter.FormatExtension.resolveFormat(this.value);
|
|
8
|
+
if (!this.format)
|
|
9
|
+
throw new SearchSyntaxError('Unknown game format', match[0]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
includes(val) {
|
|
13
|
+
return this.equals(val);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
equals(val) {
|
|
17
|
+
return this.format.expr.test(val);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SearchSyntaxError } from 'sigil-sifter/core';
|
|
2
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
3
|
+
|
|
4
|
+
export default class GameExpression extends StringExpression {
|
|
5
|
+
constructor(sifter, match, str) {
|
|
6
|
+
super(sifter, match, str);
|
|
7
|
+
this.game = sifter.GameExtension.resolveGame(this.value);
|
|
8
|
+
if (!this.game)
|
|
9
|
+
throw new SearchSyntaxError('Unknown game', match[0]);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
includes(val) {
|
|
13
|
+
return val.some(g => this.game.expr.test(g));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
equals(val) {
|
|
17
|
+
return this.includes(val);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { SearchSyntaxError } from 'sigil-sifter/core';
|
|
2
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
3
|
+
|
|
4
|
+
export default class KeywordAbilityExpression extends StringExpression {
|
|
5
|
+
static parse(sifter, match, str) {
|
|
6
|
+
return new KeywordAbilityExpression(sifter, match, str);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
includes(val) {
|
|
10
|
+
return val.includes(this.value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
equals(val) {
|
|
14
|
+
throw new SearchSyntaxError(
|
|
15
|
+
'Keyword expressions do not support the equals operator',
|
|
16
|
+
this.remainingStr
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
greaterThan(val) {
|
|
21
|
+
throw new SearchSyntaxError(
|
|
22
|
+
'Keyword expressions do not support the greater than operator',
|
|
23
|
+
this.remainingStr
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
lessThan(val) {
|
|
28
|
+
throw new SearchSyntaxError(
|
|
29
|
+
'Keyword expressions do not support the less than operator',
|
|
30
|
+
this.remainingStr
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { SearchSyntaxError } from 'sigil-sifter/core';
|
|
2
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
3
|
+
|
|
4
|
+
export default class LanguageExpression extends StringExpression {
|
|
5
|
+
constructor(sifter, match, str) {
|
|
6
|
+
super(sifter, match, str);
|
|
7
|
+
this.value = match[1];
|
|
8
|
+
this.language = sifter.LanguageExtension.resolveLanguage(this.value);
|
|
9
|
+
if (!this.language)
|
|
10
|
+
throw new SearchSyntaxError('Unknown language', this.value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
includes(val) {
|
|
14
|
+
return this.equals(val);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
equals(val) {
|
|
18
|
+
return val === this.language.acronyms[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
greaterThan(val) {
|
|
22
|
+
throw new SearchSyntaxError(
|
|
23
|
+
'Comparison operators are not supported for language ' +
|
|
24
|
+
'expressions, use the includes operator (\':\') instead.'
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
lessThan(val) {
|
|
29
|
+
throw new SearchSyntaxError(
|
|
30
|
+
'Comparison operators are not supported for language ' +
|
|
31
|
+
'expressions, use the includes operator (\':\') instead.'
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
2
|
+
import {SearchSyntaxError} from 'sigil-sifter/core';
|
|
3
|
+
import { ManaCost } from 'mana-scribe';
|
|
4
|
+
|
|
5
|
+
export default class ManaExpression extends StringExpression {
|
|
6
|
+
static parse(sifter, match, str) {
|
|
7
|
+
return new this(sifter, match, str);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
constructor(sifter, match, str) {
|
|
11
|
+
super(sifter, match, str);
|
|
12
|
+
this.searchManaCost = ManaCost.parse(this.value);
|
|
13
|
+
const unparsedManaCost = this.searchManaCost.remainingStr;
|
|
14
|
+
if (unparsedManaCost.length > 0)
|
|
15
|
+
throw new SearchSyntaxError(
|
|
16
|
+
'Failed to parse mana cost',
|
|
17
|
+
unparsedManaCost
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
includes(val) {
|
|
22
|
+
return this.greaterThan(val) || this.equals(val);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
equals(val) {
|
|
26
|
+
return val.equals(this.searchManaCost);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
greaterThan(val) {
|
|
30
|
+
return val.greaterThan(this.searchManaCost);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
lessThan(val) {
|
|
34
|
+
return val.lessThan(this.searchManaCost);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { SearchSyntaxError } from 'sigil-sifter/core';
|
|
2
|
+
import { Expression } from 'sigil-sifter/expressions';
|
|
3
|
+
|
|
4
|
+
export default class PowTouExpression extends Expression {
|
|
5
|
+
static match(sifter, str) {
|
|
6
|
+
return str.match(/^(pow(er)?|tou(ghness)?)/i);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static parse(sifter, match, str) {
|
|
10
|
+
return new PowTouExpression(sifter, match, str);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(sifter, match, str) {
|
|
14
|
+
super(sifter, match, str);
|
|
15
|
+
const key = match[1].toLowerCase();
|
|
16
|
+
this.powerMode = key === 'pow' || key === 'power';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
includes() {
|
|
20
|
+
throw new SearchSyntaxError(
|
|
21
|
+
'Includes operator is not supported for pow/tou expressions, ' +
|
|
22
|
+
'use a comparison or equality operator instead.'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
equals({ power, toughness }) {
|
|
27
|
+
return power === toughness;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
greaterThan({ power, toughness }) {
|
|
31
|
+
return this.powerMode
|
|
32
|
+
? power < toughness
|
|
33
|
+
: toughness < power;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
lessThan({ power, toughness }) {
|
|
37
|
+
return this.powerMode
|
|
38
|
+
? power > toughness
|
|
39
|
+
: toughness > power;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Expression } from 'sigil-sifter/expressions';
|
|
2
|
+
|
|
3
|
+
export default class ProducesExpression extends Expression {
|
|
4
|
+
static match(sifter, str) {
|
|
5
|
+
return str.match(sifter.ColorExtension.colorNamesExpr)
|
|
6
|
+
|| str.match(/^([wubrgc]+)/i);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static parse(sifter, match, str) {
|
|
10
|
+
return new this(sifter, match, str);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(sifter, match, str) {
|
|
14
|
+
super(sifter, match, str);
|
|
15
|
+
this.value = match[0];
|
|
16
|
+
this.colors = sifter.ColorExtension.resolveColors(this.value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
includes(val) {
|
|
20
|
+
return this.colors.every(c => val.includes(c));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
equals(val) {
|
|
24
|
+
return val.length === this.colors.length && this.includes(val);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
greaterThan(val) {
|
|
28
|
+
return val.length > this.colors.length && this.includes(val);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
lessThan(val) {
|
|
32
|
+
return val.length < this.colors.length
|
|
33
|
+
&& val.every(c => this.colors.includes(c));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { StringExpression } from 'sigil-sifter/expressions';
|
|
2
|
+
|
|
3
|
+
export default class RarityExpression extends StringExpression {
|
|
4
|
+
static match(sifter, str) {
|
|
5
|
+
return str.match(sifter.RarityExtension.rarityExpr);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
constructor(sifter, match, str) {
|
|
9
|
+
super(sifter, match, str);
|
|
10
|
+
this.rarity = sifter.RarityExtension.resolveRarity(this.value);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
includes(val) {
|
|
14
|
+
return this.equals(val);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
equals(val) {
|
|
18
|
+
return this.rarity.name.toLowerCase() === val;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
greaterThan(val) {
|
|
22
|
+
const valGroup = this.sifter.RarityExtension.resolveRarity(val);
|
|
23
|
+
return this.rarity.index < valGroup.index;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
lessThan(val) {
|
|
27
|
+
const valGroup = this.sifter.RarityExtension.resolveRarity(val);
|
|
28
|
+
return this.rarity.index > valGroup.index;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Expression } from 'sigil-sifter/expressions';
|
|
2
|
+
|
|
3
|
+
export default class FrenchVanillaExpression extends Expression {
|
|
4
|
+
static match(sifter, str) {
|
|
5
|
+
return str.match(/^frenchvanilla/i);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
includes(card) {
|
|
9
|
+
return card.isFrenchVanilla;
|
|
10
|
+
}
|
|
11
|
+
}
|