asset-hash
Advanced tools
Comparing version 1.2.1 to 1.2.2
@@ -1,2 +0,2 @@ | ||
/*! asset-hash v1.2.1 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
/*! asset-hash v1.2.2 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
'use strict'; | ||
@@ -8,3 +8,3 @@ | ||
require('lean-nodent-runtime'); | ||
require('core-js/modules/es6.promise'); | ||
var xxhash = require('xxhash'); | ||
@@ -16,3 +16,3 @@ var fs = require('fs'); | ||
const baseEncodeTables = { | ||
var baseEncodeTables = { | ||
26: "abcdefghijklmnopqrstuvwxyz", | ||
@@ -27,20 +27,19 @@ 32: "123456789abcdefghjkmnpqrstuvwxyz", | ||
}; | ||
function encodeBufferToBase(buffer, base, max) { | ||
var encodeTable = baseEncodeTables[base]; | ||
function encodeBufferToBase(buffer, base, max) { | ||
const encodeTable = baseEncodeTables[base]; | ||
if (!encodeTable) { | ||
throw new Error(`Unknown encoding base${base}`); | ||
throw new Error("Unknown encoding base" + base); | ||
} | ||
const readLength = buffer.length; | ||
var readLength = buffer.length; | ||
Big.DP = 0; | ||
Big.RM = 0; | ||
let b = new Big(0); | ||
for (let i = readLength - 1; i >= 0; i--) { | ||
for (var b = new Big(0), i = readLength - 1; i >= 0; i--) { | ||
b = b.times(256).plus(buffer[i]); | ||
} | ||
let output = ""; | ||
var output = ""; | ||
while (b.gt(0)) { | ||
@@ -53,13 +52,27 @@ output = encodeTable[b.mod(base)] + output; | ||
Big.RM = 1; | ||
return max == null ? output : output.slice(0, max); | ||
} | ||
function getHash(fileName, hash, base, max) { | ||
if (hash === void 0) { | ||
hash = "xxhash"; | ||
} | ||
function getHash(fileName, hash = "xxhash", base = 52, max = 10) { | ||
return new Promise((resolve, reject) => { | ||
if (base === void 0) { | ||
base = 52; | ||
} | ||
if (max === void 0) { | ||
max = 10; | ||
} | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
const hasher = hash === "xxhash" ? new xxhash.Stream(0xcafebabe, "buffer") : crypto.createHash(hash); | ||
fs.createReadStream(fileName).pipe(hasher).on("finish", () => { | ||
resolve(encodeBufferToBase(hasher.read(), base, max)); | ||
var hasher = hash === "xxhash" ? new xxhash.Stream(0xcafebabe, "buffer") : crypto.createHash(hash); | ||
fs.createReadStream(fileName).pipe(hasher).on("finish", function () { | ||
try { | ||
var encoded = encodeBufferToBase(hasher.read(), base, max); | ||
resolve(encoded); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
@@ -71,13 +84,27 @@ } catch (err) { | ||
} | ||
function getHashedName(fileName, hash = "xxhash", base = 52, max = 10) { | ||
return new Promise(($return, $error) => { | ||
function getHashedName(fileName, hash, base, max) { | ||
return new Promise(function ($return, $error) { | ||
var hashed, ext; | ||
return getHash(fileName).then(function ($await_2) { | ||
hashed = $await_2; | ||
ext = path.extname(fileName); | ||
if (hash === void 0) { | ||
hash = "xxhash"; | ||
} | ||
return $return(hashed + ext); | ||
}.$asyncbind(this, $error), $error); | ||
if (base === void 0) { | ||
base = 52; | ||
} | ||
if (max === void 0) { | ||
max = 10; | ||
} | ||
return Promise.resolve(getHash(fileName)).then(function ($await_3) { | ||
try { | ||
hashed = $await_3; | ||
ext = path.extname(fileName); | ||
return $return(hashed + ext); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
}, $error); | ||
}); | ||
@@ -84,0 +111,0 @@ } |
@@ -1,3 +0,3 @@ | ||
/*! asset-hash v1.2.1 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
import 'lean-nodent-runtime'; | ||
/*! asset-hash v1.2.2 by Sebastian Werner <s.werner@sebastian-software.de> */ | ||
import 'core-js/modules/es6.promise'; | ||
import { Stream } from 'xxhash'; | ||
@@ -9,3 +9,3 @@ import { createReadStream } from 'fs'; | ||
const baseEncodeTables = { | ||
var baseEncodeTables = { | ||
26: "abcdefghijklmnopqrstuvwxyz", | ||
@@ -20,20 +20,19 @@ 32: "123456789abcdefghjkmnpqrstuvwxyz", | ||
}; | ||
function encodeBufferToBase(buffer, base, max) { | ||
var encodeTable = baseEncodeTables[base]; | ||
function encodeBufferToBase(buffer, base, max) { | ||
const encodeTable = baseEncodeTables[base]; | ||
if (!encodeTable) { | ||
throw new Error(`Unknown encoding base${base}`); | ||
throw new Error("Unknown encoding base" + base); | ||
} | ||
const readLength = buffer.length; | ||
var readLength = buffer.length; | ||
Big.DP = 0; | ||
Big.RM = 0; | ||
let b = new Big(0); | ||
for (let i = readLength - 1; i >= 0; i--) { | ||
for (var b = new Big(0), i = readLength - 1; i >= 0; i--) { | ||
b = b.times(256).plus(buffer[i]); | ||
} | ||
let output = ""; | ||
var output = ""; | ||
while (b.gt(0)) { | ||
@@ -46,13 +45,27 @@ output = encodeTable[b.mod(base)] + output; | ||
Big.RM = 1; | ||
return max == null ? output : output.slice(0, max); | ||
} | ||
function getHash(fileName, hash, base, max) { | ||
if (hash === void 0) { | ||
hash = "xxhash"; | ||
} | ||
function getHash(fileName, hash = "xxhash", base = 52, max = 10) { | ||
return new Promise((resolve, reject) => { | ||
if (base === void 0) { | ||
base = 52; | ||
} | ||
if (max === void 0) { | ||
max = 10; | ||
} | ||
return new Promise(function (resolve, reject) { | ||
try { | ||
const hasher = hash === "xxhash" ? new Stream(0xcafebabe, "buffer") : createHash(hash); | ||
createReadStream(fileName).pipe(hasher).on("finish", () => { | ||
resolve(encodeBufferToBase(hasher.read(), base, max)); | ||
var hasher = hash === "xxhash" ? new Stream(0xcafebabe, "buffer") : createHash(hash); | ||
createReadStream(fileName).pipe(hasher).on("finish", function () { | ||
try { | ||
var encoded = encodeBufferToBase(hasher.read(), base, max); | ||
resolve(encoded); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
@@ -64,13 +77,27 @@ } catch (err) { | ||
} | ||
function getHashedName(fileName, hash = "xxhash", base = 52, max = 10) { | ||
return new Promise(($return, $error) => { | ||
function getHashedName(fileName, hash, base, max) { | ||
return new Promise(function ($return, $error) { | ||
var hashed, ext; | ||
return getHash(fileName).then(function ($await_2) { | ||
hashed = $await_2; | ||
ext = extname(fileName); | ||
if (hash === void 0) { | ||
hash = "xxhash"; | ||
} | ||
return $return(hashed + ext); | ||
}.$asyncbind(this, $error), $error); | ||
if (base === void 0) { | ||
base = 52; | ||
} | ||
if (max === void 0) { | ||
max = 10; | ||
} | ||
return Promise.resolve(getHash(fileName)).then(function ($await_3) { | ||
try { | ||
hashed = $await_3; | ||
ext = extname(fileName); | ||
return $return(hashed + ext); | ||
} catch ($boundEx) { | ||
return $error($boundEx); | ||
} | ||
}, $error); | ||
}); | ||
@@ -77,0 +104,0 @@ } |
{ | ||
"name": "asset-hash", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Very fast asset hashing function for using e.g. during front-end deployments.", | ||
@@ -17,2 +17,6 @@ "main": "lib/index.cjs.js", | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sebastian-software/asset-hash.git" | ||
}, | ||
"keywords": [ | ||
@@ -55,14 +59,14 @@ "asset", | ||
"devDependencies": { | ||
"babel-preset-edge": "^1.7.0", | ||
"eslint-config-readable": "^1.10.2", | ||
"jest": "^22.1.4", | ||
"preppy": "^3.3.1", | ||
"prettier": "^1.10.2", | ||
"release-it": "^6.2.0" | ||
"babel-preset-edge": "^4.5.1", | ||
"eslint": "^5.0.0", | ||
"eslint-config-readable": "^2.0.0", | ||
"flow-bin": "^0.75.0", | ||
"jest": "^23.1.0", | ||
"preppy": "^4.2.3", | ||
"prettier": "^1.13.5" | ||
}, | ||
"dependencies": { | ||
"big.js": "^5.0.3", | ||
"lean-nodent-runtime": "1.0.1", | ||
"big.js": "^5.1.2", | ||
"xxhash": "^0.2.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
18228
2
181
2
7
- Removedlean-nodent-runtime@1.0.1
- Removedlean-nodent-runtime@1.0.1(transitive)
Updatedbig.js@^5.1.2