# hex-frame-parser

> Encode & decode hexadecimal frames with ease

Latest version **1.0.2** (published 2019-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install hex-frame-parser
pnpm add hex-frame-parser
yarn add hex-frame-parser
bun add hex-frame-parser
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-02-28 |
| First published | 2019-02-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 83.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | adechassey |
| Keywords | encode, decode, hexadecimal, frames, radio, iot, sigfox, lpwan |

## Links

- npm: https://www.npmjs.com/package/hex-frame-parser
- Repository: https://github.com/AntoinedeChassey/hex-frame-parser
- npm.io page: https://npm.io/package/hex-frame-parser

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-02-28
- 1.0.1 — 2019-02-28
- 1.0.0 — 2019-02-26

## README

# Hexadecimal frame parser ![npm](https://img.shields.io/npm/v/hex-frame-parser.svg) ![npm bundle size](https://img.shields.io/bundlephobia/min/hex-frame-parser.svg)

Encode & decode hexadecimal frames with ease

## Install

```
$ npm install --save hex-frame-parser
```

## Usage

```js
const Decoder = require('hex-frame-parser').Decoder;
const DecoderProperty = require('hex-frame-parser').DecoderProperty;

// Objects
const decoder = new Decoder('47c85d800f03'); // the hexadecimal frame to decode

// Define the syntax (bitStartPos, bitEndPos, key, type, unit, add, subtract, divide, multiply)
decoder.decoderProperties.push(new DecoderProperty(0, 32, false, 'pressure', 'float', 'hPa', null, null, 100, null));

// See the result
console.log(decoder.decode());
```

## Properties

- `bitStartPos`: *Number* defines the position of the starting bit to decode
- `bitEndPos`: *Number* defines the position of the ending bit to decode
- `isSigned`: *Boolean* defines if the data is signed or unsigned
- `key`: *String* defines the name of the data to decode
- `type`: *String* defines the type of the data to decode _**(see below for usable types)**_
- `unit`: *String* defines the unit of the data to decode
- `add`: *Number* defines the number to add to the data
- `subtract`: *Number* defines the number to subtract to the data
- `multiply`: *Number* defines the number to multiply to the data
- `divide`: *Number* defines the number to divide to the data

### Types _(32bits architecture)_

`type` can be:
- `char`
- `short`
- `int`
- `long`
- `float`
- `bool`

## Examples

```js
const Decoder = require('hex-frame-parser').Decoder;
const DecoderProperty = require('hex-frame-parser').DecoderProperty;

// #1
const decoder_1 = new Decoder('47c85d800f03');
decoder_1.decoderProperties.push(new DecoderProperty(0, 32, false, 'pressure', 'float', 'hPa', null, null, null, 100));
decoder_1.decoderProperties.push(new DecoderProperty(8, 16, false, 'humidity', 'int', '%'));
console.log(decoder_1.decode());

// #2
const decoder_2 = new Decoder('b6096249');
decoder_2.decoderProperties.push(new DecoderProperty(8, 13, false, 'mode', 'bool', ''));
console.log(decoder_2.decode());

// #3
const decoder_3 = new Decoder('1a00bd4aa5181d');
decoder_3.decoderProperties.push(new DecoderProperty(8, 24, true, 'temperature', 'int', '°C', null, null, null, 8));
decoder_3.decoderProperties.push(new DecoderProperty(24, 32, false, 'humidity', 'int', '%',  null, null, null, 2));
console.log(decoder_3.decode());

// #4
const decoder_4 = new Decoder('32b641e0224484');
decoder_4.decoderProperties.push(new DecoderProperty(4, 13, true, 'temperature', 'int', '°C',  null, null, 0.25, null));
console.log(decoder_4.decode());
```

---
_Source: https://npm.io/package/hex-frame-parser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
