File tree Expand file tree Collapse file tree 12 files changed +40
-39
lines changed Expand file tree Collapse file tree 12 files changed +40
-39
lines changed Original file line number Diff line number Diff line change 1
1
import {
2
2
type InspectParameterFn ,
3
- basicInspectParameterFn ,
3
+ defaultInspect ,
4
4
isAnyArrayBuffer ,
5
5
isUint8Array
6
6
} from './parser/utils' ;
@@ -270,7 +270,7 @@ export class Binary extends BSONValue {
270
270
271
271
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
272
272
const addQuotes = ! inspect ;
273
- inspect ??= basicInspectParameterFn ;
273
+ inspect ??= defaultInspect ;
274
274
const base64 = ByteUtils . toBase64 ( this . buffer . subarray ( 0 , this . position ) ) ;
275
275
const base64Arg = inspect ( base64 , options ) ;
276
276
const subTypeArg = inspect ( this . sub_type , options ) ;
@@ -474,7 +474,7 @@ export class UUID extends Binary {
474
474
*/
475
475
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
476
476
const addQuotes = ! inspect ;
477
- inspect ??= basicInspectParameterFn ;
477
+ inspect ??= defaultInspect ;
478
478
if ( addQuotes ) {
479
479
return `new UUID('${ inspect ( this . toHexString ( ) , options ) } ')` ;
480
480
}
Original file line number Diff line number Diff line change 1
1
import type { Document } from './bson' ;
2
2
import { BSONValue } from './bson_value' ;
3
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
3
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
4
4
5
5
/** @public */
6
6
export interface CodeExtended {
@@ -57,7 +57,7 @@ export class Code extends BSONValue {
57
57
}
58
58
59
59
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
60
- inspect ??= basicInspectParameterFn ;
60
+ inspect ??= defaultInspect ;
61
61
let parametersString = inspect ( this . code , options ) ;
62
62
const multiLineFn = parametersString . includes ( '\n' ) ;
63
63
if ( this . scope != null ) {
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import type { Document } from './bson';
2
2
import { BSONValue } from './bson_value' ;
3
3
import type { EJSONOptions } from './extended_json' ;
4
4
import type { ObjectId } from './objectid' ;
5
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
5
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
6
6
7
7
/** @public */
8
8
export interface DBRefLike {
@@ -114,7 +114,7 @@ export class DBRef extends BSONValue {
114
114
115
115
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
116
116
const addQuotes = ! inspect ;
117
- inspect ??= basicInspectParameterFn ;
117
+ inspect ??= defaultInspect ;
118
118
119
119
const args = [
120
120
inspect ( this . namespace , options ) ,
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
2
import { BSONError } from './error' ;
3
3
import { Long } from './long' ;
4
- import { type InspectParameterFn , basicInspectParameterFn , isUint8Array } from './parser/utils' ;
4
+ import { type InspectParameterFn , defaultInspect , isUint8Array } from './parser/utils' ;
5
5
import { ByteUtils } from './utils/byte_utils' ;
6
6
7
7
const PARSE_STRING_REGEXP = / ^ ( \+ | - ) ? ( \d + | ( \d * \. \d * ) ) ? ( E | e ) ? ( [ - + ] ) ? ( \d + ) ? $ / ;
@@ -849,7 +849,7 @@ export class Decimal128 extends BSONValue {
849
849
850
850
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
851
851
const addQuotes = ! inspect ;
852
- inspect ??= basicInspectParameterFn ;
852
+ inspect ??= defaultInspect ;
853
853
const d128string = inspect ( this . toString ( ) , options ) ;
854
854
if ( addQuotes ) {
855
855
return `new Decimal128('${ d128string } ')` ;
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
2
import type { EJSONOptions } from './extended_json' ;
3
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
3
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
4
4
5
5
/** @public */
6
6
export interface DoubleExtended {
@@ -73,7 +73,7 @@ export class Double extends BSONValue {
73
73
}
74
74
75
75
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
76
- inspect ??= basicInspectParameterFn ;
76
+ inspect ??= defaultInspect ;
77
77
return `new Double(${ inspect ( this . valueOf ( ) , options ) } )` ;
78
78
}
79
79
}
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
2
import type { EJSONOptions } from './extended_json' ;
3
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
3
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
4
4
5
5
/** @public */
6
6
export interface Int32Extended {
@@ -61,7 +61,7 @@ export class Int32 extends BSONValue {
61
61
}
62
62
63
63
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
64
- inspect ??= basicInspectParameterFn ;
64
+ inspect ??= defaultInspect ;
65
65
return `new Int32(${ inspect ( this . value , options ) } )` ;
66
66
}
67
67
}
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
2
import { BSONError } from './error' ;
3
3
import type { EJSONOptions } from './extended_json' ;
4
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
4
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
5
5
import type { Timestamp } from './timestamp' ;
6
6
7
7
interface LongWASMHelpers {
@@ -1058,7 +1058,7 @@ export class Long extends BSONValue {
1058
1058
}
1059
1059
1060
1060
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
1061
- inspect ??= basicInspectParameterFn ;
1061
+ inspect ??= defaultInspect ;
1062
1062
const longVal = inspect ( this . toString ( ) , options ) ;
1063
1063
const unsignedVal = this . unsigned ? `, ${ inspect ( this . unsigned , options ) } ` : '' ;
1064
1064
return `new Long(${ longVal } ${ unsignedVal } )` ;
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
2
import { BSONError } from './error' ;
3
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
3
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
4
4
import { BSONDataView , ByteUtils } from './utils/byte_utils' ;
5
5
6
6
// Regular expression that checks for hex value
@@ -298,7 +298,7 @@ export class ObjectId extends BSONValue {
298
298
*/
299
299
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
300
300
const addQuotes = ! inspect ;
301
- inspect ??= basicInspectParameterFn ;
301
+ inspect ??= defaultInspect ;
302
302
if ( addQuotes ) {
303
303
return `new ObjectId('${ inspect ( this . toHexString ( ) , options ) } ')` ;
304
304
}
Original file line number Diff line number Diff line change @@ -28,22 +28,6 @@ export function isDate(d: unknown): d is Date {
28
28
return Object . prototype . toString . call ( d ) === '[object Date]' ;
29
29
}
30
30
31
- /** @internal */
32
- export type StylizeFunction = ( x : string , style : string ) => string ;
33
31
export type InspectParameterFn = ( x : unknown , options : unknown ) => string ;
34
32
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
35
- export const basicInspectParameterFn : InspectParameterFn = v => `${ v } ` ;
36
-
37
- export function getStylizeFunction ( options ?: unknown ) : StylizeFunction {
38
- const stylizeExists =
39
- options != null &&
40
- typeof options === 'object' &&
41
- 'stylize' in options &&
42
- typeof options . stylize === 'function' ;
43
-
44
- if ( stylizeExists ) {
45
- return options . stylize as StylizeFunction ;
46
- } else {
47
- return basicInspectParameterFn ;
48
- }
49
- }
33
+ export const defaultInspect : InspectParameterFn = v => `${ v } ` ;
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
2
import { BSONError } from './error' ;
3
3
import type { EJSONOptions } from './extended_json' ;
4
- import { getStylizeFunction } from './parser/utils' ;
4
+ import { defaultInspect } from './parser/utils' ;
5
5
6
6
function alphabetize ( str : string ) : string {
7
7
return str . split ( '' ) . sort ( ) . join ( '' ) ;
@@ -111,3 +111,20 @@ export class BSONRegExp extends BSONValue {
111
111
return `new BSONRegExp(${ pattern } , ${ flags } )` ;
112
112
}
113
113
}
114
+
115
+ /** @internal */
116
+ type StylizeFunction = ( x : string , style : string ) => string ;
117
+ /** @internal */
118
+ function getStylizeFunction ( options ?: unknown ) : StylizeFunction {
119
+ const stylizeExists =
120
+ options != null &&
121
+ typeof options === 'object' &&
122
+ 'stylize' in options &&
123
+ typeof options . stylize === 'function' ;
124
+
125
+ if ( stylizeExists ) {
126
+ return options . stylize as StylizeFunction ;
127
+ } else {
128
+ return defaultInspect ;
129
+ }
130
+ }
Original file line number Diff line number Diff line change 1
1
import { BSONValue } from './bson_value' ;
2
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
2
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
3
3
4
4
/** @public */
5
5
export interface BSONSymbolExtended {
@@ -59,7 +59,7 @@ export class BSONSymbol extends BSONValue {
59
59
60
60
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
61
61
const addQuotes = ! inspect ;
62
- inspect ??= basicInspectParameterFn ;
62
+ inspect ??= defaultInspect ;
63
63
if ( addQuotes ) {
64
64
return `new BSONSymbol('${ inspect ( this . value , options ) } ')` ;
65
65
}
Original file line number Diff line number Diff line change 1
1
import { BSONError } from './error' ;
2
2
import type { Int32 } from './int_32' ;
3
3
import { Long } from './long' ;
4
- import { type InspectParameterFn , basicInspectParameterFn } from './parser/utils' ;
4
+ import { type InspectParameterFn , defaultInspect } from './parser/utils' ;
5
5
6
6
/** @public */
7
7
export type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect' ;
@@ -143,7 +143,7 @@ export class Timestamp extends LongWithoutOverridesClass {
143
143
}
144
144
145
145
inspect ( depth ?: number , options ?: unknown , inspect ?: InspectParameterFn ) : string {
146
- inspect ??= basicInspectParameterFn ;
146
+ inspect ??= defaultInspect ;
147
147
const t = inspect ( this . getHighBits ( ) , options ) ;
148
148
const i = inspect ( this . getLowBits ( ) , options ) ;
149
149
return `new Timestamp({ t: ${ t } , i: ${ i } })` ;
You can’t perform that action at this time.
0 commit comments