0.1.2 • Published 8 years ago

data-view-builder v0.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
8 years ago

data-view-builder

Utility for creating DataViews

Installation

Installation requires npm

From the command line:

npm install data-view-builder

Usage

Create an instance

var builder = new DataViewBuilder();

Add a value

builder.uint8(123);

Likewise for the other methods: uint16, uint32, int8, int16, int32, float32, float64.

Each method returns the builder instance to allow for chaining.

Build

builder.build();

Returns a DataView of an ArrayBuffer containing the values added between the last call to build and now.

Examples

DataView containing two uint8 values
var builder = new DataViewBuilder();
builder.uint8(11).uint8(22);
var view = builder.build(); // [0xb, 0x16]
DataView containing a float32 followed by a int32
var builder = new DataViewBuilder();
builder.float32(13.37).int32(9001);
var view = builder.build(); // [ 0x41, 0x55, 0xeb, 0x85, 0x0, 0x0, 0x23, 0x29 ]
The builder only takes into account values added since the last call to build
var builder = new DataViewBuilder();
builder.int8(1).int8(2);
var view1 = builder.build(); // [ 0x01, 0x02 ]
var view2 = builder.build(); // [] Empty!
0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago