JSPM

hex-array

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5232
  • Score
    100M100P100Q117221F
  • License MIT

Create Uint8Array buffers from hexadecimal strings, and vice versa.

Package Exports

  • hex-array

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (hex-array) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

hex-array

Creates Uint8Array buffers from hexadecimal strings, and vice versa.

Installation

npm install hex-array

Usage

  var hexarray = require('hex-array');
  hexarray.toString(new Uint8Array([0xc9, 0x13, 0x4b, 0xca,
                                    0x6a, 0x49, 0xfc, 0xf8,
                                    0x2d, 0x30, 0x3b, 0x4e,
                                    0xa0, 0x26, 0x3a, 0xd8]);
  // = C9134BCA6A49FCF82D303B4EA0263AD8

  hexarray.fromString("C9134BCA6A49FCF82D303B4EA0263AD8");     
  // = Uint8Array [ 201, 19, 75, 202, 106, 73, 252, 248, 45, 48, 59, 78, 160, 38, 58, 216 ]

Methods

hexarray.toString(array, [options])

converts the given buffer to a string containing its hexadecimal representation.

array a Uint8Array buffer to convert.

options an optional object with the following members:

  • grouping this number of hex bytes are grouped together with spaces between groups. 0 means no grouping is applied. 0 if unspecified.

  • rowlength the number of groups which make up a row. When 0, no splitting into rows occurs. 0 if unspecified.

  • uppercase if true, the output will be in uppercase. true by default.

return a hexadecimal string representing the buffer.

hexarray.fromString(string)

takes a string containing hexadecimal and returns the equivalent as a Uint8Array buffer.

string The string to convert. Whitespace is ignored. If an odd number of characters are specified, it will act as if preceeded with a leading 0; that is, "FFF" is equivalent to "0FFF".

return a Uint8Array array.

Tests

npm test