Skip to content

Commit

Permalink
chore: add explicit types
Browse files Browse the repository at this point in the history
Signed-off-by: Okiki <okikio.dev@gmail.com>
  • Loading branch information
okikio committed Feb 21, 2024
1 parent 347c1ce commit a5946fd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions byte_methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
* @param byte - The lead byte of a UTF-8 character.
* @returns The number of bytes in a Uint8Array required to represent the UTF-8 character (the number of bytes ranges from 1 to 4).
*/
export function getByteLength(byte: number) {
export function getByteLength(byte: number): number {
return (
byte < LEAD_FOR_1B ? 1 :
LEAD_FOR_2B === (LEAD_FOR_3B & byte) ? 2 :
Expand Down Expand Up @@ -54,7 +54,7 @@ export function getByteLength(byte: number) {
* @param [bytes] - An array of length `byteLength` bytes that make up the UTF-8 character.
* @returns The Unicode code point of the UTF-8 character.
*/
export function bytesToCodePoint(byteLength: number, [byte1, byte2, byte3, byte4]: number[]) {
export function bytesToCodePoint(byteLength: number, [byte1, byte2, byte3, byte4]: number[]): number {
return (
// 1-byte UTF-8 sequence
byteLength === 1 ?
Expand Down Expand Up @@ -131,7 +131,7 @@ export function bytesToCodePointFromBuffer<T extends number = number>(
* @param index - The position in the string to extract the code point from.
* @returns A number represent the code point in UTF-16 code units.
*/
export function codePointAt(str: string, index: number) {
export function codePointAt(str: string, index: number): number {
const size = str.length;

// Account for out-of-bounds indices:
Expand Down
2 changes: 1 addition & 1 deletion iterable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @param stream ReadableStream to convert into async iterable
*/
export async function* getIterableStream<T = Uint8Array>(stream: ReadableStream<T>) {
export async function* getIterableStream<T = Uint8Array>(stream: ReadableStream<T>): AsyncIterable<T> {
const reader = stream.getReader();
try {
while (true) {
Expand Down
4 changes: 2 additions & 2 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
export async function* asCodePointsIterator<T extends Uint8Array>(
iterable: AsyncIterable<T> | Iterable<T>
) {
): AsyncIterable<number> {
const utf8Decoder = new TextDecoder("utf-8");

// Create an async iterator from the source (works for both async and sync iterables).
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function* asCodePointsIterator<T extends Uint8Array>(
*/
export async function asCodePointsArray<T extends Uint8Array>(
iterable: AsyncIterable<T> | Iterable<T>
) {
): Promise<number> {
const arr: number[] = [];
const utf8Decoder = new TextDecoder("utf-8");

Expand Down

0 comments on commit a5946fd

Please sign in to comment.