Skip to content

Commit

Permalink
Use isTypedArray
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkassimo committed Dec 10, 2018
1 parent bcc1b14 commit 7b4a368
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions js/console.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import { isTypedArray } from "./util";

// tslint:disable-next-line:no-any
type ConsoleContext = Set<any>;
Expand All @@ -11,18 +12,6 @@ type ConsoleOptions = Partial<{
// Default depth of logging nested objects
const DEFAULT_MAX_DEPTH = 4;

const TYPEDARRAY_TYPES = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
];

// tslint:disable-next-line:no-any
function getClassInstanceName(instance: any): string {
if (typeof instance !== "object") {
Expand Down Expand Up @@ -275,14 +264,12 @@ function createObjectString(
return createWeakMapString();
} else {
// Check if it is a typed array
for (const cstr of TYPEDARRAY_TYPES) {
if (value instanceof cstr) {
return createTypedArrayString(
cstr.prototype.constructor.name,
value,
...args
);
}
if (isTypedArray(value)) {
return createTypedArrayString(
Object.getPrototypeOf(value).constructor.name,
value,
...args
);
}

// Otherwise, default object formatting
Expand Down

0 comments on commit 7b4a368

Please sign in to comment.