@@ -18,6 +18,7 @@ A basic set of *token types* can be found here: [token-types](https://github.com
18
18
19
19
Below is an example of parsing the the first byte from a readable stream as an unsigned-integer:
20
20
21
+ ###### TypeScript:
21
22
``` TypeScript
22
23
import * as strtok3 from " strtok3" ;
23
24
import * as stream from " stream" ;
@@ -33,6 +34,7 @@ strtok3.fromStream(readableStream).then((tokenizer) => {
33
34
})
34
35
```
35
36
37
+ ###### JavaScript:
36
38
``` JavaScript
37
39
var strtok3 = require (' strtok3' );
38
40
var Token = require (' token-types' );
@@ -42,8 +44,8 @@ var readableStream;
42
44
43
45
44
46
strtok3 .fromStream (readableStream).then ( function (streamTokenizer ) {
45
- return streamTokenizer .readToken (Token .UINT8 ).then ( function (myUint8Number {
46
- console .log (" My number: %s" , myUint8Number);
47
+ return streamTokenizer .readToken (Token .UINT8 ).then ( function (myUint8Number ) {
48
+ console .log (' My number: %s' , myUint8Number);
47
49
});
48
50
})
49
51
```
@@ -52,8 +54,8 @@ strtok3.fromStream(readableStream).then( function(streamTokenizer) {
52
54
53
55
The same can be done from a file:
54
56
57
+ ###### TypeScript:
55
58
``` TypeScript
56
- import * as fs from " fs-extra" ;
57
59
import * as strtok3 from " strtok3" ;
58
60
import * as Token from " token-types" ;
59
61
@@ -62,8 +64,18 @@ strtok3.fromFile("somefile.bin").then((tokenizer) => {
62
64
console .log (" My number: %s" , myUint8Number );
63
65
});
64
66
})
67
+ ```
65
68
66
-
69
+ ###### JavaScript:
70
+ ``` JavaScript
71
+ var strtok3 = require (' strtok3' );
72
+ var Token = require (' token-types' );
73
+
74
+ strtok3 .fromFile (' somefile.bin' ).then ( function (streamTokenizer ) {
75
+ return streamTokenizer .readToken (Token .UINT8 ).then ( function (myUint8Number ) {
76
+ console .log (' My number: %s' , myUint8Number);
77
+ });
78
+ })
67
79
```
68
80
69
81
[ npm-url ] : https://npmjs.org/package/strtok3
0 commit comments