Skip to content

Base64.fromString

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

Imports

Named
import { Base64 } from 'ox'

Examples

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

No Padding

Turn off padding of encoded data with the pad option:

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

URL-safe Encoding

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

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

Definition

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

Source: src/Base64.ts

Parameters

value

  • Type: string

The string to encode.

options

  • Type: fromString.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