{"id":17045459,"url":"https://github.com/ballercat/wasm-utils","last_synced_at":"2025-10-14T09:14:15.390Z","repository":{"id":141203596,"uuid":"85409415","full_name":"ballercat/wasm-utils","owner":"ballercat","description":"WASM JavaScript Utils","archived":false,"fork":false,"pushed_at":"2017-04-30T16:05:31.000Z","size":9,"stargazers_count":20,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-24T12:50:26.367Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ballercat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-03-18T14:58:27.000Z","updated_at":"2023-05-11T15:14:52.000Z","dependencies_parsed_at":"2024-06-14T14:17:55.150Z","dependency_job_id":null,"html_url":"https://github.com/ballercat/wasm-utils","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ballercat/wasm-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ballercat","download_url":"https://codeload.github.com/ballercat/wasm-utils/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ballercat%2Fwasm-utils/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018499,"owners_count":26086383,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T09:37:29.239Z","updated_at":"2025-10-14T09:14:15.383Z","avatar_url":"https://github.com/ballercat.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# WASM JavaScript Utils\n\nA tiny modular collection of JavaScript Utils for use with WASM Modules.\n\n### Deps to use with a wasm module Instance:\n\n* `logger` - Logs strings from WASM  code.\n* `stack` - Stack\n* `heap` - JavaScript implementation of malloc, free to pass into wasm.\n* `types` - Helper methods for seamless mapping of JS object to WASM memory\n\n\n#### Types\n\nThe types module provides a method of mapping a JavaScript object to a section of WASM memory. Allowing you to set and get values from a memory buffer seamlessly.\n\n* `types.define(typedef) -\u003e struct(DataView)`\n  - Param: `typedef` - Object where keys are mapped to low level C-like typedefs\n  - Returns: `struct(DataView)` - A new typedef which can be attached to a generic DataView object.\n    + `struct.size` - Size of the defined struct in bytes.\n\n  - Example:\n\n    Assuming you already have a wasm module setup:\n\n    ```javascript\n    // let's say you have a wasm function which creates a new pointer to C struct\n    // This struct contains { float x; float y; float z; }\n    const ptr = wasmExports.createVec3(-1, -1, -1);\n\n    // You can create a new Object in JavaScript to access the data pointed to by the pointer\n    const vec3Struct = types.define({\n      x: types.f32,\n      y: types.f32,\n      z: types.f32\n    });\n\n    // vec3Struct can now map to a 12 continues bytes in our memory buffer\n    console.log(vec3Struct.size); // 12\n\n    // Create a DataView to access the data within wasmMemory.buffer\n    const vec3Dataview = new DataView(wasMemory.buffer, ptr, vec3Struct.size);\n\n    const myVector = vec3Struct(vec3DataView);\n\n    console.log(myVector.x); // -1\n    console.log(myVector.y); // -1\n    console.log(myVector.z); // -1\n\n    // WASM changes will reflect in our JS struct\n    wasmExports.setVec3X(ptr, 128);\n\n    console.log(myVector.x); // 128\n\n    // ... and vice-versa\n    myVector.y = 100;\n\n    wasmExports.logVec3Y(ptr); // 100\n    ```\n    *structs can be nested*:\n\n    ```javascript\n    const objectStruct = types.define({\n      value: types.u32, // unsigned 32 bit integer\n      position: vec3Struct\n    });\n\n    console.log(objectStruct.size); // 16\n\n    // Let's say this wasm function returns a pointer to object with position set to 100, 100, 0\n    const objPtr = wasmExports.createObject();\n\n    // ... we create the dataView etc.,\n\n    const myObject = objectStruct(objectDataView);\n\n    console.log(myObject.position.x); // 100\n    console.log(myObject.position.y); // 100\n    console.log(myObject.position.z); // 0\n    ```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fballercat%2Fwasm-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fballercat%2Fwasm-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fballercat%2Fwasm-utils/lists"}