@@ -3,6 +3,10 @@ import util from 'util'
3
3
// @ts -expect-error doesn't have types
4
4
import loupeImport from 'loupe'
5
5
6
+ interface LoupeOptions {
7
+ truncateThreshold ?: number
8
+ }
9
+
6
10
const loupe = ( typeof loupeImport . default === 'function' ? loupeImport . default : loupeImport )
7
11
8
12
export function format ( ...args : any [ ] ) {
@@ -14,19 +18,21 @@ export function utilInspect(item: unknown, options?: util.InspectOptions) {
14
18
}
15
19
16
20
// chai utils
17
- export function loupeInspect ( obj : unknown ) : string {
21
+ export function loupeInspect ( obj : unknown , options : LoupeOptions = { } ) : string {
18
22
return loupe ( obj , {
19
23
depth : 2 ,
20
- truncate : 40 ,
24
+ truncate : options . truncateThreshold === 0
25
+ ? Infinity
26
+ : ( options . truncateThreshold ?? 40 ) ,
21
27
} )
22
28
}
23
29
24
- export function objDisplay ( obj : unknown ) {
25
- const truncateThreshold = 40
26
- const str = loupeInspect ( obj )
30
+ export function objDisplay ( obj : unknown , options : LoupeOptions = { } ) : string {
31
+ const truncateThreshold = options . truncateThreshold ?? 40
32
+ const str = loupeInspect ( obj , options )
27
33
const type = Object . prototype . toString . call ( obj )
28
34
29
- if ( str . length >= truncateThreshold ) {
35
+ if ( truncateThreshold && str . length >= truncateThreshold ) {
30
36
if ( type === '[object Function]' ) {
31
37
const fn = obj as ( ) => void
32
38
return ( ! fn . name || fn . name === '' )
0 commit comments