Skip to content

Commit c05f756

Browse files
Added documentation
1 parent e5348bb commit c05f756

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,52 @@
11
# HQTSM: DataView
22

33
Extra DataView functions
4+
5+
# Features
6+
7+
- Pure TypeScript, run anywhere
8+
- Optimized for speed and size
9+
10+
# Usage
11+
12+
## Float16
13+
14+
```js
15+
import { getFloat16, setFloat16 } from '@hqtsm/dataview';
16+
17+
const data = new Uint8Array(4);
18+
const view = new DataView(data.buffer);
19+
setFloat16(view, 0, Math.PI);
20+
setFloat16(view, 2, Math.LN10, true);
21+
console.log(data); // Uint8Array(4) [ 66, 72, 155, 64 ]
22+
console.log(getFloat16(view, 0)); // 3.140625
23+
console.log(getFloat16(view, 2, true)); // 2.302734375
24+
```
25+
26+
## Int24
27+
28+
```js
29+
import { getInt24, setInt24 } from '@hqtsm/dataview';
30+
31+
const data = new Uint8Array(6);
32+
const view = new DataView(data.buffer);
33+
setInt24(view, 0, -1234);
34+
setInt24(view, 3, -4567, true);
35+
console.log(data); // Uint8Array(6) [ 255, 251, 46, 41, 238, 255 ]
36+
console.log(getInt24(view, 0)); // -1234
37+
console.log(getInt24(view, 3, true)); // -4567
38+
```
39+
40+
## Uint24
41+
42+
```js
43+
import { getUint24, setUint24 } from '@hqtsm/dataview';
44+
45+
const data = new Uint8Array(6);
46+
const view = new DataView(data.buffer);
47+
setUint24(view, 0, 12345678);
48+
setUint24(view, 3, 11223344, true);
49+
console.log(data); // Uint8Array(6) [ 188, 97, 78, 48, 65, 171 ]
50+
console.log(getUint24(view, 0)); // 12345678
51+
console.log(getUint24(view, 3, true)); // 11223344
52+
```

0 commit comments

Comments
 (0)