asset-hash
Advanced tools
Comparing version 3.0.9 to 3.1.0
@@ -1,2 +0,2 @@ | ||
/*! asset-hash v3.0.9 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
/*! asset-hash v3.1.0 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
'use strict'; | ||
@@ -6,8 +6,9 @@ | ||
require('core-js/modules/es.array.slice'); | ||
require('core-js/modules/es.date.to-string'); | ||
require('core-js/modules/es.object.to-string'); | ||
require('core-js/modules/es.promise'); | ||
require('core-js/modules/es.regexp.exec'); | ||
require('core-js/modules/es.regexp.to-string'); | ||
require('core-js/modules/es.array.slice.js'); | ||
require('core-js/modules/es.date.to-string.js'); | ||
require('core-js/modules/es.object.to-string.js'); | ||
require('core-js/modules/es.parse-int.js'); | ||
require('core-js/modules/es.promise.js'); | ||
require('core-js/modules/es.regexp.exec.js'); | ||
require('core-js/modules/es.regexp.to-string.js'); | ||
var crypto = require('crypto'); | ||
@@ -43,5 +44,6 @@ var fs = require('fs'); | ||
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
}; | ||
}, | ||
BYTE_SIZE = 256; | ||
function baseEncode(buffer, base) { | ||
var baseNum = typeof base == "number" ? base : /\d+/.exec(base)[0], | ||
var baseNum = typeof base == "number" ? base : parseInt(/\d+/.exec(base)[0], 10), | ||
encodeTable = baseEncodeTables[baseNum]; | ||
@@ -58,3 +60,3 @@ | ||
for (var current = new BigInt__default(0), i = length - 1; i >= 0; i--) { | ||
current = current.times(256).plus(buffer[i]); | ||
current = current.times(BYTE_SIZE).plus(buffer[i]); | ||
} | ||
@@ -65,3 +67,3 @@ | ||
while (current.gt(0)) { | ||
output = encodeTable[current.mod(baseNum)] + output; | ||
output = "" + encodeTable[current.mod(baseNum).toNumber()] + output; | ||
current = current.div(baseNum); | ||
@@ -79,9 +81,8 @@ } | ||
maxLength = _ref.maxLength, | ||
output = "", | ||
isString = typeof bufferOrString == "string"; | ||
output = ""; | ||
if (isString && encoding === "hex") { | ||
if (typeof bufferOrString == "string" && encoding === "hex") { | ||
output = bufferOrString; | ||
} else { | ||
var buffer = isString ? Buffer.from(bufferOrString, "hex") : bufferOrString; | ||
var buffer = typeof bufferOrString == "string" ? Buffer.from(bufferOrString, "hex") : bufferOrString; | ||
@@ -100,2 +101,4 @@ if (encoding === "hex" || encoding === "base64" || encoding === "utf8") { | ||
function Hasher(options) { | ||
var _options$hash, _options$encoding, _options$maxLength; | ||
if (options === void 0) { | ||
@@ -105,5 +108,8 @@ options = {}; | ||
this._hasher = createHasher(options.hash || DEFAULT_HASH); | ||
this._encoding = options.encoding || DEFAULT_ENCODING; | ||
this._maxLength = options.maxLength || null; | ||
this.hasher = void 0; | ||
this.encoding = void 0; | ||
this.maxLength = void 0; | ||
this.hasher = createHasher((_options$hash = options.hash) != null ? _options$hash : DEFAULT_HASH); | ||
this.encoding = ((_options$encoding = options.encoding) != null ? _options$encoding : DEFAULT_ENCODING) + ""; | ||
this.maxLength = (_options$maxLength = options.maxLength) != null ? _options$maxLength : null; | ||
} | ||
@@ -115,9 +121,9 @@ | ||
var buffer = data instanceof Buffer ? data : Buffer.from(data.toString(), "utf-8"); | ||
return this._hasher.update(buffer); | ||
return this.hasher.update(buffer); | ||
}; | ||
_proto.digest = function digest(encoding, maxLength) { | ||
return computeDigest(this._hasher.digest("buffer"), { | ||
encoding: encoding || this._encoding, | ||
maxLength: maxLength || this._maxLength | ||
return computeDigest(this.hasher.digest(), { | ||
encoding: encoding != null ? encoding : this.encoding, | ||
maxLength: maxLength != null ? maxLength : this.maxLength | ||
}); | ||
@@ -128,2 +134,27 @@ }; | ||
}(); | ||
function xxhashEnvelope(xxhash) { | ||
return { | ||
update: function update(input) { | ||
return xxhash.update(input); | ||
}, | ||
digest: function digest() { | ||
return xxhash.digest("buffer"); | ||
} | ||
}; | ||
} | ||
function cryptoEnvelope(hash) { | ||
var envelopeHash = { | ||
update: function update(input) { | ||
hash.update(input); | ||
return envelopeHash; | ||
}, | ||
digest: function digest() { | ||
return hash.digest(); | ||
} | ||
}; | ||
return envelopeHash; | ||
} | ||
function createHasher(hash) { | ||
@@ -137,3 +168,3 @@ var hasher; | ||
hasher = new XXHash32(XXHASH_CONSTRUCT); | ||
hasher = xxhashEnvelope(new XXHash32(XXHASH_CONSTRUCT)); | ||
} else if (hash === "xxhash64") { | ||
@@ -144,3 +175,3 @@ if (!XXHash64) { | ||
hasher = new XXHash64(XXHASH_CONSTRUCT); | ||
hasher = xxhashEnvelope(new XXHash64(XXHASH_CONSTRUCT)); | ||
} else if (hash === "metrohash64") { | ||
@@ -151,3 +182,3 @@ hasher = new metrohash.MetroHash64(); | ||
} else { | ||
hasher = crypto.createHash(hash); | ||
hasher = cryptoEnvelope(crypto.createHash(hash)); | ||
} | ||
@@ -172,7 +203,8 @@ | ||
try { | ||
var digest = computeDigest(hasher.digest("buffer"), { | ||
var _digest = computeDigest(hasher.digest(), { | ||
encoding: encoding || DEFAULT_ENCODING, | ||
maxLength: maxLength || DEFAULT_MAX_LENGTH | ||
}); | ||
resolve(digest); | ||
resolve(_digest); | ||
} catch (error) { | ||
@@ -179,0 +211,0 @@ reject(error); |
@@ -1,8 +0,9 @@ | ||
/*! asset-hash v3.0.9 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
import 'core-js/modules/es.array.slice'; | ||
import 'core-js/modules/es.date.to-string'; | ||
import 'core-js/modules/es.object.to-string'; | ||
import 'core-js/modules/es.promise'; | ||
import 'core-js/modules/es.regexp.exec'; | ||
import 'core-js/modules/es.regexp.to-string'; | ||
/*! asset-hash v3.1.0 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
import 'core-js/modules/es.array.slice.js'; | ||
import 'core-js/modules/es.date.to-string.js'; | ||
import 'core-js/modules/es.object.to-string.js'; | ||
import 'core-js/modules/es.parse-int.js'; | ||
import 'core-js/modules/es.promise.js'; | ||
import 'core-js/modules/es.regexp.exec.js'; | ||
import 'core-js/modules/es.regexp.to-string.js'; | ||
import { createHash } from 'crypto'; | ||
@@ -34,5 +35,6 @@ import { createReadStream } from 'fs'; | ||
62: "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" | ||
}; | ||
}, | ||
BYTE_SIZE = 256; | ||
function baseEncode(buffer, base) { | ||
var baseNum = typeof base == "number" ? base : /\d+/.exec(base)[0], | ||
var baseNum = typeof base == "number" ? base : parseInt(/\d+/.exec(base)[0], 10), | ||
encodeTable = baseEncodeTables[baseNum]; | ||
@@ -49,3 +51,3 @@ | ||
for (var current = new BigInt(0), i = length - 1; i >= 0; i--) { | ||
current = current.times(256).plus(buffer[i]); | ||
current = current.times(BYTE_SIZE).plus(buffer[i]); | ||
} | ||
@@ -56,3 +58,3 @@ | ||
while (current.gt(0)) { | ||
output = encodeTable[current.mod(baseNum)] + output; | ||
output = "" + encodeTable[current.mod(baseNum).toNumber()] + output; | ||
current = current.div(baseNum); | ||
@@ -70,9 +72,8 @@ } | ||
maxLength = _ref.maxLength, | ||
output = "", | ||
isString = typeof bufferOrString == "string"; | ||
output = ""; | ||
if (isString && encoding === "hex") { | ||
if (typeof bufferOrString == "string" && encoding === "hex") { | ||
output = bufferOrString; | ||
} else { | ||
var buffer = isString ? Buffer.from(bufferOrString, "hex") : bufferOrString; | ||
var buffer = typeof bufferOrString == "string" ? Buffer.from(bufferOrString, "hex") : bufferOrString; | ||
@@ -91,2 +92,4 @@ if (encoding === "hex" || encoding === "base64" || encoding === "utf8") { | ||
function Hasher(options) { | ||
var _options$hash, _options$encoding, _options$maxLength; | ||
if (options === void 0) { | ||
@@ -96,5 +99,8 @@ options = {}; | ||
this._hasher = createHasher(options.hash || DEFAULT_HASH); | ||
this._encoding = options.encoding || DEFAULT_ENCODING; | ||
this._maxLength = options.maxLength || null; | ||
this.hasher = void 0; | ||
this.encoding = void 0; | ||
this.maxLength = void 0; | ||
this.hasher = createHasher((_options$hash = options.hash) != null ? _options$hash : DEFAULT_HASH); | ||
this.encoding = ((_options$encoding = options.encoding) != null ? _options$encoding : DEFAULT_ENCODING) + ""; | ||
this.maxLength = (_options$maxLength = options.maxLength) != null ? _options$maxLength : null; | ||
} | ||
@@ -106,9 +112,9 @@ | ||
var buffer = data instanceof Buffer ? data : Buffer.from(data.toString(), "utf-8"); | ||
return this._hasher.update(buffer); | ||
return this.hasher.update(buffer); | ||
}; | ||
_proto.digest = function digest(encoding, maxLength) { | ||
return computeDigest(this._hasher.digest("buffer"), { | ||
encoding: encoding || this._encoding, | ||
maxLength: maxLength || this._maxLength | ||
return computeDigest(this.hasher.digest(), { | ||
encoding: encoding != null ? encoding : this.encoding, | ||
maxLength: maxLength != null ? maxLength : this.maxLength | ||
}); | ||
@@ -119,2 +125,27 @@ }; | ||
}(); | ||
function xxhashEnvelope(xxhash) { | ||
return { | ||
update: function update(input) { | ||
return xxhash.update(input); | ||
}, | ||
digest: function digest() { | ||
return xxhash.digest("buffer"); | ||
} | ||
}; | ||
} | ||
function cryptoEnvelope(hash) { | ||
var envelopeHash = { | ||
update: function update(input) { | ||
hash.update(input); | ||
return envelopeHash; | ||
}, | ||
digest: function digest() { | ||
return hash.digest(); | ||
} | ||
}; | ||
return envelopeHash; | ||
} | ||
function createHasher(hash) { | ||
@@ -128,3 +159,3 @@ var hasher; | ||
hasher = new XXHash32(XXHASH_CONSTRUCT); | ||
hasher = xxhashEnvelope(new XXHash32(XXHASH_CONSTRUCT)); | ||
} else if (hash === "xxhash64") { | ||
@@ -135,3 +166,3 @@ if (!XXHash64) { | ||
hasher = new XXHash64(XXHASH_CONSTRUCT); | ||
hasher = xxhashEnvelope(new XXHash64(XXHASH_CONSTRUCT)); | ||
} else if (hash === "metrohash64") { | ||
@@ -142,3 +173,3 @@ hasher = new MetroHash64(); | ||
} else { | ||
hasher = createHash(hash); | ||
hasher = cryptoEnvelope(createHash(hash)); | ||
} | ||
@@ -163,7 +194,8 @@ | ||
try { | ||
var digest = computeDigest(hasher.digest("buffer"), { | ||
var _digest = computeDigest(hasher.digest(), { | ||
encoding: encoding || DEFAULT_ENCODING, | ||
maxLength: maxLength || DEFAULT_MAX_LENGTH | ||
}); | ||
resolve(digest); | ||
resolve(_digest); | ||
} catch (error) { | ||
@@ -170,0 +202,0 @@ reject(error); |
{ | ||
"name": "asset-hash", | ||
"version": "3.0.9", | ||
"version": "3.1.0", | ||
"description": "Very fast asset hashing function for using e.g. during front-end deployments.", | ||
"main": "lib/index.cjs.js", | ||
"module": "lib/index.esm.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
@@ -49,19 +50,21 @@ "lint": "eslint '**/*.{js,jsx,ts,tsx,mjs}'", | ||
"devDependencies": { | ||
"@effective/eslint-config": "^3.9.3", | ||
"@effective/eslint-config": "^3.9.4", | ||
"@types/big.js": "^6.0.2", | ||
"@types/jest": "^26.0.20", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^26.6.3", | ||
"babel-preset-edge": "^5.5.1", | ||
"eslint": "^7.15.0", | ||
"eslint": "^7.20.0", | ||
"jest": "^26.6.3", | ||
"preppy": "^10.9.2", | ||
"preppy": "^10.9.4", | ||
"prettier": "^2.2.1", | ||
"release-it": "^14.2.2", | ||
"release-it": "^14.4.1", | ||
"semver": "^7.3.4", | ||
"typescript": "^4.1.2" | ||
"typescript": "^4.1.5" | ||
}, | ||
"dependencies": { | ||
"big.js": "^6.0.3", | ||
"core-js": "^3.8.1", | ||
"core-js": "^3.9.0", | ||
"metrohash": "^2.6.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
46937
7
414
13
Updatedcore-js@^3.9.0