Comparing version 1.4.0 to 1.4.1
20
index.js
@@ -25,3 +25,3 @@ /* @module to-float32 */ | ||
for (var i = 0; i < src.length; i++) { | ||
if (src[i].length != null) { | ||
if (src[i] && src[i].length != null) { | ||
src = flat(src) | ||
@@ -39,3 +39,3 @@ break | ||
if (src[i] > 1 || src[i] < 0) { | ||
return new Uint8Array(src) | ||
return uninfinite(new Uint8Array(src), src) | ||
} | ||
@@ -47,6 +47,6 @@ } | ||
for (var i = 0; i < src.length; i++) { | ||
pixels[i] = clamp(src[i] * 255, 0, 255) | ||
pixels[i] = clamp(src[i], 0, 1) * 255 | ||
} | ||
return pixels | ||
return uninfinite(pixels, src) | ||
} | ||
@@ -56,3 +56,3 @@ | ||
if (src.length != null && typeof src !== 'string') { | ||
return new Uint8Array(src) | ||
return uninfinite(new Uint8Array(src), src) | ||
} | ||
@@ -63,3 +63,11 @@ | ||
if (!buf) return null | ||
return new Uint8Array(buf) | ||
return uninfinite(new Uint8Array(buf), src) | ||
} | ||
// disclose infinities | ||
function uninfinite(u, src) { | ||
for (var i = 0; i < src.length; i++) { | ||
if (src[i] === Infinity) u[i] = 255 | ||
} | ||
return u | ||
} |
{ | ||
"name": "to-uint8", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "Convert data to Uint8Array", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -34,4 +34,7 @@ 'use strict' | ||
// detect nested uints | ||
a.deepEqual(u8({data: [0, 1, 1]}), [0, 255, 255]) | ||
// handle NaNs | ||
a.deepEqual(u8([[null, undefined], [NaN, -0], [/abc/, Infinity, -Infinity]]), [0, 0, 0, 0, 0, 255, 0]) | ||
a.deepEqual(u8([null, undefined, NaN, -0, /abc/, Infinity, -Infinity]), [0, 0, 0, 0, 0, 255, 0]) |
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
7761
126