Skip to content

Commit

Permalink
chore: use optional chaining
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Mar 20, 2020
1 parent a447740 commit 44dd615
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 24 deletions.
4 changes: 2 additions & 2 deletions packages/body-checksum-browser/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export async function bodyChecksumGenerator(
await blobReader(
body,
(chunk: any) => {
treeHash && treeHash.update(chunk);
contentHash && contentHash.update(chunk);
treeHash?.update(chunk);
contentHash?.update(chunk);
},
MiB
);
Expand Down
8 changes: 4 additions & 4 deletions packages/body-checksum-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export async function bodyChecksumGenerator(
ArrayBuffer.isView(body) ||
isArrayBuffer(body)
) {
contentHash && contentHash.update(body);
treeHash && treeHash.update(body);
contentHash?.update(body);
treeHash?.update(body);
} else {
if (typeof body.path !== "string") {
throw new Error("Unable to calculate checksums for non-file streams.");
Expand All @@ -32,8 +32,8 @@ export async function bodyChecksumGenerator(
});

await streamReader(bodyTee, (chunk: any) => {
contentHash && contentHash.update(chunk);
treeHash && treeHash.update(chunk);
contentHash?.update(chunk);
treeHash?.update(chunk);
});
}

Expand Down
2 changes: 1 addition & 1 deletion packages/chunked-stream-reader-node/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function streamReader(

stream.on("error", reject);
stream.on("end", () => {
if (temporaryBuffer && temporaryBuffer.byteLength) {
if (temporaryBuffer?.byteLength) {
for (let i = 0; i < temporaryBuffer.byteLength; i += chunkSize) {
onChunk(
temporaryBuffer.subarray(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class SdkClientTocPlugin extends RendererComponent {
}

private isUnion(model: DeclarationReflection): boolean {
return model.type && model.type.type === "union";
return model.type?.type === "union";
}

private isInputOrOutput(model: DeclarationReflection): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { localStorage } from "./localStorage";
import { IndexedDbStorage } from "./IndexedDbStorage";

describe("localStorage", () => {
const storageAtInit: Storage | undefined = window && window.localStorage;
const idbAtInit: IDBFactory | undefined = self && self.indexedDB;
const storageAtInit: Storage | undefined = window?.localStorage;
const idbAtInit: IDBFactory | undefined = self?.indexedDB;

beforeEach(() => {
if (window) {
Expand Down
4 changes: 2 additions & 2 deletions packages/fetch-http-handler/src/fetch-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ export class FetchHttpHandler implements HttpHandler {
request: HttpRequest,
options: HttpHandlerOptions
): Promise<{ response: HttpResponse }> {
const abortSignal = options && options.abortSignal;
const abortSignal = options?.abortSignal;
const requestTimeoutInMs = this.httpOptions.requestTimeout;

// if the request was already aborted, prevent doing extra work
if (abortSignal && abortSignal.aborted) {
if (abortSignal?.aborted) {
const abortError = new Error("Request aborted");
abortError.name = "AbortError";
return Promise.reject(abortError);
Expand Down
2 changes: 1 addition & 1 deletion packages/middleware-retry/src/retryDecider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ export const defaultRetryDecider = (error: SdkError) => {
};

function hasMetadata(error: any): error is MetadataBearer {
return error && error.$metadata;
return error?.$metadata;
}
2 changes: 1 addition & 1 deletion packages/middleware-stack/src/MiddlewareStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ export class MiddlewareStack<Input extends object, Output extends object> {
: defaultAnchorValue;
let relativeEntry = prev;
//reverse relative entry linked list and add to ordered handler list
while (relativeEntry && relativeEntry.prev) {
while (relativeEntry?.prev) {
relativeEntry = relativeEntry.prev;
}
while (relativeEntry) {
Expand Down
2 changes: 1 addition & 1 deletion packages/node-http-handler/src/node-http-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class NodeHttpHandler implements HttpHandler {
): Promise<{ response: HttpResponse }> {
return new Promise((resolve, reject) => {
// if the request was already aborted, prevent doing extra work
if (abortSignal && abortSignal.aborted) {
if (abortSignal?.aborted) {
const abortError = new Error("Request aborted");
abortError.name = "AbortError";
reject(abortError);
Expand Down
2 changes: 1 addition & 1 deletion packages/node-http-handler/src/node-http2-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class NodeHttp2Handler implements HttpHandler {
): Promise<{ response: HttpResponse }> {
return new Promise((resolve, reject) => {
// if the request was already aborted, prevent doing extra work
if (abortSignal && abortSignal.aborted) {
if (abortSignal?.aborted) {
const abortError = new Error("Request aborted");
abortError.name = "AbortError";
reject(abortError);
Expand Down
2 changes: 1 addition & 1 deletion packages/property-provider/src/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function chain<T>(...providers: Array<Provider<T>>): Provider<T> {
);
for (const provider of providers) {
promise = promise.catch((err: any) => {
if (err && err.tryNextLink) {
if (err?.tryNextLink) {
return provider();
}

Expand Down
10 changes: 3 additions & 7 deletions packages/signature-v4/src/getCanonicalHeaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ export function getCanonicalHeaders(
const canonicalHeaderName = headerName.toLowerCase();
if (
canonicalHeaderName in ALWAYS_UNSIGNABLE_HEADERS ||
(unsignableHeaders && unsignableHeaders.has(canonicalHeaderName)) ||
unsignableHeaders?.has(canonicalHeaderName) ||
!signableHeaders?.has(canonicalHeaderName) ||
PROXY_HEADER_PATTERN.test(canonicalHeaderName) ||
SEC_HEADER_PATTERN.test(canonicalHeaderName)
) {
if (
!signableHeaders ||
(signableHeaders && !signableHeaders.has(canonicalHeaderName))
) {
continue;
}
continue;
}

canonical[canonicalHeaderName] = headers[headerName]
Expand Down

0 comments on commit 44dd615

Please sign in to comment.