Skip to content

Commit

Permalink
refactor: remove typeof operator for undefined checks
Browse files Browse the repository at this point in the history
  • Loading branch information
dnalborczyk committed Oct 15, 2022
1 parent 9a07736 commit 312d4f0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
11 changes: 4 additions & 7 deletions src/events/http/HttpServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,12 +459,12 @@ export default class HttpServer {

// default request template to '' if we don't have a definition pushed in from serverless or endpoint
const requestTemplate =
typeof requestTemplates !== 'undefined' && integration === 'AWS'
requestTemplates !== undefined && integration === 'AWS'
? requestTemplates[contentType]
: ''

const schemas =
typeof endpoint?.request?.schemas !== 'undefined'
endpoint?.request?.schemas !== undefined
? endpoint.request.schemas[contentType]
: ''

Expand Down Expand Up @@ -647,10 +647,7 @@ export default class HttpServer {
headerValue = valueArray[3]
? jsonPath(result, valueArray.slice(3).join('.'))
: result
if (
typeof headerValue === 'undefined' ||
headerValue === null
) {
if (headerValue === undefined || headerValue === null) {
headerValue = ''
} else {
headerValue = headerValue.toString()
Expand Down Expand Up @@ -857,7 +854,7 @@ export default class HttpServer {

if (typeof result === 'string') {
response.source = stringify(result)
} else if (result && typeof result.body !== 'undefined') {
} else if (result && result.body !== undefined) {
if (result.isBase64Encoded) {
response.encoding = 'binary'
response.source = Buffer.from(result.body, 'base64')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export default class LambdaProxyIntegrationEvent {
) {
headers['Content-Type'] = 'application/json'
}
} else if (typeof body === 'undefined' || body === '') {
} else if (body === undefined || body === '') {
body = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default class LambdaProxyIntegrationEventV2 {
if (!headers['content-type']) {
headers['content-type'] = 'application/json'
}
} else if (typeof body === 'undefined' || body === '') {
} else if (body === undefined || body === '') {
body = null
}

Expand Down
2 changes: 1 addition & 1 deletion src/lambda/routes/invocations/invocationsRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function invocationsRoute(lambda, options) {
let statusCode = 200
let functionError = null
if (invokeResults) {
const isPayloadDefined = typeof invokeResults.Payload !== 'undefined'
const isPayloadDefined = invokeResults.Payload !== undefined
resultPayload = isPayloadDefined ? invokeResults.Payload : ''
statusCode = invokeResults.StatusCode || 200
functionError = invokeResults.FunctionError || null
Expand Down

0 comments on commit 312d4f0

Please sign in to comment.