~bradclawsie/textras

7f099f85073285773ef27ec21affd6a2cb99c0a2 — Brad Clawsie 9 months ago 5d15680
std 0.208.0: eliminate deprecated encode apis
3 files changed, 7 insertions(+), 34 deletions(-)

M README.md
M mod.ts
M test.ts
M README.md => README.md +1 -28
@@ 17,47 17,20 @@ import * as textras from "https://deno.land/x/textras/mod.ts";
const bytesToHex: (d: Uint8Array) => string
  convert a byte array to its hex string encoding

  @param {Uint8Array} d
      - the input byte array

  @return {string}
      the hex string encoding of d


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

  @param {Uint8Array} d
      - the input byte array

  @return {string}
      the string representation of s


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

  @param {string} s
      - the input hex string

  @return {Uint8Array}
      the hex-decoded byte array representation of s


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

  @param {string} s
      - the input string

  @return {Uint8Array}
      the byte array representation of s
```

## example

```ts
import { assertEquals } from "https://deno.land/std@0.178.0/testing/asserts.ts";
import { assertEquals } from "https://deno.land/std@0.208.0/testing/asserts.ts";
import {
  bytesToHex,
  bytesToString,

M mod.ts => mod.ts +5 -5
@@ 1,7 1,7 @@
import {
  decode as hexDecode,
  encode as hexEncode,
} from "https://deno.land/std@0.200.0/encoding/hex.ts";
  decodeHex,
  encodeHex,
} from "https://deno.land/std@0.208.0/encoding/hex.ts";

/**
 * convert a string to its byte array representation


@@ 22,13 22,13 @@ const bytesToString = (d: Uint8Array): string => new TextDecoder().decode(d);
 * @param {Uint8Array} d - the input byte array
 * @returns {string} the hex string encoding of d
 */
const bytesToHex = (d: Uint8Array): string => bytesToString(hexEncode(d));
const bytesToHex = (d: Uint8Array): string => encodeHex(d);

/**
 * convert a hex string to its byte array representation
 * @param {string} s - the input hex string
 * @returns {Uint8Array} the hex-decoded byte array representation of s
 */
const hexToBytes = (s: string): Uint8Array => hexDecode(stringToBytes(s));
const hexToBytes = (s: string): Uint8Array => decodeHex(s);

export { bytesToHex, bytesToString, hexToBytes, stringToBytes };

M test.ts => test.ts +1 -1
@@ 1,4 1,4 @@
import { assertEquals } from "https://deno.land/std@0.200.0/assert/mod.ts";
import { assertEquals } from "https://deno.land/std@0.208.0/assert/mod.ts";
import { bytesToHex, bytesToString, hexToBytes, stringToBytes } from "./mod.ts";

Deno.test("round trip hex value", () => {