UNPKG

@cloudpss/ubjson

Version:

25 lines (21 loc) 731 B
const getType = (obj: unknown): string => Object.prototype.toString.call(obj).slice(8, -1); /** unsupported view */ export function unsupportedView(view: ArrayBufferView): never { const type = getType(view); throw new Error(`Unsupported array buffer view of type ${type}`); } /** unsupported type */ export function unsupportedType(value: unknown): never { if (value && typeof value == 'string') { throw new Error(`Unsupported type ${value}`); } const type = getType(value); throw new Error(`Unsupported type ${type}`); } /** 未结束的流 */ export class UnexpectedEofError extends Error { constructor() { super('Unexpected EOF'); this.name = 'UnexpectedEofError'; } }