Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

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.1-alpha.0 to 7.0.0-alpha.0

dist/endianness.js

3

CHANGELOG.md
# CHANGELOG
## version 7.0.0 (2018-06-25)
- export default function endianness(){}
## version 6.0.0 (2018-06-21)
- **endianness** as a ES6 module
- Option to swap only a slice of the buffer

77

dist/endianness.cjs.js

@@ -1,74 +0,3 @@

module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
'use strict';
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (immutable) */ __webpack_exports__["endianness"] = endianness;
/*

@@ -149,4 +78,2 @@ * endianness: Swap endianness in byte arrays.

/***/ })
/******/ ]);
module.exports = endianness;
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;
c["default"]=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.default;

@@ -1,161 +0,84 @@

(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["endianness"] = factory();
else
root["endianness"] = factory();
})(typeof self !== 'undefined' ? self : this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 0);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.endianness = factory());
}(this, (function () { 'use strict';
"use strict";
Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
/* harmony export (immutable) */ __webpack_exports__["endianness"] = endianness;
/*
* endianness: Swap endianness in byte arrays.
* https://github.com/rochars/endianness
*
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/*
* endianness: Swap endianness in byte arrays.
* https://github.com/rochars/endianness
*
* Copyright (c) 2017-2018 Rafael da Silva Rocha.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
*/
/**
* @fileoverview A function to swap endianness in byte buffers.
*/
/**
* @fileoverview A function to swap endianness in byte buffers.
*/
/**
* @module endianness
*/
/**
* @module endianness
*/
/**
* Swap the byte ordering in a buffer. The buffer is modified in place.
* @param {!Array<number|string>|!Uint8Array} bytes The bytes.
* @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, start=0, end=null) {
let len = end || bytes.length;
let limit = parseInt(offset / 2, 10);
if (len % offset) {
throw new Error("Bad buffer length.");
/**
* Swap the byte ordering in a buffer. The buffer is modified in place.
* @param {!Array<number|string>|!Uint8Array} bytes The bytes.
* @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, start=0, end=null) {
let len = end || bytes.length;
let limit = parseInt(offset / 2, 10);
if (len % offset) {
throw new Error("Bad buffer length.");
}
let i = start;
while (i < len) {
swap(bytes, offset, i, limit);
i += offset;
}
}
let i = start;
while (i < len) {
swap(bytes, offset, i, limit);
i += offset;
}
}
/**
* Swap the byte order of a value in a buffer. The buffer is modified in place.
* @param {!Array<number|string>|!Uint8Array} bytes The bytes.
* @param {number} offset The byte offset.
* @param {number} index The start index.
* @private
*/
function swap(bytes, offset, index, limit) {
let x = 0;
let y = offset - 1;
while(x < limit) {
let theByte = bytes[index + x];
bytes[index + x] = bytes[index + y];
bytes[index + y] = theByte;
x++;
y--;
/**
* Swap the byte order of a value in a buffer. The buffer is modified in place.
* @param {!Array<number|string>|!Uint8Array} bytes The bytes.
* @param {number} offset The byte offset.
* @param {number} index The start index.
* @private
*/
function swap(bytes, offset, index, limit) {
let x = 0;
let y = offset - 1;
while(x < limit) {
let theByte = bytes[index + x];
bytes[index + x] = bytes[index + y];
bytes[index + y] = theByte;
x++;
y--;
}
}
}
return endianness;
/***/ })
/******/ ]);
});
})));

@@ -44,3 +44,3 @@ /*

*/
export function endianness(bytes, offset, start=0, end=null) {
export default function endianness(bytes, offset, start=0, end=null) {
let len = end || bytes.length;

@@ -47,0 +47,0 @@ let limit = parseInt(offset / 2, 10);

{
"name": "endianness",
"version": "6.0.1-alpha.0",
"version": "7.0.0-alpha.0",
"description": "Swap endianness in byte arrays.",

@@ -9,3 +9,3 @@ "homepage": "https://github.com/rochars/endianness",

"main": "./dist/endianness.cjs.js",
"module": "./index.js",
"module": "./dist/endianness.js",
"browser": "./dist/endianness.umd.js",

@@ -36,8 +36,9 @@ "jsdelivr": "./dist/endianness.min.js",

"lint": "jshint index.js && jshint test",
"test": "nyc --require=esm ./node_modules/mocha/bin/_mocha test --recursive -R min",
"test-min": "node ./node_modules/mocha/bin/_mocha test --min --recursive -R min",
"test-cjs": "node ./node_modules/mocha/bin/_mocha test --cjs --recursive -R min",
"test-umd": "node ./node_modules/mocha/bin/_mocha test --umd --recursive -R min",
"test-dist": "npm run test-min && npm run test-cjs && npm run test-umd",
"pack": "webpack && npm run test-dist && npm run test",
"test": "nyc --require=esm ./node_modules/mocha/bin/_mocha test --recursive -R dot",
"test-min": "node ./node_modules/mocha/bin/_mocha test --min --recursive -R dot",
"test-cjs": "node ./node_modules/mocha/bin/_mocha test --cjs --recursive -R dot",
"test-umd": "node ./node_modules/mocha/bin/_mocha test --umd --recursive -R dot",
"test-esm": "node ./node_modules/mocha/bin/_mocha test --esm -r esm --recursive -R dot",
"test-dist": "npm run test-esm && npm run test-min && npm run test-cjs && npm run test-umd",
"pack": "rollup --config && webpack && npm run test-dist && npm run test",
"doc": "./node_modules/.bin/jsdoc index.js -d docs -r README.md -t node_modules/docdash",

@@ -59,4 +60,5 @@ "build": "npm run lint && npm run pack && npm run doc",

"nyc": "^12.0.2",
"rollup": "^0.61.2",
"webpack": "^3.12.0"
}
}

@@ -20,4 +20,7 @@ # endianness

## Example
### ES6
Import from the **endianness.js** module:
```javascript
const endianness = require("endianness").endianness;
import endianness from 'endianness.js';

@@ -27,12 +30,16 @@ // Swap endianness of one 64-bit value:

endianness(bytes, 8);
console.log(bytes);
```
### Node
require() the default export of the **endianness** module:
```javascript
const endianness = require("endianness");
// Swap endianness of two 24-bit values:
bytes = ["00", "00", "80", "ff", "ff", "7f"];
endianness(bytes, 3),
console.log(bytes);
```
## Browser
Use the compiled file in the */dist* folder:
### Browser
Use the compiled file **endianness.min.js** in the **/dist** folder:
```html

@@ -67,26 +74,14 @@ <script src="endianness.min.js"></script>

*/
export function endianness(bytes, offset, start=0, end=null) {}
function endianness(bytes, offset, start=0, end=null) {}
```
## Distribution
This library is implemented as a ES6 module and also distributed as a CommonJS module, UMD module and a compiled script for browsers. If your system does not pick one automatically for you, you can pick one in the **dist/** folder.
- The CommonJS is the one used by Node. It is served in the "main" field of this library's package.json
- The UMD module is compatible with Node, AMD and browsers. It is served in the "browser" field.
- The compiled dist is browser-only and should be the one served by CDNs.
- The "module" field points to "./index.js" and should be the default entry point.
This library is a ES6 module also distributed as a CommonJS module, UMD and a compiled script for browsers.
If you are using a module bundler to compile a module that depends on **endianness** you might need to specify what is the correct entry point as some bundlers will assume "browser". In general, you should point to "module".
- The **CommonJS** is the one used by Node. It is served in the "main" field of package.json
- The **UMD** module is compatible with Node, AMD and browsers. It is served in the "browser" field.
- The **compiled dist** is browser-only and should be the one served by CDNs.
- The **ES6** dist is **endianness.js**, served as "module" in package.json
### webpack example:
```javascript
module.exports = {
entry: './index.js',
resolve: {
// tells webpack to use 'module' or 'main'
// not 'browser'
mainFields: ['module', 'main']
},
...
};
```
You may load both **endianness.umd.js** and **endianness.min.js** in the browser with ```<script>``` tags.

@@ -93,0 +88,0 @@ ## LICENSE

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