Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/uint8array/index.ts>default

A JavaScript extension package for building strong and modern applications.
Latest
function default
import { default } from "https://deno.land/x/ayonli_jsext@v0.9.72/uint8array/index.ts";

Converts the given data to a byte array.

Examples

Example 1

import bytes from "@ayonli/jsext/bytes";

const arr = bytes("Hello, World!");

console.log(arr);
// ByteArray(13) [Uint8Array] [ 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33 ]

console.log(String(arr)); // "Hello, World!"

// from hex
const arr2 = bytes("48656c6c6f2c20576f726c6421", "hex");

// from base64
const arr3 = bytes("SGVsbG8sIFdvcmxkIQ==", "base64");

Parameters

str: string
optional
encoding: "utf8" | "hex" | "base64"

Parameters

arr:
| string
| ArrayBufferLike
| ArrayBufferView
| ArrayLike<number>

Creates a byte array with the specified length.

Examples

Example 1

import bytes from "@ayonli/jsext/bytes";

const arr = bytes(10);

console.log(arr);
// ByteArray(10) [Uint8Array] [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

Parameters

length: number