A Node.js library for encoding and decoding text as Base64.
To install @localtools/base64, run the following command:
npm install @localtools/base64To use @localtools/base64, import the Base64 class and call its encode and decode methods:
import { Base64 } from '@localtools/base64';
const encodedText = Base64.encode({ text: 'hello world' });
console.log(encodedText); // Outputs: "aGVsbG8gd29ybGQ="
const decodedText = Base64.decode({ base64Text: encodedText });
console.log(decodedText); // Outputs: "hello world"The encode method takes an object with a text field, and returns the Base64 encoding of the text. The decode method takes an object with a base64Text field, and returns the text represented by the Base64 encoding.
Encodes a text string as a Base64 string.
args(EncodeArgs): An object with the following fields:text(string): The text to encode.encoding(string): The encoding to use. Defaults to'base64'.start(number): The index of the first character in the text to encode. Defaults to0.end(number): The index of the last character in the text to encode. Defaults totext.length.
A Base64-encoded string.
Decodes a Base64 string as a text string.
args(DecodeArgs): An object with the following fields:base64Text(string): The Base64 string to decode.fromEncoding(string): The encoding of the Base64 string. Defaults to'base64'.outputEncoding(string): The encoding to use for the output text. Defaults to'utf8'.
The text represented by the Base64 string.
Copyright © 2023 LocalTools.
This project is MIT licensed.