@woosh/meep-engine 2.48.10 → 2.48.11

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/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.48.10",
8
+ "version": "2.48.11",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -0,0 +1,63 @@
1
+ import { BaseMatcher } from "../BaseMatcher.js";
2
+
3
+
4
+ const RX = /%([0-9]+)/gi;
5
+
6
+ export class DescribeAs extends BaseMatcher {
7
+ /**
8
+ * @type {string}
9
+ */
10
+ template
11
+ /**
12
+ * @type {Matcher}
13
+ */
14
+ matcher
15
+ /**
16
+ * @type {[]}
17
+ */
18
+ values
19
+
20
+ /**
21
+ *
22
+ * @param {string} template
23
+ * @param {Matcher} matcher
24
+ * @param {[]} values
25
+ */
26
+ constructor(template, matcher, values) {
27
+ super();
28
+
29
+ this.template = template;
30
+ this.matcher = matcher;
31
+ this.values = values;
32
+ }
33
+
34
+ matches(item, mismatch_description) {
35
+ return this.matcher.matches(item, mismatch_description);
36
+ }
37
+
38
+ describeTo(description) {
39
+
40
+ let textStart = 0;
41
+
42
+ const matches = this.template.matchAll(RX);
43
+
44
+ for (let i = 0; i < matches.length; i++) {
45
+ const match = matches[i];
46
+
47
+ description.appendText(this.template.substring(textStart, match.index));
48
+
49
+ const group_index = parseInt(match.groups[1]);
50
+
51
+ description.appendValue(this.values[group_index]);
52
+
53
+ textStart = match[0].length;
54
+ }
55
+ if (textStart < this.template.length) {
56
+ description.appendText(this.template.slice(textStart));
57
+ }
58
+ }
59
+
60
+ describeMismatch(item, mismatch_description) {
61
+ this.matcher.describeMismatch(item, mismatch_description);
62
+ }
63
+ }
@@ -0,0 +1,19 @@
1
+ import { BaseMatcher } from "../BaseMatcher.js";
2
+
3
+ export class IsAnything extends BaseMatcher {
4
+ message
5
+
6
+ constructor(message = "ANYTHING") {
7
+ super();
8
+
9
+ this.message = message;
10
+ }
11
+
12
+ matches(item, mismatch_description = NullDescription.INSTANCE) {
13
+ return false;
14
+ }
15
+
16
+ describeTo(description) {
17
+ description.appendText(this.message);
18
+ }
19
+ }
@@ -7,6 +7,8 @@ import { IsIterableContaining } from "./IsIterableContaining.js";
7
7
  import { Matcher } from "../Matcher.js";
8
8
  import { IsUndefined } from "./IsUndefined.js";
9
9
  import { IsIn } from "./IsIn.js";
10
+ import { IsAnything } from "./IsAnything.js";
11
+ import { DescribeAs } from "./DescribeAs.js";
10
12
 
11
13
  export function anyOf(...matchers) {
12
14
  return new AnyOf(matchers);
@@ -16,34 +18,69 @@ export function allOf(...matchers) {
16
18
  return new AllOf(matchers);
17
19
  }
18
20
 
21
+ /**
22
+ * @template T
23
+ * @param {Matcher<T>} matcher
24
+ * @return {Matcher<T>}
25
+ */
19
26
  export function not(matcher) {
20
27
  return new IsNot(matcher);
21
28
  }
22
29
 
30
+ /**
31
+ * @template T
32
+ * @param {T} thing
33
+ * @return {Matcher<T>}
34
+ */
23
35
  export function equalTo(thing) {
24
36
  return new IsEqual(thing);
25
37
  }
26
38
 
39
+ /**
40
+ * @template T
41
+ * @param {T} thing
42
+ * @return {Matcher<T>}
43
+ */
27
44
  export function notEqualTo(thing) {
28
45
  return not(equalTo(thing));
29
46
  }
30
47
 
48
+ /**
49
+ * @template T
50
+ * @return {Matcher<T>}
51
+ */
31
52
  export function isNull() {
32
53
  return new IsNull();
33
54
  }
34
55
 
56
+ /**
57
+ * @template T
58
+ * @return {Matcher<T>}
59
+ */
35
60
  export function isNotNull() {
36
61
  return not(isNull());
37
62
  }
38
63
 
64
+ /**
65
+ * @template T
66
+ * @return {Matcher<T>}
67
+ */
39
68
  export function isUndefined() {
40
69
  return new IsUndefined();
41
70
  }
42
71
 
72
+ /**
73
+ * @template T
74
+ * @return {Matcher<T>}
75
+ */
43
76
  export function isDefined() {
44
77
  return not(isUndefined());
45
78
  }
46
79
 
80
+ /**
81
+ * @template T
82
+ * @return {Matcher<T>}
83
+ */
47
84
  export const isNoUndefined = isDefined;
48
85
 
49
86
  /**
@@ -77,3 +114,41 @@ export function isIn(array) {
77
114
  export function isOneOf(...elements) {
78
115
  return isIn(elements);
79
116
  }
117
+
118
+
119
+ /**
120
+ * @template T
121
+ * @param {string} template
122
+ * @param {Matcher<T>} matcher
123
+ * @param {[]} values
124
+ * @returns {Matcher<T>}
125
+ */
126
+ function describeAs(template, matcher, values) {
127
+ return new DescribeAs(template, matcher, values);
128
+ }
129
+
130
+ /**
131
+ *
132
+ * @template T
133
+ * @param {string} [message]
134
+ * @return {Matcher<T>}
135
+ */
136
+ export function anything(message) {
137
+ return new IsAnything(message);
138
+ }
139
+
140
+ /**
141
+ * @template T
142
+ * @param {string} [message]
143
+ * @return {Matcher<T>}
144
+ */
145
+ export function nothing(message) {
146
+ const matcher = not(anything());
147
+
148
+ if (message !== undefined) {
149
+ return describeAs(message, matcher, []);
150
+ } else {
151
+ return matcher;
152
+ }
153
+ }
154
+