UNPKG

asn1-ts

Version:

ASN.1 encoding and decoding, including BER, CER, and DER.

12 lines (11 loc) 443 B
import { ASN1Error } from "../errors.mjs"; import { Buffer } from "node:buffer"; export default function convertTextToBytes(text, codec = "utf-8") { if (typeof TextEncoder !== "undefined") { return (new TextEncoder()).encode(text); } else if (typeof Buffer !== "undefined") { return Buffer.from(text, codec); } throw new ASN1Error("Neither TextEncoder nor Buffer are defined to encode text into bytes."); }