@augment-vir/assert 31.0.0 → 31.1.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/dist/assertions/boolean.d.ts +20 -26
- package/dist/assertions/boolean.js +185 -41
- package/dist/assertions/boundary.d.ts +40 -256
- package/dist/assertions/boundary.js +265 -229
- package/dist/assertions/enum.d.ts +12 -13
- package/dist/assertions/enum.js +98 -20
- package/dist/assertions/equality/entry-equality.d.ts +11 -15
- package/dist/assertions/equality/entry-equality.js +210 -43
- package/dist/assertions/equality/json-equality.d.ts +11 -15
- package/dist/assertions/equality/json-equality.js +144 -43
- package/dist/assertions/equality/simple-equality.d.ts +39 -46
- package/dist/assertions/equality/simple-equality.js +316 -61
- package/dist/assertions/extendable-assertions.d.ts +0 -12
- package/dist/assertions/extendable-assertions.js +0 -12
- package/dist/assertions/http.d.ts +10 -14
- package/dist/assertions/http.js +96 -28
- package/dist/assertions/instance.d.ts +10 -18
- package/dist/assertions/instance.js +92 -26
- package/dist/assertions/keys.d.ts +59 -138
- package/dist/assertions/keys.js +279 -162
- package/dist/assertions/length.d.ts +30 -212
- package/dist/assertions/length.js +117 -175
- package/dist/assertions/nullish.d.ts +8 -20
- package/dist/assertions/nullish.js +85 -27
- package/dist/assertions/numeric.d.ts +67 -81
- package/dist/assertions/numeric.js +564 -133
- package/dist/assertions/output.d.ts +2 -3
- package/dist/assertions/output.js +1 -7
- package/dist/assertions/primitive.d.ts +33 -40
- package/dist/assertions/primitive.js +232 -66
- package/dist/assertions/promise.d.ts +20 -30
- package/dist/assertions/promise.js +244 -53
- package/dist/assertions/regexp.d.ts +12 -14
- package/dist/assertions/regexp.js +84 -21
- package/dist/assertions/runtime-type.d.ts +99 -150
- package/dist/assertions/runtime-type.js +805 -229
- package/dist/assertions/throws.d.ts +24 -25
- package/dist/assertions/throws.js +43 -5
- package/dist/assertions/uuid.d.ts +11 -16
- package/dist/assertions/uuid.js +91 -22
- package/dist/assertions/values.d.ts +81 -210
- package/dist/assertions/values.js +627 -234
- package/dist/augments/guards/assert-wrap.d.ts +7 -4
- package/dist/augments/guards/assert-wrap.js +5 -4
- package/dist/augments/guards/check-wrap.d.ts +7 -5
- package/dist/augments/guards/check-wrap.js +5 -4
- package/dist/augments/guards/check.d.ts +5 -5
- package/dist/augments/guards/check.js +5 -4
- package/dist/augments/guards/wait-until.d.ts +8 -4
- package/dist/augments/guards/wait-until.js +7 -8
- package/dist/guard-types/guard-group.d.ts +5 -2
- package/dist/guard-types/wait-until-function.d.ts +2 -10
- package/dist/guard-types/wait-until-function.js +1 -9
- package/dist/index.d.ts +1 -0
- package/package.json +2 -2
- package/dist/guard-types/assert-wrap-function.d.ts +0 -12
- package/dist/guard-types/assert-wrap-function.js +0 -14
- package/dist/guard-types/check-function.d.ts +0 -14
- package/dist/guard-types/check-function.js +0 -22
- package/dist/guard-types/check-wrap-wrapper-function.d.ts +0 -12
- package/dist/guard-types/check-wrap-wrapper-function.js +0 -19
- package/dist/guard-types/guard-override.d.ts +0 -4
- package/dist/guard-types/guard-override.js +0 -10
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { stringify } from '@augment-vir/core';
|
|
2
2
|
import { AssertionError } from '../augments/assertion.error.js';
|
|
3
|
-
import {
|
|
3
|
+
import { createWaitUntil } from '../guard-types/wait-until-function.js';
|
|
4
4
|
function endsWith(parent, child, failureMessage) {
|
|
5
|
-
const message = `${stringify(parent)} does not end with ${stringify(child)}}`;
|
|
6
5
|
if (typeof parent === 'string') {
|
|
7
6
|
if (!parent.endsWith(child)) {
|
|
8
|
-
throw new AssertionError(
|
|
7
|
+
throw new AssertionError(`${stringify(parent)} does not end with ${stringify(child)}}`, failureMessage);
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
else if (parent[parent.length - 1] !== child) {
|
|
12
|
-
throw new AssertionError(
|
|
11
|
+
throw new AssertionError(`${stringify(parent)} does not end with ${stringify(child)}}`, failureMessage);
|
|
13
12
|
}
|
|
14
13
|
}
|
|
15
14
|
function boundaryCheck() {
|
|
@@ -37,42 +36,127 @@ function boundaryWaitUntil() {
|
|
|
37
36
|
*/
|
|
38
37
|
}
|
|
39
38
|
function endsWithout(parent, child, failureMessage) {
|
|
40
|
-
const message = `${stringify(parent)} ends with ${stringify(child)}}`;
|
|
41
39
|
if (typeof parent === 'string') {
|
|
42
40
|
if (parent.endsWith(child)) {
|
|
43
|
-
throw new AssertionError(
|
|
41
|
+
throw new AssertionError(`${stringify(parent)} ends with ${stringify(child)}}`, failureMessage);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
else if (parent[parent.length - 1] === child) {
|
|
47
|
-
throw new AssertionError(
|
|
45
|
+
throw new AssertionError(`${stringify(parent)} ends with ${stringify(child)}}`, failureMessage);
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
function startsWith(parent, child, failureMessage) {
|
|
51
|
-
const message = `${stringify(parent)} does not start with ${stringify(child)}}`;
|
|
52
49
|
if (typeof parent === 'string') {
|
|
53
50
|
if (!parent.startsWith(child)) {
|
|
54
|
-
throw new AssertionError(
|
|
51
|
+
throw new AssertionError(`${stringify(parent)} does not start with ${stringify(child)}}`, failureMessage);
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
54
|
else if (parent[0] !== child) {
|
|
58
|
-
throw new AssertionError(
|
|
55
|
+
throw new AssertionError(`${stringify(parent)} does not start with ${stringify(child)}}`, failureMessage);
|
|
59
56
|
}
|
|
60
57
|
}
|
|
61
58
|
function startsWithout(parent, child, failureMessage) {
|
|
62
|
-
const message = `${stringify(parent)} starts with ${stringify(child)}}`;
|
|
63
59
|
if (typeof parent === 'string') {
|
|
64
60
|
if (parent.startsWith(child)) {
|
|
65
|
-
throw new AssertionError(
|
|
61
|
+
throw new AssertionError(`${stringify(parent)} starts with ${stringify(child)}}`, failureMessage);
|
|
66
62
|
}
|
|
67
63
|
}
|
|
68
64
|
else if (parent[0] === child) {
|
|
69
|
-
throw new AssertionError(
|
|
65
|
+
throw new AssertionError(`${stringify(parent)} starts with ${stringify(child)}}`, failureMessage);
|
|
70
66
|
}
|
|
71
67
|
}
|
|
72
68
|
const assertions = {
|
|
69
|
+
/**
|
|
70
|
+
* Asserts that a parent string or array ends with a specific child. This uses reference
|
|
71
|
+
* equality when the parent is an array.
|
|
72
|
+
*
|
|
73
|
+
* Performs no type guarding.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
*
|
|
77
|
+
* ```ts
|
|
78
|
+
* import {assert} from '@augment-vir/assert';
|
|
79
|
+
*
|
|
80
|
+
* assert.endsWith('ab', 'b'); // passes
|
|
81
|
+
* assert.endsWith('ab', 'a'); // fails
|
|
82
|
+
* assert.endsWith(['a', 'b'], 'b'); // passes
|
|
83
|
+
* assert.endsWith(['a', 'b'], 'a'); // fails
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @throws {@link AssertionError} If the parent does not end with the child.
|
|
87
|
+
* @see
|
|
88
|
+
* - {@link assert.endsWithout} : the opposite assertion.
|
|
89
|
+
* - {@link assert.startsWith} : assertion on the other end.
|
|
90
|
+
*/
|
|
73
91
|
endsWith,
|
|
92
|
+
/**
|
|
93
|
+
* Asserts that a parent string or array does _not_ end with a specific child. This uses
|
|
94
|
+
* reference equality when the parent is an array.
|
|
95
|
+
*
|
|
96
|
+
* Performs no type guarding.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
*
|
|
100
|
+
* ```ts
|
|
101
|
+
* import {assert} from '@augment-vir/assert';
|
|
102
|
+
*
|
|
103
|
+
* assert.endsWithout('ab', 'b'); // fails
|
|
104
|
+
* assert.endsWithout('ab', 'a'); // passes
|
|
105
|
+
* assert.endsWithout(['a', 'b'], 'b'); // fails
|
|
106
|
+
* assert.endsWithout(['a', 'b'], 'a'); // passes
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* @throws {@link AssertionError} If the parent ends with the child.
|
|
110
|
+
* @see
|
|
111
|
+
* - {@link assert.endsWith} : the opposite assertion.
|
|
112
|
+
* - {@link assert.startsWithout} : assertion on the other end.
|
|
113
|
+
*/
|
|
74
114
|
endsWithout,
|
|
115
|
+
/**
|
|
116
|
+
* Asserts that a parent string or array starts with a specific child. This uses reference
|
|
117
|
+
* equality when the parent is an array.
|
|
118
|
+
*
|
|
119
|
+
* Performs no type guarding.
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
*
|
|
123
|
+
* ```ts
|
|
124
|
+
* import {assert} from '@augment-vir/assert';
|
|
125
|
+
*
|
|
126
|
+
* assert.startsWith('ab', 'b'); // fails
|
|
127
|
+
* assert.startsWith('ab', 'a'); // passes
|
|
128
|
+
* assert.startsWith(['a', 'b'], 'b'); // fails
|
|
129
|
+
* assert.startsWith(['a', 'b'], 'a'); // passes
|
|
130
|
+
* ```
|
|
131
|
+
*
|
|
132
|
+
* @throws {@link AssertionError} If the parent does not start with the child.
|
|
133
|
+
* @see
|
|
134
|
+
* - {@link assert.startsWithout} : the opposite assertion.
|
|
135
|
+
* - {@link assert.endsWith} : assertion on the other end.
|
|
136
|
+
*/
|
|
75
137
|
startsWith,
|
|
138
|
+
/**
|
|
139
|
+
* Asserts that a parent string or array starts with a specific child. This uses reference
|
|
140
|
+
* equality when the parent is an array.
|
|
141
|
+
*
|
|
142
|
+
* Performs no type guarding.
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
*
|
|
146
|
+
* ```ts
|
|
147
|
+
* import {assert} from '@augment-vir/assert';
|
|
148
|
+
*
|
|
149
|
+
* assert.startsWith('ab', 'b'); // passes
|
|
150
|
+
* assert.startsWith('ab', 'a'); // fails
|
|
151
|
+
* assert.startsWith(['a', 'b'], 'b'); // passes
|
|
152
|
+
* assert.startsWith(['a', 'b'], 'a'); // fails
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @throws {@link AssertionError} If the parent does start with the child.
|
|
156
|
+
* @see
|
|
157
|
+
* - {@link assert.startsWithout} : the opposite assertion.
|
|
158
|
+
* - {@link assert.endsWith} : assertion on the other end.
|
|
159
|
+
*/
|
|
76
160
|
startsWithout,
|
|
77
161
|
};
|
|
78
162
|
export const boundaryGuards = {
|
|
@@ -91,27 +175,20 @@ export const boundaryGuards = {
|
|
|
91
175
|
*
|
|
92
176
|
* check.endsWith('ab', 'b'); // returns `true`
|
|
93
177
|
* check.endsWith('ab', 'a'); // returns `false`
|
|
94
|
-
* check.endsWith(
|
|
95
|
-
*
|
|
96
|
-
* 'a',
|
|
97
|
-
* 'b',
|
|
98
|
-
* ],
|
|
99
|
-
* 'b',
|
|
100
|
-
* ); // returns `true`
|
|
101
|
-
* check.endsWith(
|
|
102
|
-
* [
|
|
103
|
-
* 'a',
|
|
104
|
-
* 'b',
|
|
105
|
-
* ],
|
|
106
|
-
* 'a',
|
|
107
|
-
* ); // returns `false`
|
|
178
|
+
* check.endsWith(['a', 'b'], 'b'); // returns `true`
|
|
179
|
+
* check.endsWith(['a', 'b'], 'a'); // returns `false`
|
|
108
180
|
* ```
|
|
109
181
|
*
|
|
110
182
|
* @see
|
|
111
183
|
* - {@link check.endsWithout} : the opposite check.
|
|
112
184
|
* - {@link check.startsWith} : check on the other end.
|
|
113
185
|
*/
|
|
114
|
-
endsWith:
|
|
186
|
+
endsWith: ((parent, child) => {
|
|
187
|
+
if (typeof parent === 'string') {
|
|
188
|
+
return parent.endsWith(child);
|
|
189
|
+
}
|
|
190
|
+
return parent[parent.length - 1] === child;
|
|
191
|
+
}),
|
|
115
192
|
/**
|
|
116
193
|
* Checks that a parent string or array does _not_ end with a specific child. This uses
|
|
117
194
|
* reference equality when the parent is an array.
|
|
@@ -125,27 +202,20 @@ export const boundaryGuards = {
|
|
|
125
202
|
*
|
|
126
203
|
* check.endsWithout('ab', 'b'); // returns `false`
|
|
127
204
|
* check.endsWithout('ab', 'a'); // returns `true`
|
|
128
|
-
* check.endsWithout(
|
|
129
|
-
*
|
|
130
|
-
* 'a',
|
|
131
|
-
* 'b',
|
|
132
|
-
* ],
|
|
133
|
-
* 'b',
|
|
134
|
-
* ); // returns `false`
|
|
135
|
-
* check.endsWithout(
|
|
136
|
-
* [
|
|
137
|
-
* 'a',
|
|
138
|
-
* 'b',
|
|
139
|
-
* ],
|
|
140
|
-
* 'a',
|
|
141
|
-
* ); // returns `true`
|
|
205
|
+
* check.endsWithout(['a', 'b'], 'b'); // returns `false`
|
|
206
|
+
* check.endsWithout(['a', 'b'], 'a'); // returns `true`
|
|
142
207
|
* ```
|
|
143
208
|
*
|
|
144
209
|
* @see
|
|
145
210
|
* - {@link check.endsWith} : the opposite check.
|
|
146
211
|
* - {@link check.startsWithout} : check on the other end.
|
|
147
212
|
*/
|
|
148
|
-
endsWithout:
|
|
213
|
+
endsWithout: ((parent, child) => {
|
|
214
|
+
if (typeof parent === 'string') {
|
|
215
|
+
return !parent.endsWith(child);
|
|
216
|
+
}
|
|
217
|
+
return parent[parent.length - 1] !== child;
|
|
218
|
+
}),
|
|
149
219
|
/**
|
|
150
220
|
* Checks that a parent string or array starts with a specific child. This uses reference
|
|
151
221
|
* equality when the parent is an array.
|
|
@@ -159,27 +229,20 @@ export const boundaryGuards = {
|
|
|
159
229
|
*
|
|
160
230
|
* check.startsWith('ab', 'b'); // returns `false`
|
|
161
231
|
* check.startsWith('ab', 'a'); // returns `true`
|
|
162
|
-
* check.startsWith(
|
|
163
|
-
*
|
|
164
|
-
* 'a',
|
|
165
|
-
* 'b',
|
|
166
|
-
* ],
|
|
167
|
-
* 'b',
|
|
168
|
-
* ); // returns `false`
|
|
169
|
-
* check.startsWith(
|
|
170
|
-
* [
|
|
171
|
-
* 'a',
|
|
172
|
-
* 'b',
|
|
173
|
-
* ],
|
|
174
|
-
* 'a',
|
|
175
|
-
* ); // returns `true`
|
|
232
|
+
* check.startsWith(['a', 'b'], 'b'); // returns `false`
|
|
233
|
+
* check.startsWith(['a', 'b'], 'a'); // returns `true`
|
|
176
234
|
* ```
|
|
177
235
|
*
|
|
178
236
|
* @see
|
|
179
237
|
* - {@link check.startsWithout} : the opposite check.
|
|
180
238
|
* - {@link check.endsWith} : check on the other end.
|
|
181
239
|
*/
|
|
182
|
-
startsWith:
|
|
240
|
+
startsWith: ((parent, child) => {
|
|
241
|
+
if (typeof parent === 'string') {
|
|
242
|
+
return parent.startsWith(child);
|
|
243
|
+
}
|
|
244
|
+
return parent[0] === child;
|
|
245
|
+
}),
|
|
183
246
|
/**
|
|
184
247
|
* Checks that a parent string or array starts with a specific child. This uses reference
|
|
185
248
|
* equality when the parent is an array.
|
|
@@ -193,27 +256,20 @@ export const boundaryGuards = {
|
|
|
193
256
|
*
|
|
194
257
|
* check.startsWith('ab', 'b'); // returns `false`
|
|
195
258
|
* check.startsWith('ab', 'a'); // returns `true`
|
|
196
|
-
* check.startsWith(
|
|
197
|
-
*
|
|
198
|
-
* 'a',
|
|
199
|
-
* 'b',
|
|
200
|
-
* ],
|
|
201
|
-
* 'b',
|
|
202
|
-
* ); // returns `false`
|
|
203
|
-
* check.startsWith(
|
|
204
|
-
* [
|
|
205
|
-
* 'a',
|
|
206
|
-
* 'b',
|
|
207
|
-
* ],
|
|
208
|
-
* 'a',
|
|
209
|
-
* ); // returns `true`
|
|
259
|
+
* check.startsWith(['a', 'b'], 'b'); // returns `false`
|
|
260
|
+
* check.startsWith(['a', 'b'], 'a'); // returns `true`
|
|
210
261
|
* ```
|
|
211
262
|
*
|
|
212
263
|
* @see
|
|
213
264
|
* - {@link check.startsWithout} : the opposite check.
|
|
214
265
|
* - {@link check.endsWith} : check on the other end.
|
|
215
266
|
*/
|
|
216
|
-
startsWithout:
|
|
267
|
+
startsWithout: ((parent, child) => {
|
|
268
|
+
if (typeof parent === 'string') {
|
|
269
|
+
return !parent.startsWith(child);
|
|
270
|
+
}
|
|
271
|
+
return parent[0] !== child;
|
|
272
|
+
}),
|
|
217
273
|
},
|
|
218
274
|
assertWrap: {
|
|
219
275
|
/**
|
|
@@ -229,20 +285,8 @@ export const boundaryGuards = {
|
|
|
229
285
|
*
|
|
230
286
|
* assertWrap.endsWith('ab', 'b'); // returns `'ab'`
|
|
231
287
|
* assertWrap.endsWith('ab', 'a'); // throws an error
|
|
232
|
-
* assertWrap.endsWith(
|
|
233
|
-
*
|
|
234
|
-
* 'a',
|
|
235
|
-
* 'b',
|
|
236
|
-
* ],
|
|
237
|
-
* 'b',
|
|
238
|
-
* ); // returns `['a', 'b']`
|
|
239
|
-
* assertWrap.endsWith(
|
|
240
|
-
* [
|
|
241
|
-
* 'a',
|
|
242
|
-
* 'b',
|
|
243
|
-
* ],
|
|
244
|
-
* 'a',
|
|
245
|
-
* ); // throws an error
|
|
288
|
+
* assertWrap.endsWith(['a', 'b'], 'b'); // returns `['a', 'b']`
|
|
289
|
+
* assertWrap.endsWith(['a', 'b'], 'a'); // throws an error
|
|
246
290
|
* ```
|
|
247
291
|
*
|
|
248
292
|
* @returns The parent value if it does end with the child.
|
|
@@ -251,7 +295,17 @@ export const boundaryGuards = {
|
|
|
251
295
|
* - {@link assertWrap.endsWithout} : the opposite assertion.
|
|
252
296
|
* - {@link assertWrap.startsWith} : assertion on the other end.
|
|
253
297
|
*/
|
|
254
|
-
endsWith:
|
|
298
|
+
endsWith: ((parent, child, failureMessage) => {
|
|
299
|
+
if (typeof parent === 'string') {
|
|
300
|
+
if (!parent.endsWith(child)) {
|
|
301
|
+
throw new AssertionError(`${stringify(parent)} does not end with ${stringify(child)}}`, failureMessage);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
else if (parent[parent.length - 1] !== child) {
|
|
305
|
+
throw new AssertionError(`${stringify(parent)} does not end with ${stringify(child)}}`, failureMessage);
|
|
306
|
+
}
|
|
307
|
+
return parent;
|
|
308
|
+
}),
|
|
255
309
|
/**
|
|
256
310
|
* Asserts that a parent string or array does _not_ end with a specific child. This uses
|
|
257
311
|
* reference equality when the parent is an array. Returns the parent if the assertion
|
|
@@ -266,20 +320,8 @@ export const boundaryGuards = {
|
|
|
266
320
|
*
|
|
267
321
|
* assertWrap.endsWithout('ab', 'b'); // throws an error
|
|
268
322
|
* assertWrap.endsWithout('ab', 'a'); // returns `'ab'`
|
|
269
|
-
* assertWrap.endsWithout(
|
|
270
|
-
*
|
|
271
|
-
* 'a',
|
|
272
|
-
* 'b',
|
|
273
|
-
* ],
|
|
274
|
-
* 'b',
|
|
275
|
-
* ); // throws an error
|
|
276
|
-
* assertWrap.endsWithout(
|
|
277
|
-
* [
|
|
278
|
-
* 'a',
|
|
279
|
-
* 'b',
|
|
280
|
-
* ],
|
|
281
|
-
* 'a',
|
|
282
|
-
* ); // returns `['a', 'b']`
|
|
323
|
+
* assertWrap.endsWithout(['a', 'b'], 'b'); // throws an error
|
|
324
|
+
* assertWrap.endsWithout(['a', 'b'], 'a'); // returns `['a', 'b']`
|
|
283
325
|
* ```
|
|
284
326
|
*
|
|
285
327
|
* @returns The parent value if it does not end with the child.
|
|
@@ -288,7 +330,17 @@ export const boundaryGuards = {
|
|
|
288
330
|
* - {@link assertWrap.endsWith} : the opposite assertion.
|
|
289
331
|
* - {@link assertWrap.startsWithout} : assertion on the other end.
|
|
290
332
|
*/
|
|
291
|
-
endsWithout:
|
|
333
|
+
endsWithout: ((parent, child, failureMessage) => {
|
|
334
|
+
if (typeof parent === 'string') {
|
|
335
|
+
if (parent.endsWith(child)) {
|
|
336
|
+
throw new AssertionError(`${stringify(parent)} ends with ${stringify(child)}}`, failureMessage);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
else if (parent[parent.length - 1] === child) {
|
|
340
|
+
throw new AssertionError(`${stringify(parent)} ends with ${stringify(child)}}`, failureMessage);
|
|
341
|
+
}
|
|
342
|
+
return parent;
|
|
343
|
+
}),
|
|
292
344
|
/**
|
|
293
345
|
* Checks that a parent string or array starts with a specific child. This uses reference
|
|
294
346
|
* equality when the parent is an array. Returns the parent if the assertion passes.
|
|
@@ -302,20 +354,8 @@ export const boundaryGuards = {
|
|
|
302
354
|
*
|
|
303
355
|
* assertWrap.startsWith('ab', 'b'); // throws an error
|
|
304
356
|
* assertWrap.startsWith('ab', 'a'); // returns `'ab'`
|
|
305
|
-
* assertWrap.startsWith(
|
|
306
|
-
*
|
|
307
|
-
* 'a',
|
|
308
|
-
* 'b',
|
|
309
|
-
* ],
|
|
310
|
-
* 'b',
|
|
311
|
-
* ); // throws an error
|
|
312
|
-
* assertWrap.startsWith(
|
|
313
|
-
* [
|
|
314
|
-
* 'a',
|
|
315
|
-
* 'b',
|
|
316
|
-
* ],
|
|
317
|
-
* 'a',
|
|
318
|
-
* ); // returns `['a', 'b']`
|
|
357
|
+
* assertWrap.startsWith(['a', 'b'], 'b'); // throws an error
|
|
358
|
+
* assertWrap.startsWith(['a', 'b'], 'a'); // returns `['a', 'b']`
|
|
319
359
|
* ```
|
|
320
360
|
*
|
|
321
361
|
* @returns The parent value if it starts with the child.
|
|
@@ -324,7 +364,17 @@ export const boundaryGuards = {
|
|
|
324
364
|
* - {@link assertWrap.startsWithout} : the opposite assertion.
|
|
325
365
|
* - {@link assertWrap.endsWith} : assertion on the other end.
|
|
326
366
|
*/
|
|
327
|
-
startsWith:
|
|
367
|
+
startsWith: ((parent, child, failureMessage) => {
|
|
368
|
+
if (typeof parent === 'string') {
|
|
369
|
+
if (!parent.startsWith(child)) {
|
|
370
|
+
throw new AssertionError(`${stringify(parent)} does not start with ${stringify(child)}}`, failureMessage);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
else if (parent[0] !== child) {
|
|
374
|
+
throw new AssertionError(`${stringify(parent)} does not start with ${stringify(child)}}`, failureMessage);
|
|
375
|
+
}
|
|
376
|
+
return parent;
|
|
377
|
+
}),
|
|
328
378
|
/**
|
|
329
379
|
* Asserts that a parent string or array starts with a specific child. This uses reference
|
|
330
380
|
* equality when the parent is an array. Returns the parent if the assertion passes.
|
|
@@ -338,20 +388,8 @@ export const boundaryGuards = {
|
|
|
338
388
|
*
|
|
339
389
|
* assertWrap.startsWith('ab', 'b'); // returns `'ab'`
|
|
340
390
|
* assertWrap.startsWith('ab', 'a'); // throws an error
|
|
341
|
-
* assertWrap.startsWith(
|
|
342
|
-
*
|
|
343
|
-
* 'a',
|
|
344
|
-
* 'b',
|
|
345
|
-
* ],
|
|
346
|
-
* 'b',
|
|
347
|
-
* ); // returns `['a', 'b']`
|
|
348
|
-
* assertWrap.startsWith(
|
|
349
|
-
* [
|
|
350
|
-
* 'a',
|
|
351
|
-
* 'b',
|
|
352
|
-
* ],
|
|
353
|
-
* 'a',
|
|
354
|
-
* ); // throws an error
|
|
391
|
+
* assertWrap.startsWith(['a', 'b'], 'b'); // returns `['a', 'b']`
|
|
392
|
+
* assertWrap.startsWith(['a', 'b'], 'a'); // throws an error
|
|
355
393
|
* ```
|
|
356
394
|
*
|
|
357
395
|
* @returns The parent value if it does not start with the child.
|
|
@@ -360,7 +398,17 @@ export const boundaryGuards = {
|
|
|
360
398
|
* - {@link assertWrap.startsWithout} : the opposite assertion.
|
|
361
399
|
* - {@link assertWrap.endsWith} : assertion on the other end.
|
|
362
400
|
*/
|
|
363
|
-
startsWithout:
|
|
401
|
+
startsWithout: ((parent, child, failureMessage) => {
|
|
402
|
+
if (typeof parent === 'string') {
|
|
403
|
+
if (parent.startsWith(child)) {
|
|
404
|
+
throw new AssertionError(`${stringify(parent)} starts with ${stringify(child)}}`, failureMessage);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
else if (parent[0] === child) {
|
|
408
|
+
throw new AssertionError(`${stringify(parent)} starts with ${stringify(child)}}`, failureMessage);
|
|
409
|
+
}
|
|
410
|
+
return parent;
|
|
411
|
+
}),
|
|
364
412
|
},
|
|
365
413
|
checkWrap: {
|
|
366
414
|
/**
|
|
@@ -377,20 +425,8 @@ export const boundaryGuards = {
|
|
|
377
425
|
*
|
|
378
426
|
* checkWrap.endsWith('ab', 'b'); // returns `'ab'`
|
|
379
427
|
* checkWrap.endsWith('ab', 'a'); // returns `undefined`
|
|
380
|
-
* checkWrap.endsWith(
|
|
381
|
-
*
|
|
382
|
-
* 'a',
|
|
383
|
-
* 'b',
|
|
384
|
-
* ],
|
|
385
|
-
* 'b',
|
|
386
|
-
* ); // returns `['a', 'b']`
|
|
387
|
-
* checkWrap.endsWith(
|
|
388
|
-
* [
|
|
389
|
-
* 'a',
|
|
390
|
-
* 'b',
|
|
391
|
-
* ],
|
|
392
|
-
* 'a',
|
|
393
|
-
* ); // returns `undefined`
|
|
428
|
+
* checkWrap.endsWith(['a', 'b'], 'b'); // returns `['a', 'b']`
|
|
429
|
+
* checkWrap.endsWith(['a', 'b'], 'a'); // returns `undefined`
|
|
394
430
|
* ```
|
|
395
431
|
*
|
|
396
432
|
* @returns The first value if the check passes, otherwise `undefined`.
|
|
@@ -398,7 +434,22 @@ export const boundaryGuards = {
|
|
|
398
434
|
* - {@link checkWrap.endsWithout} : the opposite check.
|
|
399
435
|
* - {@link checkWrap.startsWith} : check on the other end.
|
|
400
436
|
*/
|
|
401
|
-
endsWith:
|
|
437
|
+
endsWith: ((parent, child) => {
|
|
438
|
+
if (typeof parent === 'string') {
|
|
439
|
+
if (parent.endsWith(child)) {
|
|
440
|
+
return parent;
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
return undefined;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (parent[parent.length - 1] === child) {
|
|
447
|
+
return parent;
|
|
448
|
+
}
|
|
449
|
+
else {
|
|
450
|
+
return undefined;
|
|
451
|
+
}
|
|
452
|
+
}),
|
|
402
453
|
/**
|
|
403
454
|
* Checks that a parent string or array does _not_ end with a specific child. This uses
|
|
404
455
|
* reference equality when the parent is an array. Returns the value if the check passes,
|
|
@@ -413,20 +464,8 @@ export const boundaryGuards = {
|
|
|
413
464
|
*
|
|
414
465
|
* checkWrap.endsWithout('ab', 'b'); // returns `undefined`
|
|
415
466
|
* checkWrap.endsWithout('ab', 'a'); // returns `'ab'`
|
|
416
|
-
* checkWrap.endsWithout(
|
|
417
|
-
*
|
|
418
|
-
* 'a',
|
|
419
|
-
* 'b',
|
|
420
|
-
* ],
|
|
421
|
-
* 'b',
|
|
422
|
-
* ); // returns `undefined`
|
|
423
|
-
* checkWrap.endsWithout(
|
|
424
|
-
* [
|
|
425
|
-
* 'a',
|
|
426
|
-
* 'b',
|
|
427
|
-
* ],
|
|
428
|
-
* 'a',
|
|
429
|
-
* ); // returns `['a', 'b']`
|
|
467
|
+
* checkWrap.endsWithout(['a', 'b'], 'b'); // returns `undefined`
|
|
468
|
+
* checkWrap.endsWithout(['a', 'b'], 'a'); // returns `['a', 'b']`
|
|
430
469
|
* ```
|
|
431
470
|
*
|
|
432
471
|
* @returns The first value if the check passes, otherwise `undefined`.
|
|
@@ -434,7 +473,22 @@ export const boundaryGuards = {
|
|
|
434
473
|
* - {@link checkWrap.endsWith} : the opposite check.
|
|
435
474
|
* - {@link checkWrap.startsWithout} : check on the other end.
|
|
436
475
|
*/
|
|
437
|
-
endsWithout:
|
|
476
|
+
endsWithout: ((parent, child) => {
|
|
477
|
+
if (typeof parent === 'string') {
|
|
478
|
+
if (parent.endsWith(child)) {
|
|
479
|
+
return undefined;
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
return parent;
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
if (parent[parent.length - 1] === child) {
|
|
486
|
+
return undefined;
|
|
487
|
+
}
|
|
488
|
+
else {
|
|
489
|
+
return parent;
|
|
490
|
+
}
|
|
491
|
+
}),
|
|
438
492
|
/**
|
|
439
493
|
* Checks that a parent string or array starts with a specific child. This uses reference
|
|
440
494
|
* equality when the parent is an array. Returns the value if the check passes, otherwise
|
|
@@ -449,20 +503,8 @@ export const boundaryGuards = {
|
|
|
449
503
|
*
|
|
450
504
|
* checkWrap.startsWith('ab', 'b'); // returns `undefined`
|
|
451
505
|
* checkWrap.startsWith('ab', 'a'); // returns `'ab'`
|
|
452
|
-
* checkWrap.startsWith(
|
|
453
|
-
*
|
|
454
|
-
* 'a',
|
|
455
|
-
* 'b',
|
|
456
|
-
* ],
|
|
457
|
-
* 'b',
|
|
458
|
-
* ); // returns `undefined`
|
|
459
|
-
* checkWrap.startsWith(
|
|
460
|
-
* [
|
|
461
|
-
* 'a',
|
|
462
|
-
* 'b',
|
|
463
|
-
* ],
|
|
464
|
-
* 'a',
|
|
465
|
-
* ); // returns `['a', 'b']`
|
|
506
|
+
* checkWrap.startsWith(['a', 'b'], 'b'); // returns `undefined`
|
|
507
|
+
* checkWrap.startsWith(['a', 'b'], 'a'); // returns `['a', 'b']`
|
|
466
508
|
* ```
|
|
467
509
|
*
|
|
468
510
|
* @returns The first value if the check passes, otherwise `undefined`.
|
|
@@ -470,7 +512,22 @@ export const boundaryGuards = {
|
|
|
470
512
|
* - {@link checkWrap.startsWithout} : the opposite check.
|
|
471
513
|
* - {@link checkWrap.endsWith} : check on the other end.
|
|
472
514
|
*/
|
|
473
|
-
startsWith:
|
|
515
|
+
startsWith: ((parent, child) => {
|
|
516
|
+
if (typeof parent === 'string') {
|
|
517
|
+
if (parent.startsWith(child)) {
|
|
518
|
+
return parent;
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
return undefined;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
if (parent[0] === child) {
|
|
525
|
+
return parent;
|
|
526
|
+
}
|
|
527
|
+
else {
|
|
528
|
+
return undefined;
|
|
529
|
+
}
|
|
530
|
+
}),
|
|
474
531
|
/**
|
|
475
532
|
* Checks that a parent string or array starts with a specific child. This uses reference
|
|
476
533
|
* equality when the parent is an array. Returns the value if the check passes, otherwise
|
|
@@ -485,20 +542,8 @@ export const boundaryGuards = {
|
|
|
485
542
|
*
|
|
486
543
|
* checkWrap.startsWith('ab', 'b'); // returns `undefined`
|
|
487
544
|
* checkWrap.startsWith('ab', 'a'); // returns `'ab'`
|
|
488
|
-
* checkWrap.startsWith(
|
|
489
|
-
*
|
|
490
|
-
* 'a',
|
|
491
|
-
* 'b',
|
|
492
|
-
* ],
|
|
493
|
-
* 'b',
|
|
494
|
-
* ); // returns `undefined`
|
|
495
|
-
* checkWrap.startsWith(
|
|
496
|
-
* [
|
|
497
|
-
* 'a',
|
|
498
|
-
* 'b',
|
|
499
|
-
* ],
|
|
500
|
-
* 'a',
|
|
501
|
-
* ); // returns `['a', 'b']`
|
|
545
|
+
* checkWrap.startsWith(['a', 'b'], 'b'); // returns `undefined`
|
|
546
|
+
* checkWrap.startsWith(['a', 'b'], 'a'); // returns `['a', 'b']`
|
|
502
547
|
* ```
|
|
503
548
|
*
|
|
504
549
|
* @returns The first value if the check passes, otherwise `undefined`.
|
|
@@ -506,7 +551,22 @@ export const boundaryGuards = {
|
|
|
506
551
|
* - {@link checkWrap.startsWithout} : the opposite check.
|
|
507
552
|
* - {@link checkWrap.endsWith} : check on the other end.
|
|
508
553
|
*/
|
|
509
|
-
startsWithout:
|
|
554
|
+
startsWithout: ((parent, child) => {
|
|
555
|
+
if (typeof parent === 'string') {
|
|
556
|
+
if (parent.startsWith(child)) {
|
|
557
|
+
return undefined;
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
return parent;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
if (parent[0] === child) {
|
|
564
|
+
return undefined;
|
|
565
|
+
}
|
|
566
|
+
else {
|
|
567
|
+
return parent;
|
|
568
|
+
}
|
|
569
|
+
}),
|
|
510
570
|
},
|
|
511
571
|
waitUntil: {
|
|
512
572
|
/**
|
|
@@ -523,14 +583,8 @@ export const boundaryGuards = {
|
|
|
523
583
|
*
|
|
524
584
|
* await waitUntil.endsWith('b', () => 'ab'); // returns `'ab'`
|
|
525
585
|
* await waitUntil.endsWith('a', () => 'ab'); // throws an error
|
|
526
|
-
* await waitUntil.endsWith('b', () => [
|
|
527
|
-
*
|
|
528
|
-
* 'b',
|
|
529
|
-
* ]); // returns `['a', 'b']`
|
|
530
|
-
* await waitUntil.endsWith('a', () => [
|
|
531
|
-
* 'a',
|
|
532
|
-
* 'b',
|
|
533
|
-
* ]); // throws an error
|
|
586
|
+
* await waitUntil.endsWith('b', () => ['a', 'b']); // returns `['a', 'b']`
|
|
587
|
+
* await waitUntil.endsWith('a', () => ['a', 'b']); // throws an error
|
|
534
588
|
* ```
|
|
535
589
|
*
|
|
536
590
|
* @returns The callback output once it passes.
|
|
@@ -539,7 +593,7 @@ export const boundaryGuards = {
|
|
|
539
593
|
* - {@link waitUntil.endsWithout} : the opposite assertion.
|
|
540
594
|
* - {@link waitUntil.startsWith} : assertion on the other end.
|
|
541
595
|
*/
|
|
542
|
-
endsWith:
|
|
596
|
+
endsWith: createWaitUntil(assertions.endsWith),
|
|
543
597
|
/**
|
|
544
598
|
* Repeatedly calls a callback until its output string or array does not end with the first
|
|
545
599
|
* input child value. This uses reference equality when the parent is an array. Once the
|
|
@@ -554,14 +608,8 @@ export const boundaryGuards = {
|
|
|
554
608
|
*
|
|
555
609
|
* await waitUntil.endsWith('b', () => 'ab'); // throws an error
|
|
556
610
|
* await waitUntil.endsWith('a', () => 'ab'); // returns `'ab'`
|
|
557
|
-
* await waitUntil.endsWith('b', () => [
|
|
558
|
-
*
|
|
559
|
-
* 'b',
|
|
560
|
-
* ]); // throws an error
|
|
561
|
-
* await waitUntil.endsWith('a', () => [
|
|
562
|
-
* 'a',
|
|
563
|
-
* 'b',
|
|
564
|
-
* ]); // returns `['a', 'b']`
|
|
611
|
+
* await waitUntil.endsWith('b', () => ['a', 'b']); // throws an error
|
|
612
|
+
* await waitUntil.endsWith('a', () => ['a', 'b']); // returns `['a', 'b']`
|
|
565
613
|
* ```
|
|
566
614
|
*
|
|
567
615
|
* @returns The callback output once it passes.
|
|
@@ -570,7 +618,7 @@ export const boundaryGuards = {
|
|
|
570
618
|
* - {@link waitUntil.endsWith} : the opposite assertion.
|
|
571
619
|
* - {@link waitUntil.startsWithout} : assertion on the other end.
|
|
572
620
|
*/
|
|
573
|
-
endsWithout:
|
|
621
|
+
endsWithout: createWaitUntil(assertions.endsWithout),
|
|
574
622
|
/**
|
|
575
623
|
* Repeatedly calls a callback until its output string or array starts with the first input
|
|
576
624
|
* child value. This uses reference equality when the parent is an array. Once the callback
|
|
@@ -585,14 +633,8 @@ export const boundaryGuards = {
|
|
|
585
633
|
*
|
|
586
634
|
* await waitUntil.endsWith('b', () => 'ab'); // throws an error
|
|
587
635
|
* await waitUntil.endsWith('a', () => 'ab'); // returns `'ab'`
|
|
588
|
-
* await waitUntil.endsWith('b', () => [
|
|
589
|
-
*
|
|
590
|
-
* 'b',
|
|
591
|
-
* ]); // throws an error
|
|
592
|
-
* await waitUntil.endsWith('a', () => [
|
|
593
|
-
* 'a',
|
|
594
|
-
* 'b',
|
|
595
|
-
* ]); // returns `['a', 'b']`
|
|
636
|
+
* await waitUntil.endsWith('b', () => ['a', 'b']); // throws an error
|
|
637
|
+
* await waitUntil.endsWith('a', () => ['a', 'b']); // returns `['a', 'b']`
|
|
596
638
|
* ```
|
|
597
639
|
*
|
|
598
640
|
* @returns The callback output once it passes.
|
|
@@ -601,7 +643,7 @@ export const boundaryGuards = {
|
|
|
601
643
|
* - {@link waitUntil.startsWithout} : the opposite assertion.
|
|
602
644
|
* - {@link waitUntil.endsWith} : assertion on the other end.
|
|
603
645
|
*/
|
|
604
|
-
startsWith:
|
|
646
|
+
startsWith: createWaitUntil(assertions.startsWith),
|
|
605
647
|
/**
|
|
606
648
|
* Repeatedly calls a callback until its output string or array does not start with the
|
|
607
649
|
* first input child value. This uses reference equality when the parent is an array. Once
|
|
@@ -615,14 +657,8 @@ export const boundaryGuards = {
|
|
|
615
657
|
* ```ts
|
|
616
658
|
* await waitUntil.endsWith('b', () => 'ab'); // returns `'ab'`
|
|
617
659
|
* await waitUntil.endsWith('a', () => 'ab'); // throws an error
|
|
618
|
-
* await waitUntil.endsWith('b', () => [
|
|
619
|
-
*
|
|
620
|
-
* 'b',
|
|
621
|
-
* ]); // returns `['a', 'b']`
|
|
622
|
-
* await waitUntil.endsWith('a', () => [
|
|
623
|
-
* 'a',
|
|
624
|
-
* 'b',
|
|
625
|
-
* ]); // throws an error
|
|
660
|
+
* await waitUntil.endsWith('b', () => ['a', 'b']); // returns `['a', 'b']`
|
|
661
|
+
* await waitUntil.endsWith('a', () => ['a', 'b']); // throws an error
|
|
626
662
|
* ```
|
|
627
663
|
*
|
|
628
664
|
* @returns The callback output once it passes.
|
|
@@ -631,6 +667,6 @@ export const boundaryGuards = {
|
|
|
631
667
|
* - {@link waitUntil.startsWith} : the opposite assertion.
|
|
632
668
|
* - {@link waitUntil.endsWithout} : assertion on the other end.
|
|
633
669
|
*/
|
|
634
|
-
startsWithout:
|
|
670
|
+
startsWithout: createWaitUntil(assertions.startsWithout),
|
|
635
671
|
},
|
|
636
672
|
};
|