Skip to content

Commit ca773fd

Browse files
PR requested changes pt 2
1 parent cf5d132 commit ca773fd

File tree

12 files changed

+40
-39
lines changed

12 files changed

+40
-39
lines changed

src/binary.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
22
type InspectParameterFn,
3-
basicInspectParameterFn,
3+
defaultInspect,
44
isAnyArrayBuffer,
55
isUint8Array
66
} from './parser/utils';
@@ -270,7 +270,7 @@ export class Binary extends BSONValue {
270270

271271
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
272272
const addQuotes = !inspect;
273-
inspect ??= basicInspectParameterFn;
273+
inspect ??= defaultInspect;
274274
const base64 = ByteUtils.toBase64(this.buffer.subarray(0, this.position));
275275
const base64Arg = inspect(base64, options);
276276
const subTypeArg = inspect(this.sub_type, options);
@@ -474,7 +474,7 @@ export class UUID extends Binary {
474474
*/
475475
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
476476
const addQuotes = !inspect;
477-
inspect ??= basicInspectParameterFn;
477+
inspect ??= defaultInspect;
478478
if (addQuotes) {
479479
return `new UUID('${inspect(this.toHexString(), options)}')`;
480480
}

src/code.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Document } from './bson';
22
import { BSONValue } from './bson_value';
3-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
3+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
44

55
/** @public */
66
export interface CodeExtended {
@@ -57,7 +57,7 @@ export class Code extends BSONValue {
5757
}
5858

5959
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
60-
inspect ??= basicInspectParameterFn;
60+
inspect ??= defaultInspect;
6161
let parametersString = inspect(this.code, options);
6262
const multiLineFn = parametersString.includes('\n');
6363
if (this.scope != null) {

src/db_ref.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Document } from './bson';
22
import { BSONValue } from './bson_value';
33
import type { EJSONOptions } from './extended_json';
44
import type { ObjectId } from './objectid';
5-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
5+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
66

77
/** @public */
88
export interface DBRefLike {
@@ -114,7 +114,7 @@ export class DBRef extends BSONValue {
114114

115115
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
116116
const addQuotes = !inspect;
117-
inspect ??= basicInspectParameterFn;
117+
inspect ??= defaultInspect;
118118

119119
const args = [
120120
inspect(this.namespace, options),

src/decimal128.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BSONValue } from './bson_value';
22
import { BSONError } from './error';
33
import { Long } from './long';
4-
import { type InspectParameterFn, basicInspectParameterFn, isUint8Array } from './parser/utils';
4+
import { type InspectParameterFn, defaultInspect, isUint8Array } from './parser/utils';
55
import { ByteUtils } from './utils/byte_utils';
66

77
const PARSE_STRING_REGEXP = /^(\+|-)?(\d+|(\d*\.\d*))?(E|e)?([-+])?(\d+)?$/;
@@ -849,7 +849,7 @@ export class Decimal128 extends BSONValue {
849849

850850
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
851851
const addQuotes = !inspect;
852-
inspect ??= basicInspectParameterFn;
852+
inspect ??= defaultInspect;
853853
const d128string = inspect(this.toString(), options);
854854
if (addQuotes) {
855855
return `new Decimal128('${d128string}')`;

src/double.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BSONValue } from './bson_value';
22
import type { EJSONOptions } from './extended_json';
3-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
3+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
44

55
/** @public */
66
export interface DoubleExtended {
@@ -73,7 +73,7 @@ export class Double extends BSONValue {
7373
}
7474

7575
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
76-
inspect ??= basicInspectParameterFn;
76+
inspect ??= defaultInspect;
7777
return `new Double(${inspect(this.valueOf(), options)})`;
7878
}
7979
}

src/int_32.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BSONValue } from './bson_value';
22
import type { EJSONOptions } from './extended_json';
3-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
3+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
44

55
/** @public */
66
export interface Int32Extended {
@@ -61,7 +61,7 @@ export class Int32 extends BSONValue {
6161
}
6262

6363
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
64-
inspect ??= basicInspectParameterFn;
64+
inspect ??= defaultInspect;
6565
return `new Int32(${inspect(this.value, options)})`;
6666
}
6767
}

src/long.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BSONValue } from './bson_value';
22
import { BSONError } from './error';
33
import type { EJSONOptions } from './extended_json';
4-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
4+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
55
import type { Timestamp } from './timestamp';
66

77
interface LongWASMHelpers {
@@ -1058,7 +1058,7 @@ export class Long extends BSONValue {
10581058
}
10591059

10601060
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
1061-
inspect ??= basicInspectParameterFn;
1061+
inspect ??= defaultInspect;
10621062
const longVal = inspect(this.toString(), options);
10631063
const unsignedVal = this.unsigned ? `, ${inspect(this.unsigned, options)}` : '';
10641064
return `new Long(${longVal}${unsignedVal})`;

src/objectid.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { BSONValue } from './bson_value';
22
import { BSONError } from './error';
3-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
3+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
44
import { BSONDataView, ByteUtils } from './utils/byte_utils';
55

66
// Regular expression that checks for hex value
@@ -298,7 +298,7 @@ export class ObjectId extends BSONValue {
298298
*/
299299
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
300300
const addQuotes = !inspect;
301-
inspect ??= basicInspectParameterFn;
301+
inspect ??= defaultInspect;
302302
if (addQuotes) {
303303
return `new ObjectId('${inspect(this.toHexString(), options)}')`;
304304
}

src/parser/utils.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ export function isDate(d: unknown): d is Date {
2828
return Object.prototype.toString.call(d) === '[object Date]';
2929
}
3030

31-
/** @internal */
32-
export type StylizeFunction = (x: string, style: string) => string;
3331
export type InspectParameterFn = (x: unknown, options: unknown) => string;
3432
// 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}`;

src/regexp.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BSONValue } from './bson_value';
22
import { BSONError } from './error';
33
import type { EJSONOptions } from './extended_json';
4-
import { getStylizeFunction } from './parser/utils';
4+
import { defaultInspect } from './parser/utils';
55

66
function alphabetize(str: string): string {
77
return str.split('').sort().join('');
@@ -111,3 +111,20 @@ export class BSONRegExp extends BSONValue {
111111
return `new BSONRegExp(${pattern}, ${flags})`;
112112
}
113113
}
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+
}

src/symbol.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BSONValue } from './bson_value';
2-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
2+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
33

44
/** @public */
55
export interface BSONSymbolExtended {
@@ -59,7 +59,7 @@ export class BSONSymbol extends BSONValue {
5959

6060
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
6161
const addQuotes = !inspect;
62-
inspect ??= basicInspectParameterFn;
62+
inspect ??= defaultInspect;
6363
if (addQuotes) {
6464
return `new BSONSymbol('${inspect(this.value, options)}')`;
6565
}

src/timestamp.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BSONError } from './error';
22
import type { Int32 } from './int_32';
33
import { Long } from './long';
4-
import { type InspectParameterFn, basicInspectParameterFn } from './parser/utils';
4+
import { type InspectParameterFn, defaultInspect } from './parser/utils';
55

66
/** @public */
77
export type TimestampOverrides = '_bsontype' | 'toExtendedJSON' | 'fromExtendedJSON' | 'inspect';
@@ -143,7 +143,7 @@ export class Timestamp extends LongWithoutOverridesClass {
143143
}
144144

145145
inspect(depth?: number, options?: unknown, inspect?: InspectParameterFn): string {
146-
inspect ??= basicInspectParameterFn;
146+
inspect ??= defaultInspect;
147147
const t = inspect(this.getHighBits(), options);
148148
const i = inspect(this.getLowBits(), options);
149149
return `new Timestamp({ t: ${t}, i: ${i} })`;

0 commit comments

Comments
 (0)