@mainframe/utils-hex

Hex encoding utilities

Usage no npm install needed!

<script type="module">
  import mainframeUtilsHex from 'https://cdn.skypack.dev/@mainframe/utils-hex';
</script>

README

utils-hex

Utilities for hexadecimal-encoded strings.

Installation

yarn add @mainframe/utils-hex

Usage

import { encodeHex, decodeHex } from 'utils-hex'

const encoded = encodeHex('hello')
const decoded = decodeHex(encoded) // 'hello'

Types

hex

Opaque type representing an hexadecimal-encoded string prefixed with 0x

API

hexType()

Simple identity function casting the provided value as hex to properly type-check.

Arguments

  1. value: any

Returns hex

hexEmpty

Returns 0x value with hex type.

encodeHex()

Arguments

  1. input: string
  2. from?: buffer$Encoding = 'utf8'

Returns hex

decodeHex()

Arguments

  1. input: hex
  2. to?: buffer$Encoding = 'utf8'

Returns string

License

MIT