Skip to content

Commit

Permalink
fix: use ArrayBufferLike type for return types
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Mar 26, 2024
1 parent 4ffbf37 commit 81feabb
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/data-types/array-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const assertArrayBuffer = (input: unknown) =>
* @group ArrayBuffer
*/
export function arrayBufferToBlob(
arrayBuffer: ArrayBufferLike,
arrayBuffer: ArrayBuffer,
options?: BlobPropertyBag,
): Blob {
assertArrayBuffer(arrayBuffer);
Expand Down Expand Up @@ -69,7 +69,7 @@ export function arrayBufferToReadableStream(
* @group ArrayBuffer
*/
export function arrayBufferToResponse(
arrayBuffer: ArrayBufferLike,
arrayBuffer: ArrayBuffer,
init?: ResponseInit,
): Response {
assertArrayBuffer(arrayBuffer);
Expand All @@ -80,7 +80,7 @@ export function arrayBufferToResponse(
* Convert from [ArrayBuffer][ArrayBuffer] to [String][String]
* @group ArrayBuffer
*/
export function arrayBufferToString(arrayBuffer: ArrayBufferLike): string {
export function arrayBufferToString(arrayBuffer: ArrayBuffer): string {
assertArrayBuffer(arrayBuffer);
return new TextDecoder().decode(arrayBuffer);
}
Expand Down
4 changes: 3 additions & 1 deletion src/data-types/number-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export const assertNumberArray = (input: unknown) =>
* Convert from [Number Array][Number Array] to [ArrayBuffer][ArrayBuffer]
* @group NumberArray
*/
export function numberArrayToArrayBuffer(numberArray: number[]): ArrayBuffer {
export function numberArrayToArrayBuffer(
numberArray: number[],
): ArrayBufferLike {
return new Uint8Array(numberArray).buffer;
}

Expand Down
2 changes: 1 addition & 1 deletion src/data-types/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const assertString = (input: unknown) =>
* Convert from [string][string] to [ArrayBuffer][ArrayBuffer]
* @group String
*/
export function stringToArrayBuffer(string: string): ArrayBuffer {
export function stringToArrayBuffer(string: string): ArrayBufferLike {
assertString(string);
return new TextEncoder().encode(string).buffer;
}
Expand Down
4 changes: 3 additions & 1 deletion src/data-types/uint8-array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const assertUint8Array = (input: unknown) =>
* Convert from [Uint8Array][Uint8Array] to [ArrayBuffer][ArrayBuffer]
* @group Uint8Array
*/
export function uint8ArrayToArrayBuffer(uint8Array: Uint8Array): ArrayBuffer {
export function uint8ArrayToArrayBuffer(
uint8Array: Uint8Array,
): ArrayBufferLike {
return uint8Array.buffer;
}

Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export type DataTypeName =

export type DataType =
| ArrayBuffer
| ArrayBufferLike
| Blob
| DataView
| number[]
Expand Down

0 comments on commit 81feabb

Please sign in to comment.