{"_id":"@busyexplore/zotonic-audio-util","_rev":"3-dce8c613be0998f5c9031a6f4f3485c7","name":"@busyexplore/zotonic-audio-util","dist-tags":{"latest":"0.0.1-beta.2"},"versions":{"0.0.1-beta.0":{"name":"@busyexplore/zotonic-audio-util","version":"0.0.1-beta.0","_id":"@busyexplore/zotonic-audio-util@0.0.1-beta.0","maintainers":[{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"}],"dist":{"shasum":"e3eb4823d0712ae408b29886696c2d71c7eba958","tarball":"https://registry.npmjs.org/@busyexplore/zotonic-audio-util/-/zotonic-audio-util-0.0.1-beta.0.tgz","fileCount":4,"integrity":"sha512-IlgZJSCMmCR9/iX2ABqPA4alcgSMy0BC+gLyElUaaZgR/nd1btQu589vICvpctldNT6o/PA81OpeXCeL/eUvdA==","signatures":[{"sig":"MEQCICRqfSef0BoInhxpZuXjonQbk5fJ7ak4oRheq+uwq4/eAiAGFzDAGyyv0lyFTSZgi9LSmNXgVokyQZFiMfafDJZQIw==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8075},"main":"dist/zotonic-audio-util.umd.js","type":"module","module":"dist/zotonic-audio-util.es.js","gitHead":"70b3961b7709bde6bd2dbbcb6269802746dd88e1","private":false,"scripts":{"dev":"set NODE_OPTIONS=--openssl-legacy-provider && vite","lint":"eslint .","build":"vite build","deploy":"npm version prerelease --preid=beta --no-git-tag-version && npm publish --tag beta","preview":"vite preview"},"_npmUser":{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"},"_npmVersion":"10.1.0","description":"A tiny utility for normalizing different binary input types (URLs, `Request` objects, `Blob`/`File`, `Buffer`, `ArrayBuffer`, typed arrays) into a single `ArrayBuffer`, wrapped in a small object with safe accessors.","directories":{},"_nodeVersion":"20.9.0","dependencies":{"react":"^16.8 || ^17 || ^18","react-dom":"^16.8 || ^17 || ^18"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.3.5","eslint":"^9.29.0","globals":"^16.2.0","@eslint/js":"^9.29.0","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","@vitejs/plugin-react":"^4.6.0","eslint-plugin-react-hooks":"^5.2.0","eslint-plugin-react-refresh":"^0.4.20"},"peerDependencies":{"react":"^16.8 || ^17 || ^18","react-dom":"^16.8 || ^17 || ^18"},"_npmOperationalInternal":{"tmp":"tmp/zotonic-audio-util_0.0.1-beta.0_1786990232934_0.9503555108595303","host":"s3://npm-registry-packages-npm-production"}},"0.0.1-beta.1":{"name":"@busyexplore/zotonic-audio-util","version":"0.0.1-beta.1","_id":"@busyexplore/zotonic-audio-util@0.0.1-beta.1","maintainers":[{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"}],"dist":{"shasum":"cb03ca7e3f506c2a1a30bada286776727dae53a0","tarball":"https://registry.npmjs.org/@busyexplore/zotonic-audio-util/-/zotonic-audio-util-0.0.1-beta.1.tgz","fileCount":4,"integrity":"sha512-8zMi30b+umTQc3NPJyfp1zzYh4CC9vWjD1ixqdAgK+881tYEKljHSZxKi4fgt5/7OlmHuAa3cqcqeOR6sKVi8w==","signatures":[{"sig":"MEYCIQDUMDS/hEVEX2dz33J39rN72q3/V7Pxeq78h2dUJ602kQIhALOO0FoevBH0mdJfF56XJQaOyLq9MbI9R/B1ec9vnmtU","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":8075},"main":"dist/zotonic-audio-util.es.js","type":"module","module":"dist/zotonic-audio-util.umd.js","gitHead":"94d43a2f8c946a36b25f00dac4516c3a51de7d17","private":false,"scripts":{"dev":"set NODE_OPTIONS=--openssl-legacy-provider && vite","lint":"eslint .","build":"vite build","deploy":"npm version prerelease --preid=beta --no-git-tag-version && npm publish --tag beta","preview":"vite preview"},"_npmUser":{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"},"_npmVersion":"10.1.0","description":"A tiny utility for normalizing different binary input types (URLs, `Request` objects, `Blob`/`File`, `Buffer`, `ArrayBuffer`, typed arrays) into a single `ArrayBuffer`, wrapped in a small object with safe accessors.","directories":{},"_nodeVersion":"20.9.0","dependencies":{"react":"^16.8 || ^17 || ^18","react-dom":"^16.8 || ^17 || ^18"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^6.3.5","eslint":"^9.29.0","globals":"^16.2.0","@eslint/js":"^9.29.0","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","@vitejs/plugin-react":"^4.6.0","eslint-plugin-react-hooks":"^5.2.0","eslint-plugin-react-refresh":"^0.4.20"},"peerDependencies":{"react":"^16.8 || ^17 || ^18","react-dom":"^16.8 || ^17 || ^18"},"_npmOperationalInternal":{"tmp":"tmp/zotonic-audio-util_0.0.1-beta.1_1786990408876_0.4096688288739567","host":"s3://npm-registry-packages-npm-production"}},"0.0.1-beta.2":{"name":"@busyexplore/zotonic-audio-util","private":false,"version":"0.0.1-beta.2","type":"module","main":"dist/zotonic-audio-util.es.js","module":"dist/zotonic-audio-util.umd.js","scripts":{"dev":"set NODE_OPTIONS=--openssl-legacy-provider && vite","build":"vite build","lint":"eslint .","preview":"vite preview","deploy":"npm version prerelease --preid=beta --no-git-tag-version && npm publish --tag beta"},"dependencies":{"react":"^16.8 || ^17 || ^18","react-dom":"^16.8 || ^17 || ^18"},"peerDependencies":{"react":"^16.8 || ^17 || ^18","react-dom":"^16.8 || ^17 || ^18"},"devDependencies":{"@eslint/js":"^9.29.0","@types/react":"^19.1.8","@types/react-dom":"^19.1.6","@vitejs/plugin-react":"^4.6.0","eslint":"^9.29.0","eslint-plugin-react-hooks":"^5.2.0","eslint-plugin-react-refresh":"^0.4.20","globals":"^16.2.0","vite":"^6.3.5"},"_id":"@busyexplore/zotonic-audio-util@0.0.1-beta.2","gitHead":"2cfef0b5a82e02fb0a300bb6d8e6eb4a52c13134","description":"A tiny utility for normalizing different binary input types (URLs, `Request` objects, `Blob`/`File`, `Buffer`, `ArrayBuffer`, typed arrays) into a single `ArrayBuffer`, wrapped in a small object with safe accessors.","_nodeVersion":"20.9.0","_npmVersion":"10.1.0","dist":{"integrity":"sha512-ehaloL6QGCf2Vo2g6XHmWJk1RtBoNqsAdYC5oPPphsX2iT0O6L9fpwp9YDM+GaRfB5iu1vYSH9UkUCFqglB6wA==","shasum":"366b2c9cef73fdee326b1d9557bd639a3bd19e81","tarball":"https://registry.npmjs.org/@busyexplore/zotonic-audio-util/-/zotonic-audio-util-0.0.1-beta.2.tgz","fileCount":4,"unpackedSize":8164,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQCYS1y/Ucf+n1t3xkJmq1kdCkCcKqoSSPv6Lf5RfI7o8wIgHvJVONCudorkNPkYAKySqUxBLtfFMSUZaHW9VDtLAnk="}]},"_npmUser":{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"},"directories":{},"maintainers":[{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/zotonic-audio-util_0.0.1-beta.2_1786990693106_0.47351728987682296"},"_hasShrinkwrap":false}},"time":{"created":"2026-08-17T18:10:32.757Z","modified":"2026-08-17T18:18:13.474Z","0.0.1-beta.0":"2026-08-17T18:10:33.078Z","0.0.1-beta.1":"2026-08-17T18:13:29.031Z","0.0.1-beta.2":"2026-08-17T18:18:13.280Z"},"description":"A tiny utility for normalizing different binary input types (URLs, `Request` objects, `Blob`/`File`, `Buffer`, `ArrayBuffer`, typed arrays) into a single `ArrayBuffer`, wrapped in a small object with safe accessors.","maintainers":[{"name":"busyexplore","email":"suprise.mlimi97@gmail.com"}],"readme":"# zotonicAudioUtil\n\nA tiny utility for normalizing different binary input types (URLs, `Request` objects, `Blob`/`File`, `Buffer`, `ArrayBuffer`, typed arrays) into a single `ArrayBuffer`, wrapped in a small object with safe accessors.\n\n## Features\n\n* Accepts a wide range of input types: strings/URLs, `Request`, `Blob`/`File`, Node `Buffer`, `ArrayBuffer`, and any `ArrayBuffer` view (e.g. `Uint8Array`)\n* Fetches remote resources automatically when given a URL or `Request`\n* Returns a lightweight wrapper object with `buffer`, `clone()`, and `free()`\n* Throws clear, descriptive errors for missing or unsupported input\n* Works in a browser \n\n## Installation\n\n```bash\nnpm install @busyexplore/zotonic-audio-util\n```\n\nOr with Yarn:\n\n```bash\nyarn add @busyexplore/zotonic-audio-util\n```\n\n## Usage\n\n```js\nimport { zotonicAudioUtil } from '@busyexplore/zotonic-audio-util';\n\n// From a URL\nconst fromUrl = await zotonicAudioUtil('https://example.com/audio.wav');\n\n// From a File input\nconst file = fileInput.files[0];\nconst fromFile = await zotonicAudioUtil(file);\n\n// From a Node Buffer\nconst fromBuffer = await zotonicAudioUtil(nodeBuffer);\n\nconsole.log(fromUrl.buffer); // ArrayBuffer\n```\n\n## API\n\n### `zotonicAudioUtil(input)`\n\nNormalizes `input` into an `ArrayBuffer` and returns a wrapper object.\n\n```js\nconst result = await zotonicAudioUtil(input);\n```\n\n#### Parameters\n\n| Parameter | Type                                                                    | Description                                     |\n| --------- | ------------------------------------------------------------------------| -------------------------------------------------|\n| `input`   | `string \\| Request \\| Blob \\| Buffer \\| ArrayBuffer \\| ArrayBufferView` | The source to normalize into an `ArrayBuffer`.   |\n\n#### Returns\n\nA `Promise` resolving to an object with:\n\n##### `buffer` (getter)\n\n```js\nresult.buffer\n```\n\nReturns the underlying `ArrayBuffer`, or `null` if `free()` has already been called.\n\n##### `clone()`\n\n```js\nconst copy = result.clone();\n```\n\nReturns a fresh copy (`ArrayBuffer.slice(0)`) of the buffer. Throws an `Error` if the buffer has already been freed.\n\n##### `free()`\n\n```js\nresult.free();\n```\n\nReleases the internal reference to the buffer (sets it to `null`), allowing it to be garbage collected. Subsequent calls to `clone()` will throw.\n\n## Supported Input Types\n\n### String or `Request`\n\nTreated as a fetchable resource. The utility calls `fetch()` internally and reads the response as an `ArrayBuffer`.\n\n```js\nawait zotonicAudioUtil('https://example.com/audio.mp3');\nawait zotonicAudioUtil(new Request('https://example.com/audio.mp3'));\n```\n\nIf the fetch fails (non-OK response), an `Error` is thrown containing the HTTP status and status text.\n\n### `Blob` / `File`\n\nAny object exposing an `arrayBuffer()` method (such as `Blob` or `File`) is handled directly.\n\n```js\nawait zotonicAudioUtil(someBlob);\n```\n\n### Node.js `Buffer`\n\nDetected via `Buffer.isBuffer()`. The underlying `ArrayBuffer` is sliced to match the `Buffer`'s byte range.\n\n```js\nawait zotonicAudioUtil(nodeBuffer);\n```\n\n### `ArrayBuffer`\n\nPassed through unchanged.\n\n```js\nawait zotonicAudioUtil(existingArrayBuffer);\n```\n\n### `ArrayBuffer` Views (Typed Arrays)\n\nAny typed array (`Uint8Array`, `Int16Array`, `Float32Array`, etc.) is sliced to its view's byte range.\n\n```js\nawait zotonicAudioUtil(new Uint8Array([1, 2, 3]));\n```\n\n## Error Handling\n\n| Condition                                   | Error Type   | Message                                              |\n| -------------------------------------------- | ------------ | ----------------------------------------------------- |\n| No input provided                            | `Error`      | `\"Input is required\"`                                  |\n| Fetch response not OK                        | `Error`      | `\"Failed to fetch resource: {status} {statusText}\"`     |\n| Unsupported input type                       | `TypeError`  | `\"Unsupported input type provided to toArrayBuffer\"`    |\n| `clone()` called after `free()`              | `Error`      | `\"Buffer has been freed\"`                               |\n\n## Memory Management\n\nBecause the returned object holds a reference to a potentially large `ArrayBuffer`, call `free()` once you're done with it to release the reference for garbage collection:\n\n```js\nconst result = await zotonicAudioUtil(input);\n\n// ... use result.buffer or result.clone() ...\n\nresult.free();\n```\n\nAfter `free()` is called, `result.buffer` returns `null` and `result.clone()` throws.\n\n## Notes\n\n* This utility does not decode or parse audio data — it only normalizes the input into a raw `ArrayBuffer`. Decoding (e.g. via `AudioContext.decodeAudioData`) is left to the consumer.\n* `clone()` returns a **copy** of the buffer, leaving the original buffer inside the wrapper untouched, so you can safely pass clones to code that may transfer or detach the buffer.\n\n<!-- ## License\n\nAdd the project's applicable license here. -->","readmeFilename":"README.md"}