# flatten-vertex-data

> flattens nested vertex data into a typed array

Latest version **1.0.2** (published 2018-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install flatten-vertex-data
pnpm add flatten-vertex-data
yarn add flatten-vertex-data
bun add flatten-vertex-data
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2018-05-01 |
| First published | 2015-10-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Matt DesLauriers |
| Maintainers | mattdesl |
| Keywords | dtype, flat, flatten, pack, array, type, typed, typedarray, vert, vertex, webgl, gl, glsl, shader, buffer |

## Links

- npm: https://www.npmjs.com/package/flatten-vertex-data
- Repository: https://github.com/glo-js/flatten-vertex-data
- Issues: https://github.com/glo-js/flatten-vertex-data/issues
- npm.io page: https://npm.io/package/flatten-vertex-data

## Dependencies (1)

- [dtype](https://npm.io/package/dtype.md) ^2.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-05-01
- 1.0.1 — 2018-04-23
- 1.0.0 — 2015-10-13

## README

# flatten-vertex-data

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Copies flat or nested array data into the specified typed array, or a new typed array. Intended to be used for WebGL buffers. If the input is nested array data, this guesses the dimensionality based on the length of the first sub-array.

## Install

```sh
npm install flatten-vertex-data --save
```

## Example

Accepts a [dtype string](https://www.npmjs.com/package/dtype) (creating a new array) or an output typed array to re-use. Defaults to creating a new Float32Array.

```js
var flatten = require('flatten-vertex-data')

var positions = [ [x1, y1], [x2, y2], [x3, y3] ]

flatten(positions)
//=> new Float32Array([ x1, y1, x2, y2, x3, y3 ])

flatten(positions, 'uint16')
//=> new Uint16Array([ x1, y1, x2, y2, x3, y3 ])

// flatten & copy positions into output
var output = new Uint16Array(positions.length * 2)
flatten(positions, output)
```

## Usage

[![NPM](https://nodei.co/npm/flatten-vertex-data.png)](https://www.npmjs.com/package/flatten-vertex-data)

#### `output = flatten(data, [output|type], [offset])`

Copies flat or nested arrays into a typed array, where `data` can be:

- a nested array like `[ [ x, y ], [ x, y ] ]`
- a flat array like `[ x, y, z, x, y, z ]`
- a typed array like `new Float32Array([ x, y ])`

The second parameter can be a `type` string for [dtype](https://www.npmjs.com/package/dtype), which creates a new array. Or, it can be an existing typed array to re-use as the `output` destination. It defaults to `'float32'` (a new Float32Array).

Returns the `output` typed array.

The third parameter, `offset`, can be a number (default 0), the index in the destination array at which to start copying the `data`. If a new array is being created, its capacity will be expanded to fit `dataLength + offset` (i.e. it will have leading zeros).

## License

MIT, see [LICENSE.md](http://github.com/glo-js/flatten-vertex-data/blob/master/LICENSE.md) for details.

---
_Source: https://npm.io/package/flatten-vertex-data · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
