Socket
Socket
Sign inDemoInstall

endianness

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

endianness - npm Package Compare versions

Comparing version 6.0.0-alpha.2 to 6.0.0-alpha.3

4

CHANGELOG.md
# CHANGELOG
## version 6.0.0 (unreleased)
- **endianness** as a ES6 module: endianness.js
- **"main"** dist file is a UMD: endianness.umd.js
- **endianness** as a ES6 module
- Option to swap only a slice of the buffer

@@ -112,12 +112,15 @@ (function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap

* @param {number} offset The byte offset.
* @param {number=} start The start index. Assumes 0.
* @param {?number=} end The end index. Assumes the buffer length.
* @throws {Error} If the buffer length is not valid.
*/
function endianness(bytes, offset) {
let len = bytes.length;
function endianness(bytes, offset, start=0, end=null) {
let len = end || bytes.length;
let limit = parseInt(offset / 2, 10);
if (len % offset) {
throw new Error("Not enough bytes.");
throw new Error("Bad buffer length.");
}
let i = 0;
let i = start;
while (i < len) {
swap(bytes, offset, i);
swap(bytes, offset, i, limit);
i += offset;

@@ -134,6 +137,5 @@ }

*/
function swap(bytes, offset, index) {
function swap(bytes, offset, index, limit) {
let x = 0;
let y = offset - 1;
let limit = parseInt(offset / 2, 10);
while(x < limit) {

@@ -140,0 +142,0 @@ let theByte = bytes[index + x];

@@ -1,2 +0,2 @@

window.endianness=function(e){function b(a){if(d[a])return d[a].a;var c=d[a]={m:a,f:!1,a:{}};e[a].call(c.a,c,c.a,b);c.f=!0;return c.a}var d={};b.l=e;b.h=d;b.b=function(a,c){b.c(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:c})};b.i=function(a){var c=a&&a.g?function(){return a["default"]}:function(){return a};b.b(c,c);return c};b.c=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};b.j="";return b(b.o=0)}([function(e,b){Object.defineProperty(b,"__esModule",{value:!0});
b.endianness=function(b,a){var c=b.length;if(c%a)throw Error("Not enough bytes.");for(var d=0;d<c;){for(var f=b,g=d,h=0,e=a-1,k=parseInt(a/2,10);h<k;){var l=f[g+h];f[g+h]=f[g+e];f[g+e]=l;h++;e--}d+=a}}}]);
window.endianness=function(e){function c(a){if(d[a])return d[a].a;var b=d[a]={m:a,f:!1,a:{}};e[a].call(b.a,b,b.a,c);b.f=!0;return b.a}var d={};c.l=e;c.h=d;c.b=function(a,b){c.c(a)||Object.defineProperty(a,"a",{configurable:!1,enumerable:!0,get:b})};c.i=function(a){var b=a&&a.g?function(){return a["default"]}:function(){return a};c.b(b,b);return b};c.c=function(a){return Object.prototype.hasOwnProperty.call(a,"a")};c.j="";return c(c.o=0)}([function(e,c){Object.defineProperty(c,"__esModule",{value:!0});
c.endianness=function(c,a,b,f){f=(void 0===f?null:f)||c.length;var d=parseInt(a/2,10);if(f%a)throw Error("Bad buffer length.");for(b=void 0===b?0:b;b<f;){for(var g=c,h=b,e=d,k=0,l=a-1;k<e;){var m=g[h+k];g[h+k]=g[h+l];g[h+l]=m;k++;l--}b+=a}}}]);window["endianness"]=window["endianness"]["endianness"];

@@ -122,12 +122,15 @@ (function webpackUniversalModuleDefinition(root, factory) {

* @param {number} offset The byte offset.
* @param {number=} start The start index. Assumes 0.
* @param {?number=} end The end index. Assumes the buffer length.
* @throws {Error} If the buffer length is not valid.
*/
function endianness(bytes, offset) {
let len = bytes.length;
function endianness(bytes, offset, start=0, end=null) {
let len = end || bytes.length;
let limit = parseInt(offset / 2, 10);
if (len % offset) {
throw new Error("Not enough bytes.");
throw new Error("Bad buffer length.");
}
let i = 0;
let i = start;
while (i < len) {
swap(bytes, offset, i);
swap(bytes, offset, i, limit);
i += offset;

@@ -144,6 +147,5 @@ }

*/
function swap(bytes, offset, index) {
function swap(bytes, offset, index, limit) {
let x = 0;
let y = offset - 1;
let limit = parseInt(offset / 2, 10);
while(x < limit) {

@@ -150,0 +152,0 @@ let theByte = bytes[index + x];

@@ -40,12 +40,15 @@ /*

* @param {number} offset The byte offset.
* @param {number=} start The start index. Assumes 0.
* @param {?number=} end The end index. Assumes the buffer length.
* @throws {Error} If the buffer length is not valid.
*/
export function endianness(bytes, offset) {
let len = bytes.length;
export function endianness(bytes, offset, start=0, end=null) {
let len = end || bytes.length;
let limit = parseInt(offset / 2, 10);
if (len % offset) {
throw new Error("Not enough bytes.");
throw new Error("Bad buffer length.");
}
let i = 0;
let i = start;
while (i < len) {
swap(bytes, offset, i);
swap(bytes, offset, i, limit);
i += offset;

@@ -62,6 +65,5 @@ }

*/
function swap(bytes, offset, index) {
function swap(bytes, offset, index, limit) {
let x = 0;
let y = offset - 1;
let limit = parseInt(offset / 2, 10);
while(x < limit) {

@@ -68,0 +70,0 @@ let theByte = bytes[index + x];

{
"name": "endianness",
"version": "6.0.0-alpha.2",
"version": "6.0.0-alpha.3",
"description": "Swap endianness in byte arrays.",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/rochars/endianness",

@@ -18,2 +18,17 @@ # endianness

## Example
```javascript
const endianness = require("endianness").endianness;
// Swap endianness of one 64-bit value:
bytes = [64, 9, 33, 251, 84, 68, 45, 24];
endianness(bytes, 8);
console.log(bytes);
// Swap endianness of two 24-bit values:
bytes = ["00", "00", "80", "ff", "ff", "7f"];
endianness(bytes, 3),
console.log(bytes);
```
## Browser

@@ -32,18 +47,8 @@ Use the compiled file in the */dist* folder:

```html
<script src="https://cdn.jsdelivr.net/npm/endianness@5/dist/endianness.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/endianness@6"></script>
```
## Example
```javascript
const endianness = require("endianness");
// Swap endianness of one 64-bit value:
bytes = [64, 9, 33, 251, 84, 68, 45, 24];
endianness(bytes, 8);
console.log(bytes);
// Swap endianness of two 24-bit values:
bytes = ["00", "00", "80", "ff", "ff", "7f"];
endianness(bytes, 3),
console.log(bytes);
Or get it from [unpkg](https://www.unpkg.com):
```html
<script src="https://unpkg.com/endianness@6"></script>
```

@@ -57,5 +62,7 @@

* @param {number} offset The byte offset.
* @param {number=} start The start index. Assumes 0.
* @param {?number=} end The end index. Assumes the buffer length.
* @throws {Error} If the buffer length is not valid.
*/
function endianness(bytes, offset) {}
export function endianness(bytes, offset, start=0, end=null) {}
```

@@ -62,0 +69,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc