polyvalid 0.1.7

A validator for package names, namespace, username and app name on wasmer
Documentation
---
source: /Users/ayushjha/.cargo/registry/src/github.com-1ecc6299db9ec823/wasmer-pack-testing-0.6.0/src/autodiscover.rs
---
const { data_view, UTF8_DECODER, utf8_encode, utf8_encoded_len, throw_invalid_bool } = require('./intrinsics.js');
class Polyvalid {
  addToImports(imports) {
  }
  
  async instantiate(module, imports) {
    imports = imports || {};
    this.addToImports(imports);
    
    if (module instanceof WebAssembly.Instance) {
      this.instance = module;
    } else if (module instanceof WebAssembly.Module) {
      this.instance = await WebAssembly.instantiate(module, imports);
    } else if (module instanceof ArrayBuffer || module instanceof Uint8Array) {
      const { instance } = await WebAssembly.instantiate(module, imports);
      this.instance = instance;
    } else {
      const { instance } = await WebAssembly.instantiateStreaming(module, imports);
      this.instance = instance;
    }
    this._exports = this.instance.exports;
  }
  isAppNameValid(arg0) {
    const memory = this._exports.memory;
    const realloc = this._exports["canonical_abi_realloc"];
    const free = this._exports["canonical_abi_free"];
    const ptr0 = utf8_encode(arg0, realloc, memory);
    const len0 = utf8_encoded_len();
    const ret = this._exports['is-app-name-valid'](ptr0, len0);
    const bool1 = data_view(memory).getUint8(ret + 0, true);
    const ptr2 = data_view(memory).getInt32(ret + 4, true);
    const len2 = data_view(memory).getInt32(ret + 8, true);
    const list2 = UTF8_DECODER.decode(new Uint8Array(memory.buffer, ptr2, len2));
    free(ptr2, len2, 1);
    return {
      isValid: bool1 == 0 ? false : (bool1 == 1 ? true : throw_invalid_bool()),
      errorMessage: list2,
    };
  }
}

module.exports = { Polyvalid };