Comparing version 1.1.1 to 1.1.2
# Changelog | ||
## 1.1.2 (June 29, 2019) | ||
- added `isBlurhashValid()` utility | ||
## 1.1.1 (June 29, 2019) | ||
* fixed incorrect type declaration path in package.json | ||
* improved error handling | ||
- fixed incorrect type declaration path in package.json | ||
- improved error handling |
@@ -0,2 +1,6 @@ | ||
export declare const isBlurhashValid: (blurhash: string) => { | ||
result: boolean; | ||
errorReason?: string; | ||
}; | ||
declare const decode: (blurhash: string, width: number, height: number, punch?: number) => Uint8ClampedArray; | ||
export default decode; |
@@ -6,2 +6,26 @@ "use strict"; | ||
var error_1 = require("./error"); | ||
/** | ||
* Returns an error message if invalid or undefined if valid | ||
* @param blurhash | ||
*/ | ||
var validateBlurhash = function (blurhash) { | ||
if (!blurhash || blurhash.length < 6) { | ||
throw new error_1.ValidationError("The blurhash string must be at least 6 characters"); | ||
} | ||
var sizeFlag = base83_1.decode83(blurhash[0]); | ||
var numY = Math.floor(sizeFlag / 9) + 1; | ||
var numX = (sizeFlag % 9) + 1; | ||
if (blurhash.length !== 4 + 2 * numX * numY) { | ||
throw new error_1.ValidationError("blurhash length mismatch: length is " + blurhash.length + " but it should be " + (4 + 2 * numX * numY)); | ||
} | ||
}; | ||
exports.isBlurhashValid = function (blurhash) { | ||
try { | ||
validateBlurhash(blurhash); | ||
} | ||
catch (error) { | ||
return { result: false, errorReason: error.message }; | ||
} | ||
return { result: true }; | ||
}; | ||
var decodeDC = function (value) { | ||
@@ -25,6 +49,4 @@ var intR = value >> 16; | ||
var decode = function (blurhash, width, height, punch) { | ||
validateBlurhash(blurhash); | ||
punch = punch | 1; | ||
if (blurhash.length < 6) { | ||
throw new error_1.ValidationError("The blurhash string must be at least 6 characters"); | ||
} | ||
var sizeFlag = base83_1.decode83(blurhash[0]); | ||
@@ -35,6 +57,2 @@ var numY = Math.floor(sizeFlag / 9) + 1; | ||
var maximumValue = (quantisedMaximumValue + 1) / 166; | ||
if (blurhash.length !== 4 + 2 * numX * numY) { | ||
throw new error_1.ValidationError("blurhash length mismatch: length is " + blurhash.length + " but it should be " + (4 + 2 * numX * numY)); | ||
return null; | ||
} | ||
var colors = new Array(numX * numY); | ||
@@ -41,0 +59,0 @@ for (var i = 0; i < colors.length; i++) { |
@@ -1,3 +0,3 @@ | ||
export { default as decode } from "./decode"; | ||
export { default as decode, isBlurhashValid } from "./decode"; | ||
export { default as encode } from "./encode"; | ||
export * from "./error"; |
@@ -8,2 +8,3 @@ "use strict"; | ||
exports.decode = decode_1.default; | ||
exports.isBlurhashValid = decode_1.isBlurhashValid; | ||
var encode_1 = require("./encode"); | ||
@@ -10,0 +11,0 @@ exports.encode = encode_1.default; |
{ | ||
"name": "blurhash", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Encoder and decoder for the Wolt BlurHash algorithm.", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
31392
24
389