loader-utils
Advanced tools
Comparing version 3.1.3 to 3.2.0
@@ -14,3 +14,18 @@ "use strict"; | ||
function encodeBufferToBase(buffer, base) { | ||
/** | ||
* @param {Uint32Array} uint32Array Treated as a long base-0x100000000 number, little endian | ||
* @param {number} divisor The divisor | ||
* @return {number} Modulo (remainder) of the division | ||
*/ | ||
function divmod32(uint32Array, divisor) { | ||
let carry = 0; | ||
for (let i = uint32Array.length - 1; i >= 0; i--) { | ||
const value = carry * 0x100000000 + uint32Array[i]; | ||
carry = value % divisor; | ||
uint32Array[i] = Math.floor(value / divisor); | ||
} | ||
return carry; | ||
} | ||
function encodeBufferToBase(buffer, base, length) { | ||
const encodeTable = baseEncodeTables[base]; | ||
@@ -22,23 +37,20 @@ | ||
const readLength = buffer.length; | ||
const Big = require("big.js"); | ||
// Input bits are only enough to generate this many characters | ||
const limit = Math.ceil((buffer.length * 8) / Math.log2(base)); | ||
length = Math.min(length, limit); | ||
Big.RM = Big.DP = 0; | ||
// Most of the crypto digests (if not all) has length a multiple of 4 bytes. | ||
// Fewer numbers in the array means faster math. | ||
const uint32Array = new Uint32Array(Math.ceil(buffer.length / 4)); | ||
let b = new Big(0); | ||
// Make sure the input buffer data is copied and is not mutated by reference. | ||
// divmod32() would corrupt the BulkUpdateDecorator cache otherwise. | ||
buffer.copy(Buffer.from(uint32Array.buffer)); | ||
for (let i = readLength - 1; i >= 0; i--) { | ||
b = b.times(256).plus(buffer[i]); | ||
} | ||
let output = ""; | ||
while (b.gt(0)) { | ||
output = encodeTable[b.mod(base)] + output; | ||
b = b.div(base); | ||
for (let i = 0; i < length; i++) { | ||
output = encodeTable[divmod32(uint32Array, base)] + output; | ||
} | ||
Big.DP = 20; | ||
Big.RM = 1; | ||
return output; | ||
@@ -115,6 +127,3 @@ } | ||
) { | ||
return encodeBufferToBase(hash.digest(), digestType.substr(4)).substr( | ||
0, | ||
maxLength | ||
); | ||
return encodeBufferToBase(hash.digest(), digestType.substr(4), maxLength); | ||
} else { | ||
@@ -121,0 +130,0 @@ return hash.digest(digestType || "hex").substr(0, maxLength); |
{ | ||
"name": "loader-utils", | ||
"version": "3.1.3", | ||
"version": "3.2.0", | ||
"author": "Tobias Koppers @sokra", | ||
"description": "utils for webpack loaders", | ||
"dependencies": { | ||
"big.js": "^6.1.1" | ||
}, | ||
"dependencies": {}, | ||
"scripts": { | ||
@@ -10,0 +8,0 @@ "lint": "prettier --list-different . && eslint .", |
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
31937
0
635
- Removedbig.js@^6.1.1
- Removedbig.js@6.2.2(transitive)