1
+ /* eslint-disable @typescript-eslint/no-namespace */
1
2
export type EqualityOptions = {
2
3
strict : boolean ;
3
4
}
@@ -60,16 +61,12 @@ class BellatrixAssertionError extends Error {
60
61
}
61
62
}
62
63
63
- export class Assert {
64
- private constructor ( ) {
65
- throw new Error ( 'PluginExecutionEngine is static and cannot be instantiated' ) ;
66
- }
67
-
68
- static areEqual ( expected : unknown , actual : unknown , message ?: string ) : void
69
- static areEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
70
- static areEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
64
+ export namespace Assert {
65
+ export function areEqual ( expected : unknown , actual : unknown , message ?: string ) : void
66
+ export function areEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
67
+ export function areEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
71
68
if ( typeof options === 'string' ) {
72
- return this . areEqual ( expected , actual , undefined , options ) ;
69
+ return areEqual ( expected , actual , undefined , options ) ;
73
70
}
74
71
75
72
options ??= { strict : false } ;
@@ -83,11 +80,11 @@ export class Assert {
83
80
}
84
81
}
85
82
86
- static areDeepEqual ( expected : unknown , actual : unknown , message ?: string ) : void
87
- static areDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
88
- static areDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
83
+ export function areDeepEqual ( expected : unknown , actual : unknown , message ?: string ) : void
84
+ export function areDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
85
+ export function areDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
89
86
if ( typeof options === 'string' ) {
90
- return this . areDeepEqual ( expected , actual , undefined , options ) ;
87
+ return areDeepEqual ( expected , actual , undefined , options ) ;
91
88
}
92
89
93
90
options ??= { strict : false } ;
@@ -97,11 +94,11 @@ export class Assert {
97
94
}
98
95
}
99
96
100
- static areApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , message ?: string ) : void
101
- static areApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions , message ?: string ) : void
102
- static areApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions | string , message ?: string ) {
97
+ export function areApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , message ?: string ) : void
98
+ export function areApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions , message ?: string ) : void
99
+ export function areApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions | string , message ?: string ) {
103
100
if ( typeof options === 'string' ) {
104
- return this . areApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
101
+ return areApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
105
102
}
106
103
107
104
options ??= { method : 'round' } ;
@@ -114,11 +111,11 @@ export class Assert {
114
111
}
115
112
}
116
113
117
- static areNotEqual ( expected : unknown , actual : unknown , message ?: string ) : void
118
- static areNotEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
119
- static areNotEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
114
+ export function areNotEqual ( expected : unknown , actual : unknown , message ?: string ) : void
115
+ export function areNotEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
116
+ export function areNotEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
120
117
if ( typeof options === 'string' ) {
121
- return this . areNotEqual ( expected , actual , undefined , options ) ;
118
+ return areNotEqual ( expected , actual , undefined , options ) ;
122
119
}
123
120
124
121
options ??= { strict : false } ;
@@ -134,11 +131,11 @@ export class Assert {
134
131
}
135
132
}
136
133
137
- static areNotDeepEqual ( expected : unknown , actual : unknown , message ?: string ) : void
138
- static areNotDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
139
- static areNotDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
134
+ export function areNotDeepEqual ( expected : unknown , actual : unknown , message ?: string ) : void
135
+ export function areNotDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions , message ?: string ) : void
136
+ export function areNotDeepEqual ( expected : unknown , actual : unknown , options ?: EqualityOptions | string , message ?: string ) {
140
137
if ( typeof options === 'string' ) {
141
- return this . areNotDeepEqual ( expected , actual , undefined , options ) ;
138
+ return areNotDeepEqual ( expected , actual , undefined , options ) ;
142
139
}
143
140
144
141
options ??= { strict : false } ;
@@ -148,11 +145,11 @@ export class Assert {
148
145
}
149
146
}
150
147
151
- static areNotApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , message ?: string ) : void
152
- static areNotApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions , message ?: string ) : void
153
- static areNotApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions | string , message ?: string ) {
148
+ export function areNotApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , message ?: string ) : void
149
+ export function areNotApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions , message ?: string ) : void
150
+ export function areNotApproximatelyEqual ( expected : number , actual : number , decimalPlaces : number , options ?: ApproximateEqualityOptions | string , message ?: string ) {
154
151
if ( typeof options === 'string' ) {
155
- return this . areNotApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
152
+ return areNotApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
156
153
}
157
154
158
155
options ??= { method : 'round' } ;
@@ -165,112 +162,112 @@ export class Assert {
165
162
}
166
163
}
167
164
168
- static isFalse ( value : boolean , message ?: string ) {
165
+ export function isFalse ( value : boolean , message ?: string ) {
169
166
const result = value === false ;
170
167
if ( result === false ) {
171
168
throw new BellatrixAssertionError ( 'false' , String ( value ) , message ) ;
172
169
}
173
170
}
174
171
175
- static isFalsy ( value : unknown , message ?: string ) {
172
+ export function isFalsy ( value : unknown , message ?: string ) {
176
173
const result = value == false ;
177
174
if ( result === false ) {
178
175
throw new BellatrixAssertionError ( 'falsy' , quoteString ( value ) , message ) ;
179
176
}
180
177
}
181
178
182
- static isTrue ( value : boolean , message ?: string ) {
179
+ export function isTrue ( value : boolean , message ?: string ) {
183
180
const result = value === true ;
184
181
if ( result === false ) {
185
182
throw new BellatrixAssertionError ( 'true' , String ( value ) , message ) ;
186
183
}
187
184
}
188
185
189
- static isTruthy ( value : unknown , message ?: string ) {
186
+ export function isTruthy ( value : unknown , message ?: string ) {
190
187
const result = value == true ;
191
188
if ( result === false ) {
192
189
throw new BellatrixAssertionError ( 'truthy' , quoteString ( value ) , message ) ;
193
190
}
194
191
}
195
192
196
- static isNaN ( value : unknown , message ?: string ) : void
197
- static isNaN ( value : unknown , options ?: EqualityOptions , message ?: string ) : void
198
- static isNaN ( value : unknown , options ?: EqualityOptions | string , message ?: string ) {
193
+ export function isNaN ( value : unknown , message ?: string ) : void
194
+ export function isNaN ( value : unknown , options ?: EqualityOptions , message ?: string ) : void
195
+ export function isNaN ( value : unknown , options ?: EqualityOptions | string , message ?: string ) {
199
196
if ( typeof options === 'string' ) {
200
- return this . isNaN ( value , undefined , options ) ;
197
+ return isNaN ( value , undefined , options ) ;
201
198
}
202
199
203
200
options ??= { strict : false } ;
204
- const result = isNaN ( value as number ) && options . strict ? typeof value === 'number' : true ;
201
+ const result = globalThis . isNaN ( value as number ) && options . strict ? typeof value === 'number' : true ;
205
202
if ( result === false ) {
206
203
throw new BellatrixAssertionError ( 'NaN' , quoteString ( value ) , message ) ;
207
204
}
208
205
}
209
206
210
- static isNull ( value : unknown , message ?: string ) {
207
+ export function isNull ( value : unknown , message ?: string ) {
211
208
const result = value === null ;
212
209
if ( result === false ) {
213
210
throw new BellatrixAssertionError ( 'null' , quoteString ( value ) , message ) ;
214
211
}
215
212
}
216
213
217
- static isNotNull ( value : unknown , message ?: string ) {
214
+ export function isNotNull ( value : unknown , message ?: string ) {
218
215
const result = value !== null ;
219
216
if ( result === false ) {
220
217
throw new BellatrixAssertionError ( 'not null' , undefined , message ) ;
221
218
}
222
219
}
223
220
224
- static isDefined ( value : unknown , message ?: string ) {
221
+ export function isDefined ( value : unknown , message ?: string ) {
225
222
const result = value !== undefined ;
226
223
if ( result === false ) {
227
224
throw new BellatrixAssertionError ( 'not undefined' , undefined , message ) ;
228
225
}
229
226
}
230
227
231
- static isUndefined ( value : unknown , message ?: string ) {
228
+ export function isUndefined ( value : unknown , message ?: string ) {
232
229
const result = value === undefined ;
233
230
if ( result === false ) {
234
231
throw new BellatrixAssertionError ( 'undefined' , quoteString ( value ) , message ) ;
235
232
}
236
233
}
237
234
238
- static stringContains ( substring : string , value : string , message ?: string ) {
235
+ export function stringContains ( substring : string , value : string , message ?: string ) {
239
236
const result = value . includes ( substring ) ;
240
237
if ( result === false ) {
241
238
throw new BellatrixAssertionError ( `contains ${ substring } ` , quoteString ( value ) , message ) ;
242
239
}
243
240
}
244
241
245
- static arrayIsEmpty ( array : unknown [ ] , message ?: string ) {
242
+ export function arrayIsEmpty ( array : unknown [ ] , message ?: string ) {
246
243
const result = Array . isArray ( array ) && array . length === 0 ;
247
244
if ( result === false ) {
248
245
throw new BellatrixAssertionError ( '[]' , quoteString ( array ) , message ) ;
249
246
}
250
247
}
251
248
252
- static arrayIsNotEmpty ( array : unknown [ ] , message ?: string ) {
249
+ export function arrayIsNotEmpty ( array : unknown [ ] , message ?: string ) {
253
250
const result = Array . isArray ( array ) && array . length > 0 ;
254
251
if ( result === false ) {
255
252
throw new BellatrixAssertionError ( '[]' , quoteString ( array ) , message ) ;
256
253
}
257
254
}
258
255
259
- static isInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
256
+ export function isInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
260
257
const result = value instanceof instanceOf ;
261
258
if ( result === false ) {
262
259
throw new BellatrixAssertionError ( `instance of ${ instanceOf . name } ` , ( value as object ) . constructor . name , message ) ;
263
260
}
264
261
}
265
262
266
- static isNotInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
263
+ export function isNotInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
267
264
const result = ! ( value instanceof instanceOf ) ;
268
265
if ( result === false ) {
269
266
throw new BellatrixAssertionError ( `not instance of ${ instanceOf . name } ` , value . constructor . name , message ) ;
270
267
}
271
268
}
272
269
273
- static arrayIsSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
270
+ export function arrayIsSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
274
271
const result = array . every ( ( item ) => subsetOf . includes ( item ) ) ;
275
272
276
273
const arraySet = new Set ( array ) ;
@@ -289,15 +286,15 @@ export class Assert {
289
286
}
290
287
}
291
288
292
- static arrayIsNotSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
289
+ export function arrayIsNotSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
293
290
const result = array . every ( ( item ) => subsetOf . includes ( item ) ) ;
294
291
295
292
if ( result === false ) {
296
293
throw new BellatrixAssertionError ( `not subset of ${ quoteString ( subsetOf ) } ` , quoteString ( array ) , message ) ;
297
294
}
298
295
}
299
296
300
- static arrayIsSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
297
+ export function arrayIsSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
301
298
const result = supersetOf . every ( ( item ) => array . includes ( item ) ) ;
302
299
303
300
const arraySet = new Set ( array ) ;
@@ -316,19 +313,19 @@ export class Assert {
316
313
}
317
314
}
318
315
319
- static arrayIsNotSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
316
+ export function arrayIsNotSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
320
317
const result = ! supersetOf . every ( ( item ) => array . includes ( item ) ) ;
321
318
322
319
if ( result === false ) {
323
320
throw new BellatrixAssertionError ( `not be superset of ${ quoteString ( supersetOf ) } ` , quoteString ( array ) , message ) ;
324
321
}
325
322
}
326
323
327
- static that < T > ( value : T , ...expressions : AssertExpression < T > [ ] ) : void
328
- static that < T > ( value : T , options : AssertMultipleOptions , ...expressions : AssertExpression < T > [ ] ) : void
329
- static that < T > ( value : T , options ?: AssertMultipleOptions | AssertExpression < T > , ...expressions : AssertExpression < T > [ ] ) {
324
+ export function that < T > ( value : T , ...expressions : AssertExpression < T > [ ] ) : void
325
+ export function that < T > ( value : T , options : AssertMultipleOptions , ...expressions : AssertExpression < T > [ ] ) : void
326
+ export function that < T > ( value : T , options ?: AssertMultipleOptions | AssertExpression < T > , ...expressions : AssertExpression < T > [ ] ) {
330
327
if ( typeof options !== 'object' ) {
331
- return this . that ( value , { } , options ! , ...expressions ) ;
328
+ return that ( value , { } , options ! , ...expressions ) ;
332
329
}
333
330
334
331
if ( expressions [ 0 ] === undefined ) {
@@ -358,11 +355,11 @@ export class Assert {
358
355
}
359
356
}
360
357
361
- static async multiple ( ...expressions : Function [ ] ) : Promise < void >
362
- static async multiple ( options : AssertMultipleOptions , ...expressions : Function [ ] ) : Promise < void >
363
- static async multiple ( options ?: AssertMultipleOptions | Function , ...expressions : Function [ ] ) {
358
+ export async function multiple ( ...expressions : Function [ ] ) : Promise < void >
359
+ export async function multiple ( options : AssertMultipleOptions , ...expressions : Function [ ] ) : Promise < void >
360
+ export async function multiple ( options ?: AssertMultipleOptions | Function , ...expressions : Function [ ] ) {
364
361
if ( typeof options !== 'object' ) {
365
- return this . multiple ( { } , options ! , ...expressions ) ;
362
+ return multiple ( { } , options ! , ...expressions ) ;
366
363
}
367
364
368
365
if ( expressions [ 0 ] === undefined ) {
@@ -581,7 +578,7 @@ export const is = {
581
578
} ;
582
579
} ,
583
580
} ,
584
- } as const ;
581
+ } ;
585
582
586
583
function deepEquals ( obj1 : unknown , obj2 : unknown , strict : boolean ) {
587
584
if ( obj1 === obj2 ) return true ;
0 commit comments