2
2
3
3
This is a tiny module to help you convert between JSON data and ArrayBuffer, and you can use it in both Node.js and browsers.
4
4
5
- ## Feature
5
+ ## Features
6
6
7
7
* Convert JSON data to ArrayBuffer.
8
8
* Revert JSON data from ArrayBuffer.
@@ -15,19 +15,15 @@ npm install json-bufferify
15
15
16
16
## Usage
17
17
18
- ### Import json-bufferify.
18
+ ### Step 0 - Import json-bufferify.
19
19
20
20
__ In Node.js__
21
21
22
- CommonJS
23
-
24
22
``` javascript
23
+ // CommonJS
25
24
const bufferify = require (' json-bufferify' );
26
- ```
27
25
28
- ES6 Modules
29
-
30
- ``` javascript
26
+ // ES6 Modules
31
27
import bufferify from ' json-bufferify' ;
32
28
```
33
29
@@ -39,8 +35,12 @@ __In browsers__
39
35
40
36
__ In TypeScript__
41
37
42
- ``` javascript
38
+ ``` typescript
39
+ // Traditional style
43
40
import bufferify = require (' json-bufferify' );
41
+
42
+ // ES6 Modules
43
+ import bufferify from ' json-bufferify' ;
44
44
```
45
45
46
46
__ In Egret__
@@ -54,7 +54,7 @@ Open "egretProperties.json" and Add the following code to "modules" node.
54
54
}
55
55
```
56
56
57
- ### Convert JSON data to ArrayBuffer and send via WebSocket.
57
+ ### Step 1 - Convert JSON data to ArrayBuffer and send via WebSocket.
58
58
59
59
``` javascript
60
60
let ws = new WebSocket (url);
@@ -66,7 +66,7 @@ ws.send(bufferify.encode(0, {
66
66
}));
67
67
```
68
68
69
- ### Revert JSON data from ArrayBuffer.
69
+ ### Step 2 - Revert JSON data from ArrayBuffer.
70
70
71
71
``` javascript
72
72
ws .on (' message' , data => {
@@ -78,7 +78,7 @@ ws.on('message', data => {
78
78
});
79
79
```
80
80
81
- ## API
81
+ ## APIs
82
82
83
83
### bufferify.encode(offset, data)
84
84
@@ -95,7 +95,7 @@ Revert JSON data from ArrayBuffer and return it.
95
95
* ` template ` - The template of the JSON data.
96
96
* ` source ` - The ArrayBuffer, or the Buffer in Node.js, or the DataView of the ArrayBuffer.
97
97
98
- ## Example
98
+ ## Examples
99
99
100
100
### Convert/Revert an array.
101
101
0 commit comments