Comparing version 1.0.0 to 1.1.0
13
index.js
@@ -8,2 +8,3 @@ /* @module to-float32 */ | ||
var clamp = require('clamp') | ||
var flat = require('flatten-vertex-data') | ||
@@ -13,4 +14,14 @@ module.exports = function tou8 (src, detectFloat) { | ||
// if at least one component is an array - flatten data | ||
if (Array.isArray(src)) { | ||
for (var i = 0; i < src.length; i++) { | ||
if (src[i].length != null) { | ||
src = flat(src) | ||
break | ||
} | ||
} | ||
} | ||
// convert float to int | ||
if (isFloat(src)) { | ||
if (isFloat(src)) { | ||
if (detectFloat) { | ||
@@ -17,0 +28,0 @@ // if at least one pixel is more than 1, then does not convert input array |
{ | ||
"name": "to-uint8", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Convert data to Uint8Array", | ||
@@ -29,2 +29,3 @@ "main": "index.js", | ||
"clamp": "^1.0.1", | ||
"flatten-vertex-data": "^1.0.2", | ||
"is-float-array": "^1.0.0", | ||
@@ -31,0 +32,0 @@ "to-array-buffer": "^2.2.2" |
@@ -10,3 +10,3 @@ # to-uint8 [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges) | ||
var pixels = u8([0,0,0,1, 1,1,1,1]) // <Uint8Array 0,0,0,255, 255,255,255,255> | ||
var pixels = u8([[0,0,0,1], [1,1,1,1]]) // <uint8 0,0,0,255, 255,255,255,255> | ||
``` | ||
@@ -19,12 +19,13 @@ | ||
```js | ||
u8(new Uint16Array([0, 1, 2])) // <Uint8Array 0, 1, 2> | ||
u8(new Float32Array([0, .5, 1])) // <Uint8Array 0, 127, 255> | ||
u8(new Float64Array([0, .5, 1])) // <Uint8Array 0, 127, 255> | ||
u8([0, .5, 1]) // <Uint8Array 0, 127, 255> | ||
u8(new Uint16Array([0, 1, 2])) // <uint8 0, 1, 2> | ||
u8(new Float32Array([0, .5, 1])) // <uint8 0, 127, 255> | ||
u8(new Float64Array([0, .5, 1])) // <uint8 0, 127, 255> | ||
u8([0, .5, 1]) // <uint8 0, 127, 255> | ||
u8([[0,0,0,0], [1,1,1,1]]) // <uint8 0,0,0,0, 255,255,255,255> | ||
// untyped array with int-ish values doesn't get converted | ||
u8([0, 1, 255]) // <Uint8Array 0, 1, 255> | ||
u8([0, 1, 255]) // <uint8 0, 1, 255> | ||
// unless passed a flag to force conversion | ||
u8([0, 1, 255], false) // <Uint8Array 0, 255, 255> | ||
u8([0, 1, 255], false) // <uint8 0, 255, 255> | ||
``` | ||
@@ -31,0 +32,0 @@ |
@@ -20,1 +20,3 @@ 'use strict' | ||
a.deepEqual(u8({data: [0, 1, 2]}), [0, 1, 2]) | ||
a.deepEqual(u8([[0,0,0,0], [1,1,1,1]]), [0,0,0,0, 255,255,255,255]) |
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
6455
98
39
4
+ Addedflatten-vertex-data@^1.0.2