Sha256: 3c6247e7143c6b7b296d02f2a0669f4af31b49b58d4183f98d572def33aa9417

Contents?: true

Size: 1.06 KB

Versions: 61

Compression:

Stored size: 1.06 KB

Contents

'use strict';

var GetIntrinsic = require('get-intrinsic');

var $Number = GetIntrinsic('%Number%');
var $BigInt = GetIntrinsic('%BigInt%', true);

module.exports = function integerToNBytes(intValue, n, isLittleEndian) {
	var Z = typeof intValue === 'bigint' ? $BigInt : $Number;
	/*
	if (intValue >= 0) { // step 3.d
		// Let rawBytes be a List containing the n-byte binary encoding of intValue. If isLittleEndian is false, the bytes are ordered in big endian order. Otherwise, the bytes are ordered in little endian order.
	} else { // step 3.e
		// Let rawBytes be a List containing the n-byte binary 2's complement encoding of intValue. If isLittleEndian is false, the bytes are ordered in big endian order. Otherwise, the bytes are ordered in little endian order.
	}
    */
	if (intValue < 0) {
		intValue >>>= 0; // eslint-disable-line no-param-reassign
	}

	var rawBytes = [];
	for (var i = 0; i < n; i++) {
		rawBytes[isLittleEndian ? i : n - 1 - i] = $Number(intValue & Z(0xFF));
		intValue >>= Z(8); // eslint-disable-line no-param-reassign
	}

	return rawBytes; // step 4
};

Version data entries

61 entries across 61 versions & 3 rubygems

Version Path
immosquare-cleaner-0.1.68 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.67 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.66 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.65 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.64 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.63 node_modules/es-abstract/helpers/integerToNBytes.js
rapid_stack-0.2.0 templates/frontend/node_modules/es-abstract/helpers/integerToNBytes.js
rapid_stack-0.1.1 templates/FrontEnd/node_modules/es-abstract/helpers/integerToNBytes.js
rapid_stack-0.1.0 templates/FrontEnd/node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.62 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.61 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.60 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.59 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.58 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.57 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.56 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.55 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.54 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.53 node_modules/es-abstract/helpers/integerToNBytes.js
immosquare-cleaner-0.1.52 node_modules/es-abstract/helpers/integerToNBytes.js