File tree 3 files changed +16
-6
lines changed
3 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import {
12
12
FunctionDebugExecutor ,
13
13
} from '../support/engine'
14
14
import pako from 'pako'
15
- import { base64ToUint8Array , uint8ArrayToBase64 } from '../support/utils'
15
+ import { base64ToUint8Array , isObject , uint8ArrayToBase64 } from '../support/utils'
16
16
17
17
export async function handleInvokeFunction ( req : IRequest , res : Response ) {
18
18
const name = req . params ?. name
@@ -90,7 +90,7 @@ async function invokeFunction(
90
90
91
91
// reject request if interceptor return false
92
92
if (
93
- typeof result . data === 'object' &&
93
+ isObject ( result . data ) &&
94
94
result . data . __type__ === '__interceptor__' &&
95
95
result . data . __res__ == false
96
96
) {
@@ -200,7 +200,7 @@ async function invokeDebug(
200
200
201
201
// reject request if interceptor return false
202
202
if (
203
- typeof result . data === 'object' &&
203
+ isObject ( result . data ) &&
204
204
result . data . __type__ === '__interceptor__' &&
205
205
result . data . __res__ == false
206
206
) {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import * as util from 'util'
2
2
import chalk from 'chalk'
3
3
import { padStart } from 'lodash'
4
4
import Config from '../../config'
5
+ import { isObject } from '../utils'
5
6
6
7
enum LogLevel {
7
8
DEBUG = 'DEBUG' ,
@@ -31,7 +32,7 @@ export class Console {
31
32
let content = params
32
33
. map ( ( param ) => {
33
34
if ( typeof param === 'string' ) return this . _colorize ( level , param )
34
- if ( typeof param === 'object' ) {
35
+ if ( isObject ( param ) ) {
35
36
return this . _colorize (
36
37
level ,
37
38
util . inspect ( param , { depth : Config . LOG_DEPTH , colors : true } ) ,
Original file line number Diff line number Diff line change @@ -68,7 +68,7 @@ export function deepFreeze(object: Object) {
68
68
for ( const name of propNames ) {
69
69
const value = object [ name ]
70
70
71
- if ( value && typeof value === 'object' ) {
71
+ if ( isObject ( value ) ) {
72
72
deepFreeze ( value )
73
73
}
74
74
}
@@ -114,4 +114,13 @@ export function uint8ArrayToBase64(buffer: Uint8Array) {
114
114
export function base64ToUint8Array ( base64 : string ) {
115
115
const buffer = Buffer . from ( base64 , 'base64' )
116
116
return new Uint8Array ( buffer )
117
- }
117
+ }
118
+
119
+ /**
120
+ * is object.
121
+ * @param obj
122
+ * @returns
123
+ */
124
+ export function isObject ( obj : unknown ) : obj is Object {
125
+ return obj !== null && typeof obj === 'object'
126
+ }
You can’t perform that action at this time.
0 commit comments