_utils.js 674 B

1234567891011121314151617181920
  1. export * from './platform.js'
  2. const Buffer = /* @__PURE__ */ (() => globalThis.Buffer)()
  3. export function assert(condition, msg) {
  4. if (!condition) throw new Error(msg)
  5. }
  6. export function assertU8(arg) {
  7. if (!(arg instanceof Uint8Array)) throw new TypeError('Expected an Uint8Array')
  8. }
  9. // On arrays in heap (<= 64) it's cheaper to copy into a pooled buffer than lazy-create the ArrayBuffer storage
  10. export const toBuf = (x) =>
  11. x.byteLength <= 64 && x.BYTES_PER_ELEMENT === 1
  12. ? Buffer.from(x)
  13. : Buffer.from(x.buffer, x.byteOffset, x.byteLength)
  14. export const E_STRING = 'Input is not a string'
  15. export const E_STRICT_UNICODE = 'Input is not well-formed Unicode'