diff options
author | MichaĆ Sabiniarz <31597105+mhvsa@users.noreply.github.com> | 2020-03-30 19:45:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-30 13:45:37 -0400 |
commit | 4b71ac550ea964e9c647dbb6bd9879bc06357255 (patch) | |
tree | 2bda96726a1900a334b20fa8b1a4cfea5e2aac7b /cli/js/web/util.ts | |
parent | a98512af9a123b77332f0e7a75cfce753b7189bc (diff) |
console: iterable printing improvements (#4472)
1. Array elements are now grouped the same as in Node.js
2. Limit to 100 (Node.js default) elements to display in iterable
3. Print each element in new line if excessing max line length (same as in Node.js)
4. Print length of the TypedArray
5. Print information about empty items in Array
Diffstat (limited to 'cli/js/web/util.ts')
-rw-r--r-- | cli/js/web/util.ts | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/cli/js/web/util.ts b/cli/js/web/util.ts index 19a30a675..2d63b4d60 100644 --- a/cli/js/web/util.ts +++ b/cli/js/web/util.ts @@ -1,9 +1,28 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -export type TypedArray = Uint8Array | Float32Array | Int32Array; -const TypedArrayConstructor = Object.getPrototypeOf(Uint8Array); +export type TypedArray = + | Int8Array + | Uint8Array + | Uint8ClampedArray + | Int16Array + | Uint16Array + | Int32Array + | Uint32Array + | Float32Array + | Float64Array; + export function isTypedArray(x: unknown): x is TypedArray { - return x instanceof TypedArrayConstructor; + return ( + x instanceof Int8Array || + x instanceof Uint8Array || + x instanceof Uint8ClampedArray || + x instanceof Int16Array || + x instanceof Uint16Array || + x instanceof Int32Array || + x instanceof Uint32Array || + x instanceof Float32Array || + x instanceof Float64Array + ); } // @internal |