endianness
Copyright (c) 2017-2018 Rafael da Silva Rocha.
https://github.com/rochars/endianness
Swap endianness in byte arrays. The input buffer is modified in-place.
- Works everywhere, server and browser
- Works with any byte offset
- Can swap only a part of the buffer
Install
npm install endianness
Use
ES6
import
endianness from the endianness.js module:
import endianness from 'endianness.js';
let bytes = [64, 9, 33, 251, 84, 68, 45, 24];
endianness(bytes, 8);
Node
require()
the endianness module:
const endianness = require("endianness");
let bytes = ["00", "00", "80", "ff", "ff", "7f"];
endianness(bytes, 3),
Browser
Use the compiled file endianness.min.js in the dist/ folder:
<script src="endianness.min.js"></script>
<script>
var bytes = [64, 9, 33, 251, 84, 68, 45, 24];
endianness(bytes, 8);
console.log(bytes);
</script>
Or get it from the jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/endianness@7"></script>
Or get it from unpkg:
<script src="https://unpkg.com/endianness@7"></script>
Or as a ES6 module for modern browsers from jspm:
<script type="module">
import endianness from 'https://dev.jspm.io/endianness';
</script>
API
function endianness(bytes, offset, start=0, end=null) {}
Distribution
This library is a ES6 module also distributed as a CommonJS module, UMD module and a compiled script for browsers.
- 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
You may load both endianness.umd.js and endianness.min.js in the browser with <script>
tags.
LICENSE
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.