~bradclawsie/textras

Text wrangling Typescript utilities
github ci deno version update
std 0.208.0: eliminate deprecated encode apis
std to 0.200.0; fix assertEquals ref

clone

read-only
https://git.sr.ht/~bradclawsie/textras
read/write
git@git.sr.ht:~bradclawsie/textras

You can also use your local clone with git send-email.

#textras

Text wrangling Typescript utilities

License:MIT ci

#import

import * as textras from "https://deno.land/x/textras/mod.ts";

#exported fuctions

const bytesToHex: (d: Uint8Array) => string
  convert a byte array to its hex string encoding

const bytesToString: (d: Uint8Array) => string
  convert a byte array to its string representation

const hexToBytes: (s: string) => Uint8Array
  convert a hex string to its byte array representation

const stringToBytes: (s: string) => Uint8Array
  convert a string to its byte array representation

#example

import { assertEquals } from "https://deno.land/std@0.208.0/testing/asserts.ts";
import {
  bytesToHex,
  bytesToString,
  hexToBytes,
  stringToBytes,
} from "https://deno.land/x/textras/mod.ts";

// round trip a string to hex and back again
const s = "hello world";
const h = bytesToHex(stringToBytes(s));
assertEquals(h, "68656c6c6f20776f726c64", "hex value");
assertEquals(bytesToString(hexToBytes(h)), s, "round trip");