summaryrefslogtreecommitdiff
path: root/util.ts
blob: c4fa032558679219ab285aa2c296398e212787cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { debug } from "./main";
import { TypedArray } from "./types";

// Internal logging for deno. Use the "debug" variable above to control
// output.
// tslint:disable-next-line:no-any
export function log(...args: any[]): void {
  if (debug) {
    console.log(...args);
  }
}

export function assert(cond: boolean, msg = "") {
  if (!cond) {
    throw Error("Assert fail. " + msg);
  }
}

export function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer {
  const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
  return ab as ArrayBuffer;
}