endianness
Advanced tools
Comparing version 1.0.1 to 2.0.0
/* | ||
endianness: Swap byte endianness in arrays. | ||
endianness | ||
Swap endianness in byte arrays. | ||
Copyright (c) 2017 Rafael da Silva Rocha. | ||
@@ -7,3 +8,3 @@ https://github.com/rochars/endianness | ||
*/ | ||
(function(d){function b(a){if(e[a])return e[a].a;var c=e[a]={m:a,f:!1,a:{}};d[a].call(c.a,c,c.a,b);c.f=!0;return c.a}var e={};b.l=d;b.h=e;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(){window.endianness=function(d,b){for(var e=d.length,a=0;a<e;){for(var c, | ||
f=d,g=a,h=0,k=b-1,l=parseInt(b/2,10);h<l;)c=f[g+h],f[g+h]=f[g+k],f[g+k]=c,h++,k--;a+=b}return d}}]); | ||
(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(){window.endianness=function(e,b){for(var d=e.length,a=0;a<d;){for(var c, | ||
f=e,g=a,h=0,k=b-1,l=parseInt(b/2,10);h<l;)c=f[g+h],f[g+h]=f[g+k],f[g+k]=c,h++,k--;a+=b}}}]); |
@@ -71,3 +71,4 @@ /******/ (function(modules) { // webpackBootstrap | ||
/*! | ||
* endianness: Swap byte endianness in arrays. | ||
* endianness | ||
* Swap endianness in byte arrays. | ||
* Copyright (c) 2017 Rafael da Silva Rocha. | ||
@@ -79,5 +80,6 @@ * https://github.com/rochars/endianness | ||
/** | ||
* Swap the endianness of units of information in a array of bytes. | ||
* @param {!Array<number>|Uint8Array} bytes An array of bytes. | ||
* @param {number} offset The offset according to the bit depth. | ||
* Swap the endianness of units of information in a byte array. | ||
* The original array is modified in-place. | ||
* @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes. | ||
* @param {number} offset The byte offset according to the bit depth. | ||
* - 2 for 16-bit | ||
@@ -88,2 +90,3 @@ * - 3 for 24-bit | ||
* - 6 for 48-bit | ||
* - 7 for 56-bit | ||
* - 8 for 64-bit | ||
@@ -95,6 +98,5 @@ */ | ||
while (i < len) { | ||
byteSwap(bytes, i, offset); | ||
i+=offset; | ||
byteSwap(bytes, offset, i); | ||
i += offset; | ||
} | ||
return bytes; | ||
} | ||
@@ -104,16 +106,16 @@ | ||
* Swap the endianness of a unit of information in a array of bytes. | ||
* @param {!Array<number>|Uint8Array} bytes An array of bytes. | ||
* @param {number} i The index to read. | ||
* @param {number} numBytes The number of bytes according to | ||
* the bit depth of the data. | ||
* The original array is modified in-place. | ||
* @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes. | ||
* @param {number} offset The number of bytes according to the bit depth. | ||
* @param {number} index The start index of the unit of information. | ||
*/ | ||
function byteSwap(bytes, i, numBytes) { | ||
function byteSwap(bytes, offset, index) { | ||
let x = 0; | ||
let y = numBytes - 1; | ||
let limit = parseInt(numBytes / 2, 10); | ||
let y = offset - 1; | ||
let limit = parseInt(offset / 2, 10); | ||
let swap; | ||
while(x < limit) { | ||
swap = bytes[i+x]; | ||
bytes[i+x] = bytes[i+y]; | ||
bytes[i+y] = swap; | ||
swap = bytes[index + x]; | ||
bytes[index + x] = bytes[index + y]; | ||
bytes[index + y] = swap; | ||
x++; | ||
@@ -120,0 +122,0 @@ y--; |
36
index.js
/*! | ||
* endianness: Swap byte endianness in arrays. | ||
* endianness | ||
* Swap endianness in byte arrays. | ||
* Copyright (c) 2017 Rafael da Silva Rocha. | ||
@@ -9,5 +10,6 @@ * https://github.com/rochars/endianness | ||
/** | ||
* Swap the endianness of units of information in a array of bytes. | ||
* @param {!Array<number>|Uint8Array} bytes An array of bytes. | ||
* @param {number} offset The offset according to the bit depth. | ||
* Swap the endianness of units of information in a byte array. | ||
* The original array is modified in-place. | ||
* @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes. | ||
* @param {number} offset The byte offset according to the bit depth. | ||
* - 2 for 16-bit | ||
@@ -18,2 +20,3 @@ * - 3 for 24-bit | ||
* - 6 for 48-bit | ||
* - 7 for 56-bit | ||
* - 8 for 64-bit | ||
@@ -25,6 +28,5 @@ */ | ||
while (i < len) { | ||
byteSwap(bytes, i, offset); | ||
i+=offset; | ||
byteSwap(bytes, offset, i); | ||
i += offset; | ||
} | ||
return bytes; | ||
} | ||
@@ -34,16 +36,16 @@ | ||
* Swap the endianness of a unit of information in a array of bytes. | ||
* @param {!Array<number>|Uint8Array} bytes An array of bytes. | ||
* @param {number} i The index to read. | ||
* @param {number} numBytes The number of bytes according to | ||
* the bit depth of the data. | ||
* The original array is modified in-place. | ||
* @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes. | ||
* @param {number} offset The number of bytes according to the bit depth. | ||
* @param {number} index The start index of the unit of information. | ||
*/ | ||
function byteSwap(bytes, i, numBytes) { | ||
function byteSwap(bytes, offset, index) { | ||
let x = 0; | ||
let y = numBytes - 1; | ||
let limit = parseInt(numBytes / 2, 10); | ||
let y = offset - 1; | ||
let limit = parseInt(offset / 2, 10); | ||
let swap; | ||
while(x < limit) { | ||
swap = bytes[i+x]; | ||
bytes[i+x] = bytes[i+y]; | ||
bytes[i+y] = swap; | ||
swap = bytes[index + x]; | ||
bytes[index + x] = bytes[index + y]; | ||
bytes[index + y] = swap; | ||
x++; | ||
@@ -50,0 +52,0 @@ y--; |
{ | ||
"name": "endianness", | ||
"version": "1.0.1", | ||
"description": "Swap byte endianness in arrays.", | ||
"version": "2.0.0", | ||
"description": "Swap endianness in byte arrays.", | ||
"homepage": "https://github.com/rochars/endianness", | ||
@@ -27,3 +27,3 @@ "author": "Rafael da Silva Rocha <rocha.rafaelsilva@gmail.com>", | ||
"bundle": "webpack", | ||
"compile": "google-closure-compiler-js dist/endianness.js > dist/endianness-min.js --compilationLevel ADVANCED", | ||
"compile": "google-closure-compiler-js dist/endianness.js > dist/endianness-min.js --compilationLevel=ADVANCED", | ||
"doc": "./node_modules/.bin/jsdoc index.js -d docs", | ||
@@ -30,0 +30,0 @@ "qa": "npm run lint && npm run test", |
# endianness | ||
Swap byte endianness in arrays. | ||
Copyright (c) 2017 Rafael da Silva Rocha. MIT License. | ||
https://github.com/rochars/endianness | ||
Swap endianness in byte arrays. | ||
Copyright (c) 2017 Rafael da Silva Rocha. | ||
https://github.com/rochars/endianness | ||
[![Build Status](https://travis-ci.org/rochars/endianness.svg?branch=master)](https://travis-ci.org/rochars/endianness) [![Build status](https://ci.appveyor.com/api/projects/status/e5r0tc303hueqq8e?svg=true)](https://ci.appveyor.com/project/rochars/endianness) [![codecov](https://codecov.io/gh/rochars/endianness/branch/master/graph/badge.svg)](https://codecov.io/gh/rochars/endianness) [![NPM version](https://img.shields.io/npm/v/endianness.svg?style=flat)](https://www.npmjs.com/package/endianness) [![NPM downloads](https://img.shields.io/npm/dm/endianness.svg?style=flat)](https://www.npmjs.com/package/endianness) | ||
[![Travis](https://img.shields.io/travis/rochars/endianness.svg?style=for-the-badge)](https://travis-ci.org/rochars/endianness) [![AppVeyor](https://img.shields.io/appveyor/ci/rochars/endianness.svg?style=for-the-badge&logo=appveyor)](https://ci.appveyor.com/project/rochars/endianness) [![Codecov](https://img.shields.io/codecov/c/github/rochars/endianness.svg?style=for-the-badge)](https://codecov.io/gh/rochars/endianness) [![NPM version](https://img.shields.io/npm/v/endianness.svg?style=for-the-badge)](https://www.npmjs.com/package/endianness) | ||
Swap byte endianness in a array of bytes. Works with any byte offset. | ||
Swap endianness in byte arrays. | ||
Arguments can be **Array** and **Uint8Array**. | ||
- Works in Node.js and in the browser | ||
- Arguments can be **Array<number>**, **Array<string>** and **Uint8Array** | ||
- Works with any byte offset | ||
- The byte array is modified in-place. | ||
For Node.js and the browser. | ||
## Install | ||
@@ -36,5 +37,6 @@ ``` | ||
/** | ||
* Swap the endianness of units of information in a array of bytes. | ||
* @param {!Array<number>|Uint8Array} bytes An array of bytes. | ||
* @param {number} offset The offset according to the bit depth. | ||
* Swap the endianness of units of information in a byte array. | ||
* The original array is modified in-place. | ||
* @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes. | ||
* @param {number} offset The byte offset according to the bit depth. | ||
* - 2 for 16-bit | ||
@@ -45,2 +47,3 @@ * - 3 for 24-bit | ||
* - 6 for 48-bit | ||
* - 7 for 56-bit | ||
* - 8 for 64-bit | ||
@@ -55,4 +58,4 @@ */ | ||
<script> | ||
endianness([64, 9, 33, 251, 84, 68, 45, 24]); | ||
//[24, 45, 68, 84, 251, 33, 9, 64] | ||
endianness([64, 9, 33, 251, 84, 68, 45, 24], 8); | ||
// returns [24, 45, 68, 84, 251, 33, 9, 64] | ||
</script> | ||
@@ -59,0 +62,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1035388
768
82