Skip to content

Base64.fromHex

Encodes a Hex.Hex to a Base64-encoded string (with optional padding and/or URL-safe characters).

Imports

Named
import { Base64 } from 'ox'

Examples

import { Base64, Hex } from 'ox'
 
const value = Base64.fromHex(Hex.fromString('hello world'))
'aGVsbG8gd29ybGQ='

No Padding

Turn off padding of encoded data with the pad option:

import { Base64, Hex } from 'ox'
 
const value = Base64.fromHex(Hex.fromString('hello world'), { pad: false })
'aGVsbG8gd29ybGQ'

URL-safe Encoding

Turn on URL-safe encoding (Base64 URL) with the url option:

import { Base64, Hex } from 'ox'
 
const value = Base64.fromHex(Hex.fromString('hello wod'), { url: true })
'aGVsbG8gd29_77-9ZA=='

Definition

function fromHex(
  value: Hex.Hex,
  options?: fromHex.Options,
): string

Source: src/Base64.ts

Parameters

value

  • Type: Hex.Hex

The hex value to encode.

options

  • Type: fromHex.Options
  • Optional

Encoding options.

options.pad

  • Type: boolean
  • Optional

Whether to pad the Base64 encoded string.

options.url

  • Type: boolean
  • Optional

Whether to Base64 encode with URL safe characters.

Return Type

The Base64 encoded string.

string