1+ /* eslint-disable @typescript-eslint/no-namespace */
12export type EqualityOptions = {
23 strict : boolean ;
34}
@@ -60,16 +61,12 @@ class BellatrixAssertionError extends Error {
6061 }
6162}
6263
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 ) {
7168 if ( typeof options === 'string' ) {
72- return this . areEqual ( expected , actual , undefined , options ) ;
69+ return areEqual ( expected , actual , undefined , options ) ;
7370 }
7471
7572 options ??= { strict : false } ;
@@ -83,11 +80,11 @@ export class Assert {
8380 }
8481 }
8582
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 ) {
8986 if ( typeof options === 'string' ) {
90- return this . areDeepEqual ( expected , actual , undefined , options ) ;
87+ return areDeepEqual ( expected , actual , undefined , options ) ;
9188 }
9289
9390 options ??= { strict : false } ;
@@ -97,11 +94,11 @@ export class Assert {
9794 }
9895 }
9996
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 ) {
103100 if ( typeof options === 'string' ) {
104- return this . areApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
101+ return areApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
105102 }
106103
107104 options ??= { method : 'round' } ;
@@ -114,11 +111,11 @@ export class Assert {
114111 }
115112 }
116113
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 ) {
120117 if ( typeof options === 'string' ) {
121- return this . areNotEqual ( expected , actual , undefined , options ) ;
118+ return areNotEqual ( expected , actual , undefined , options ) ;
122119 }
123120
124121 options ??= { strict : false } ;
@@ -134,11 +131,11 @@ export class Assert {
134131 }
135132 }
136133
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 ) {
140137 if ( typeof options === 'string' ) {
141- return this . areNotDeepEqual ( expected , actual , undefined , options ) ;
138+ return areNotDeepEqual ( expected , actual , undefined , options ) ;
142139 }
143140
144141 options ??= { strict : false } ;
@@ -148,11 +145,11 @@ export class Assert {
148145 }
149146 }
150147
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 ) {
154151 if ( typeof options === 'string' ) {
155- return this . areNotApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
152+ return areNotApproximatelyEqual ( expected , actual , decimalPlaces , undefined , options ) ;
156153 }
157154
158155 options ??= { method : 'round' } ;
@@ -165,112 +162,112 @@ export class Assert {
165162 }
166163 }
167164
168- static isFalse ( value : boolean , message ?: string ) {
165+ export function isFalse ( value : boolean , message ?: string ) {
169166 const result = value === false ;
170167 if ( result === false ) {
171168 throw new BellatrixAssertionError ( 'false' , String ( value ) , message ) ;
172169 }
173170 }
174171
175- static isFalsy ( value : unknown , message ?: string ) {
172+ export function isFalsy ( value : unknown , message ?: string ) {
176173 const result = value == false ;
177174 if ( result === false ) {
178175 throw new BellatrixAssertionError ( 'falsy' , quoteString ( value ) , message ) ;
179176 }
180177 }
181178
182- static isTrue ( value : boolean , message ?: string ) {
179+ export function isTrue ( value : boolean , message ?: string ) {
183180 const result = value === true ;
184181 if ( result === false ) {
185182 throw new BellatrixAssertionError ( 'true' , String ( value ) , message ) ;
186183 }
187184 }
188185
189- static isTruthy ( value : unknown , message ?: string ) {
186+ export function isTruthy ( value : unknown , message ?: string ) {
190187 const result = value == true ;
191188 if ( result === false ) {
192189 throw new BellatrixAssertionError ( 'truthy' , quoteString ( value ) , message ) ;
193190 }
194191 }
195192
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 ) {
199196 if ( typeof options === 'string' ) {
200- return this . isNaN ( value , undefined , options ) ;
197+ return isNaN ( value , undefined , options ) ;
201198 }
202199
203200 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 ;
205202 if ( result === false ) {
206203 throw new BellatrixAssertionError ( 'NaN' , quoteString ( value ) , message ) ;
207204 }
208205 }
209206
210- static isNull ( value : unknown , message ?: string ) {
207+ export function isNull ( value : unknown , message ?: string ) {
211208 const result = value === null ;
212209 if ( result === false ) {
213210 throw new BellatrixAssertionError ( 'null' , quoteString ( value ) , message ) ;
214211 }
215212 }
216213
217- static isNotNull ( value : unknown , message ?: string ) {
214+ export function isNotNull ( value : unknown , message ?: string ) {
218215 const result = value !== null ;
219216 if ( result === false ) {
220217 throw new BellatrixAssertionError ( 'not null' , undefined , message ) ;
221218 }
222219 }
223220
224- static isDefined ( value : unknown , message ?: string ) {
221+ export function isDefined ( value : unknown , message ?: string ) {
225222 const result = value !== undefined ;
226223 if ( result === false ) {
227224 throw new BellatrixAssertionError ( 'not undefined' , undefined , message ) ;
228225 }
229226 }
230227
231- static isUndefined ( value : unknown , message ?: string ) {
228+ export function isUndefined ( value : unknown , message ?: string ) {
232229 const result = value === undefined ;
233230 if ( result === false ) {
234231 throw new BellatrixAssertionError ( 'undefined' , quoteString ( value ) , message ) ;
235232 }
236233 }
237234
238- static stringContains ( substring : string , value : string , message ?: string ) {
235+ export function stringContains ( substring : string , value : string , message ?: string ) {
239236 const result = value . includes ( substring ) ;
240237 if ( result === false ) {
241238 throw new BellatrixAssertionError ( `contains ${ substring } ` , quoteString ( value ) , message ) ;
242239 }
243240 }
244241
245- static arrayIsEmpty ( array : unknown [ ] , message ?: string ) {
242+ export function arrayIsEmpty ( array : unknown [ ] , message ?: string ) {
246243 const result = Array . isArray ( array ) && array . length === 0 ;
247244 if ( result === false ) {
248245 throw new BellatrixAssertionError ( '[]' , quoteString ( array ) , message ) ;
249246 }
250247 }
251248
252- static arrayIsNotEmpty ( array : unknown [ ] , message ?: string ) {
249+ export function arrayIsNotEmpty ( array : unknown [ ] , message ?: string ) {
253250 const result = Array . isArray ( array ) && array . length > 0 ;
254251 if ( result === false ) {
255252 throw new BellatrixAssertionError ( '[]' , quoteString ( array ) , message ) ;
256253 }
257254 }
258255
259- static isInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
256+ export function isInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
260257 const result = value instanceof instanceOf ;
261258 if ( result === false ) {
262259 throw new BellatrixAssertionError ( `instance of ${ instanceOf . name } ` , ( value as object ) . constructor . name , message ) ;
263260 }
264261 }
265262
266- static isNotInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
263+ export function isNotInstanceOf ( instanceOf : Function , value : unknown , message ?: string ) {
267264 const result = ! ( value instanceof instanceOf ) ;
268265 if ( result === false ) {
269266 throw new BellatrixAssertionError ( `not instance of ${ instanceOf . name } ` , value . constructor . name , message ) ;
270267 }
271268 }
272269
273- static arrayIsSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
270+ export function arrayIsSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
274271 const result = array . every ( ( item ) => subsetOf . includes ( item ) ) ;
275272
276273 const arraySet = new Set ( array ) ;
@@ -289,15 +286,15 @@ export class Assert {
289286 }
290287 }
291288
292- static arrayIsNotSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
289+ export function arrayIsNotSubsetOf ( subsetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
293290 const result = array . every ( ( item ) => subsetOf . includes ( item ) ) ;
294291
295292 if ( result === false ) {
296293 throw new BellatrixAssertionError ( `not subset of ${ quoteString ( subsetOf ) } ` , quoteString ( array ) , message ) ;
297294 }
298295 }
299296
300- static arrayIsSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
297+ export function arrayIsSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
301298 const result = supersetOf . every ( ( item ) => array . includes ( item ) ) ;
302299
303300 const arraySet = new Set ( array ) ;
@@ -316,19 +313,19 @@ export class Assert {
316313 }
317314 }
318315
319- static arrayIsNotSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
316+ export function arrayIsNotSupersetOf ( supersetOf : unknown [ ] , array : unknown [ ] , message ?: string ) {
320317 const result = ! supersetOf . every ( ( item ) => array . includes ( item ) ) ;
321318
322319 if ( result === false ) {
323320 throw new BellatrixAssertionError ( `not be superset of ${ quoteString ( supersetOf ) } ` , quoteString ( array ) , message ) ;
324321 }
325322 }
326323
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 > [ ] ) {
330327 if ( typeof options !== 'object' ) {
331- return this . that ( value , { } , options ! , ...expressions ) ;
328+ return that ( value , { } , options ! , ...expressions ) ;
332329 }
333330
334331 if ( expressions [ 0 ] === undefined ) {
@@ -358,11 +355,11 @@ export class Assert {
358355 }
359356 }
360357
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 [ ] ) {
364361 if ( typeof options !== 'object' ) {
365- return this . multiple ( { } , options ! , ...expressions ) ;
362+ return multiple ( { } , options ! , ...expressions ) ;
366363 }
367364
368365 if ( expressions [ 0 ] === undefined ) {
@@ -581,7 +578,7 @@ export const is = {
581578 } ;
582579 } ,
583580 } ,
584- } as const ;
581+ } ;
585582
586583function deepEquals ( obj1 : unknown , obj2 : unknown , strict : boolean ) {
587584 if ( obj1 === obj2 ) return true ;
0 commit comments