Skip to content

Bytes.fromString

Encodes a string into Bytes.Bytes.

Imports

Named
import { Bytes } from 'ox'

Examples

import { Bytes } from 'ox'
 
const data = Bytes.fromString('Hello world!')
Uint8Array([72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100, 33])
import { Bytes } from 'ox'
 
const data = Bytes.fromString('Hello world!', { size: 32 })
Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])

Definition

function fromString(
  value: string,
  options?: fromString.Options,
): Bytes

Source: src/Bytes.ts

Parameters

value

  • Type: string

String to encode.

options

  • Type: fromString.Options
  • Optional

Encoding options.

options.size

  • Type: number
  • Optional

Size of the output bytes.

Return Type

Encoded Bytes.Bytes.

Bytes