# endian-code

> Encodes and decodes numbers of given size in big and little endian.

Latest version **1.0.5** (published 2018-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install endian-code
pnpm add endian-code
yarn add endian-code
bun add endian-code
```

## 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.5 |
| Published | 2018-10-08 |
| First published | 2018-08-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Emre Tapci |
| Maintainers | emretapci |
| Keywords | little, big, endian, encode, decode |

## Links

- npm: https://www.npmjs.com/package/endian-code
- Repository: https://github.com/emretapci/endian-code
- Homepage: https://github.com/emretapci/endian-code#readme
- Issues: https://github.com/emretapci/endian-code/issues
- npm.io page: https://npm.io/package/endian-code

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M 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
- [datasets-fi-postalcodes](https://npm.io/package/datasets-fi-postalcodes.md) — 1.1K weekly downloads

## Recent versions

- 1.0.5 (latest) — 2018-10-08
- 1.0.4 — 2018-08-15
- 1.0.3 — 2018-08-15
- 1.0.2 — 2018-08-15
- 1.0.1 — 2018-08-15
- 1.0.0 — 2018-08-07

## README

# endian-code
Copyright (C) 2018 Emre Tapci.  
NodeJS module for encoding and decoding numbers of given size in big and little endian.  
https://github.com/emretapci/endian-code

## install
```
npm install --save endian-code
```

## API
```
const endianCode = require('endian-code');

/*
 encode() params:
  n: number to be encoded
  size: number's size in bytes
  bigEndian: true for big endian, false for little endian
*/
console.log(endianCode.encode(0x1234, 2, true).map(x => x.toString(16))); //outputs [ '12', '34' ]
console.log(endianCode.encode(0x1234, 4, true).map(x => x.toString(16))); //outputs [ '0', '0', '12', '34' ]
console.log(endianCode.encode(0x1234, 8, true).map(x => x.toString(16))); //outputs [ '0', '0', '0', '0', '0', '0', '12', '34' ]

console.log(endianCode.encode(0x1234, 2, false).map(x => x.toString(16))); //outputs [ '34', '12' ]
console.log(endianCode.encode(0x1234, 4, false).map(x => x.toString(16))); //outputs [ '34', '12', '0', '0' ]
console.log(endianCode.encode(0x1234, 8, false).map(x => x.toString(16))); //outputs [ '34', '12', '0', '0', '0', '0', '0', '0' ]


/*
 decode() params:
  array: array or buffer to be decoded
  size: number's size in bytes
  bigEndian: true for big endian, false for little endian
*/
console.log(endianCode.decode([0x12, 0x34], 2, true).toString(16)); //outputs 1234
console.log(endianCode.decode([0x12, 0x34], 4, true).toString(16)); //outputs 12340000
console.log(endianCode.decode([0x12, 0x34], 8, true).toString(16)); //outputs 1234000000000000

console.log(endianCode.decode([0x34, 0x12], 2, false).toString(16)); //outputs 1234
console.log(endianCode.decode([0x34, 0x12], 4, false).toString(16)); //outputs 1234
console.log(endianCode.decode([0x34, 0x12], 8, false).toString(16)); //outputs 1234
```

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