strtok3 7.0.0-alpha.9 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,15 +1,15 @@
1
- Copyright (c) 2017, Borewit
2
- All rights reserved.
3
-
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
- documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
- rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
- persons to whom the Software is furnished to do so, subject to the following conditions:
8
-
9
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
- Software.
11
-
12
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1
+ Copyright (c) 2017, Borewit
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
7
+ persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
10
+ Software.
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
13
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
14
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
15
15
  OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -1,300 +1,316 @@
1
- ![Node.js CI](https://github.com/Borewit/strtok3/workflows/Node.js%20CI/badge.svg)
2
- [![NPM version](https://badge.fury.io/js/strtok3.svg)](https://npmjs.org/package/strtok3)
3
- [![npm downloads](http://img.shields.io/npm/dm/strtok3.svg)](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
4
- [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/8526/branches/103329/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=8526&bid=103329)
5
- [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/strtok3/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/strtok3?targetFile=package.json)
6
- [![Total alerts](https://img.shields.io/lgtm/alerts/g/Borewit/strtok3.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Borewit/strtok3/alerts/)
7
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/strtok3?utm_source=github.com&utm_medium=referral&utm_content=Borewit/strtok3&utm_campaign=Badge_Grade)
8
- [![Language grade: JavaScript](https://img.shields.io/lgtm/grade/javascript/g/Borewit/strtok3.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Borewit/strtok3/context:javascript)
9
- # strtok3
10
-
11
- A promise based streaming [*tokenizer*](#tokenizer) for [Node.js](http://nodejs.org) and browsers.
12
- This node module is a successor of [strtok2](https://github.com/Borewit/strtok2).
13
-
14
- The `strtok3` contains a few methods to turn different input into a [*tokenizer*](#tokenizer). Designed to
15
- * Support a streaming environment
16
- * Decoding of binary data, strings and numbers in mind
17
- * Read [predefined](https://github.com/Borewit/token-types) or custom tokens.
18
- * Optimized [*tokenizers*](#tokenizer) for reading from [file](#method-strtok3fromfile), [stream](#method-strtok3fromstream) or [buffer](#method-strtok3frombuffer).
19
-
20
- It can read from:
21
- * A file (taking a file path as an input)
22
- * A Node.js [stream](https://nodejs.org/api/stream.html).
23
- * A [Buffer](https://nodejs.org/api/buffer.html) or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
24
- * HTTP chunked transfer provided by [@tokenizer/http](https://github.com/Borewit/tokenizer-http).
25
- * Chunked [Amazon S3](https://aws.amazon.com/s3) access provided by [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3).
26
-
27
- ## Installation
28
-
29
- ```sh
30
- npm install strtok3
31
- ```
32
-
33
- ## API
34
-
35
- Use one of the methods to instantiate an [*abstract tokenizer*](#tokenizer):
36
- * [strtok3.fromFile](#method-strtok3fromfile)
37
- * [strtok3.fromStream](#method-strtok3fromstream)
38
- * [strtok3.fromBuffer](#method-strtok3fromBuffer)
39
- * [strtok3.fromUint8Array](#method-strtok3fromUint8Array)
40
-
41
- ### strtok3 methods
42
-
43
- All of the strtok3 methods return a [*tokenizer*](#tokenizer), either directly or via a promise.
44
-
45
- #### Method `strtok3.fromFile()`
46
-
47
- | Parameter | Type | Description |
48
- |-----------|-----------------------|----------------------------|
49
- | path | Path to file (string) | Path to file to read from |
50
-
51
- > __Note__: that [file-information](#file-information) is automatically added.
52
-
53
- Returns, via a promise, a [*tokenizer*](#tokenizer) which can be used to parse a file.
54
-
55
- ```js
56
- const strtok3 = require('strtok3');
57
- const Token = require('token-types');
58
-
59
- (async () => {
60
-
61
- const tokenizer = await strtok3.fromFile("somefile.bin");
62
- try {
63
- const myNumber = await tokenizer.readToken(Token.UINT8);
64
- console.log(`My number: ${myNumber}`);
65
- } finally {
66
- tokenizer.close(); // Close the file
67
- }
68
- })();
69
-
70
- ```
71
-
72
- #### Method `strtok3.fromStream()`
73
-
74
- Create [*tokenizer*](#tokenizer) from a node.js [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
75
-
76
- | Parameter | Optional | Type | Description |
77
- |-----------|-----------|-----------------------------------------------------------------------------|--------------------------|
78
- | stream | no | [Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) | Stream to read from |
79
- | fileInfo | yes | [IFileInfo](#IFileInfo) | Provide file information |
80
-
81
- Returns a [*tokenizer*](#tokenizer), via a Promise, which can be used to parse a buffer.
82
-
83
- ```js
84
- const strtok3 = require('strtok3');
85
- const Token = require('token-types');
86
-
87
- strtok3.fromStream(stream).then(tokenizer => {
88
- return tokenizer.readToken(Token.UINT8).then(myUint8Number => {
89
- console.log(`My number: ${myUint8Number}`);
90
- });
91
- });
92
- ```
93
-
94
- #### Method `strtok3.fromBuffer()`
95
-
96
- | Parameter | Optional | Type | Description |
97
- |------------|----------|--------------------------------------------------|----------------------------------------|
98
- | uint8Array | no | [Uint8Array](https://nodejs.org/api/buffer.html) | Uint8Array or Buffer to read from |
99
- | fileInfo | yes | [IFileInfo](#IFileInfo) | Provide file information |
100
-
101
- Returns a [*tokenizer*](#tokenizer) which can be used to parse the provided buffer.
102
-
103
- ```js
104
- const strtok3 = require('strtok3');
105
-
106
- const tokenizer = strtok3.fromBuffer(buffer);
107
-
108
- tokenizer.readToken(Token.UINT8).then(myUint8Number => {
109
- console.log(`My number: ${myUint8Number}`);
110
- });
111
- ```
112
-
113
- ## Tokenizer
114
- The tokenizer allows us to *read* or *peek* from the *tokenizer-stream*. The *tokenizer-stream* is an abstraction of a [stream](https://nodejs.org/api/stream.html), file or [Buffer](https://nodejs.org/api/buffer.html).
115
- It can also be translated in chunked reads, as done in [@tokenizer/http](https://github.com/Borewit/tokenizer-http);
116
-
117
- What is the difference with Nodejs.js stream?
118
- * The *tokenizer-stream* supports jumping / seeking in a the *tokenizer-stream* using [`tokenizer.ignore()`](#method-tokenizerignore)
119
- * In addition to *read* methods, it has *peek* methods, to read a ahead and check what is coming.
120
-
121
- The [tokenizer.position](#attribute-tokenizerposition) keeps tracks of the read position.
122
-
123
- ### strtok3 attributes
124
-
125
- #### Attribute `tokenizer.fileInfo`
126
- Optional attribute describing the file information, see [IFileInfo](#IFileInfo)
127
-
128
- #### Attribute `tokenizer.position`
129
- Pointer to the current position in the [*tokenizer*](#tokenizer) stream.
130
- If a *position* is provided to a *read* or *peek* method, is should be, at least, equal or greater than this value.
131
-
132
- ### Tokenizer methods
133
-
134
- There are two kind of methods:
135
- 1. *read* methods: used to read a *token* of [Buffer](https://nodejs.org/api/buffer.html) from the [*tokenizer*](#tokenizer). The position of the *tokenizer-stream* will advance with the size of the token.
136
- 2. *peek* methods: same as the read, but it will *not* advance the pointer. It allows to read (peek) ahead.
137
-
138
- #### Method `tokenizer.readBuffer()`
139
-
140
- Read buffer from stream.
141
- `readBuffer(buffer, options?)`
142
-
143
- | Parameter | Type | Description |
144
- |------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
145
- | buffer | [Buffer](https://nodejs.org/api/buffer.html) | Uint8Array | Target buffer to write the data read to |
146
- | options | [IReadChunkOptions](#ireadchunkoptions) | An integer specifying the number of bytes to read |
147
-
148
- Return value `Promise<number>` Promise with number of bytes read. The number of bytes read maybe if less, *mayBeLess* flag was set.
149
-
150
- #### Method `tokenizer.peekBuffer()`
151
-
152
- Peek (read ahead) buffer from [*tokenizer*](#tokenizer)
153
- `peekBuffer(buffer, options?)`
154
-
155
- | Parameter | Type | Description |
156
- |------------|-----------------------------------------|-----------------------------------------------------|
157
- | buffer | Buffer &#124; Uint8Array | Target buffer to write the data read (peeked) to. |
158
- | options | [IReadChunkOptions](#ireadchunkoptions) | An integer specifying the number of bytes to read. | |
159
-
160
- Return value `Promise<number>` Promise with number of bytes read. The number of bytes read maybe if less, *mayBeLess* flag was set.
161
-
162
- #### Method `tokenizer.readToken()`
163
-
164
- Read a *token* from the tokenizer-stream.
165
- `readToken(token, position?)`
166
-
167
- | Parameter | Type | Description |
168
- |------------|-------------------------|---------------------------------------------------------------------------------------------------------------------- |
169
- | token | [IGetToken](#IGetToken) | Token to read from the tokenizer-stream. |
170
- | position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
171
-
172
- Return value `Promise<number>`. Promise with number of bytes read. The number of bytes read maybe if less, *mayBeLess* flag was set.
173
-
174
- #### Method `tokenizer.peekToken()`
175
-
176
- Peek a *token* from the [*tokenizer*](#tokenizer).
177
- `peekToken(token, position?)`
178
-
179
- | Parameter | Type | Description |
180
- |------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------|
181
- | token | [IGetToken<T>](#IGetToken) | Token to read from the tokenizer-stream. |
182
- | position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
183
-
184
- Return value `Promise<T>` Promise with token value peeked from the [*tokenizer*](#tokenizer).
185
-
186
- #### Method `tokenizer.readNumber()`
187
-
188
- Peek a numeric [*token*](#token) from the [*tokenizer*](#tokenizer).
189
- `readNumber(token)`
190
-
191
- | Parameter | Type | Description |
192
- |------------|---------------------------------|----------------------------------------------------|
193
- | token | [IGetToken<number>](#IGetToken) | Numeric token to read from the tokenizer-stream. |
194
-
195
- Return value `Promise<number>` Promise with number peeked from the *tokenizer-stream*.
196
-
197
- #### Method `tokenizer.ignore()`
198
-
199
- Advanse the offset pointer with the number of bytes provided.
200
- `ignore(length)`
201
-
202
- | Parameter | Type | Description |
203
- |------------|--------|----------------------------------------------------------------------|
204
- | ignore | number | Numeric of bytes to ignore. Will advance the `tokenizer.position` |
205
-
206
- Return value `Promise<number>` Promise with number peeked from the *tokenizer-stream*.
207
-
208
- #### Method `tokenizer.close()`
209
- Clean up resources, such as closing a file pointer if applicable.
210
-
211
- ### IReadChunkOptions
212
-
213
- Each attribute is optional:
214
-
215
- | Attribute | Type | Description |
216
- |-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
217
- | offset | number | The offset in the buffer to start writing at; if not provided, start at 0 |
218
- | length | number | Requested number of bytes to read. |
219
- | position | number | Position where to peek from the file. If position is null, data will be read from the [current file position](#attribute-tokenizerposition). Position may not be less then [tokenizer.position](#attribute-tokenizerposition) |
220
- | mayBeLess | boolean | If and only if set, will not throw an EOF error if less then the requested *mayBeLess* could be read. |
221
-
222
- Example:
223
- ```js
224
- tokenizer.peekBuffer(buffer, {mayBeLess: true});
225
- ```
226
-
227
- ## IFileInfo
228
-
229
- File information interface which describes the underlying file, each attribute is optional.
230
-
231
- | Attribute | Type | Description |
232
- |-----------|---------|---------------------------------------------------------------------------------------------------|
233
- | size | number | File size in bytes |
234
- | mimeType | number | [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of file. |
235
- | path | number | File path |
236
- | url | boolean | File URL |
237
-
238
- ## Token
239
-
240
- The *token* is basically a description what to read form the [*tokenizer-stream*](#tokenizer).
241
- A basic set of *token types* can be found here: [*token-types*](https://github.com/Borewit/token-types).
242
-
243
- A token is something which implements the following interface:
244
- ```ts
245
- export interface IGetToken<T> {
246
-
247
- /**
248
- * Length in bytes of encoded value
249
- */
250
- len: number;
251
-
252
- /**
253
- * Decode value from buffer at offset
254
- * @param buf Buffer to read the decoded value from
255
- * @param off Decode offset
256
- */
257
- get(buf: Buffer, off: number): T;
258
- }
259
- ```
260
- The *tokenizer* reads `token.len` bytes from the *tokenizer-stream* into a Buffer.
261
- The `token.get` will be called with the Buffer. `token.get` is responsible for conversion from the buffer to the desired output type.
262
-
263
- ## Browser compatibility
264
- To exclude fs based dependencies, you can use a submodule-import from 'strtok3/lib/core'.
265
-
266
- | function | 'strtok3' | 'strtok3/lib/core' |
267
- | ----------------------| --------------------|---------------------|
268
- | `parseBuffer` | ✓ | ✓ |
269
- | `parseStream` | ✓ | ✓ |
270
- | `fromFile` | ✓ | |
271
-
272
- ### Working with Web-API readable stream
273
- To convert a [Web-API readable stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader) into a [Node.js readable stream]((https://nodejs.org/api/stream.html#stream_readable_streams)), you can use [readable-web-to-node-stream](https://github.com/Borewit/readable-web-to-node-stream) to convert one in another.
274
-
275
- Example submodule-import:
276
- ```js
277
- const strtok3core = require('strtok3/lib/core'); // Submodule-import to prevent Node.js specific dependencies
278
- const {ReadableWebToNodeStream} = require('readable-web-to-node-stream');
279
-
280
- (async () => {
281
-
282
- const response = await fetch(url);
283
- const readableWebStream = response.body; // Web-API readable stream
284
- const nodeStream = new ReadableWebToNodeStream(readableWebStream); // convert to Node.js readable stream
285
-
286
- const tokenizer = strtok3core.fromStream(nodeStream); // And we now have tokenizer in a web environment
287
- })();
288
- ```
289
-
290
- ## Licence
291
-
292
- (The MIT License)
293
-
294
- Copyright (c) 2020 Borewit
295
-
296
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
297
-
298
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
299
-
300
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ ![Node.js CI](https://github.com/Borewit/strtok3/workflows/Node.js%20CI/badge.svg)
2
+ [![NPM version](https://badge.fury.io/js/strtok3.svg)](https://npmjs.org/package/strtok3)
3
+ [![npm downloads](http://img.shields.io/npm/dm/strtok3.svg)](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
4
+ [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/8526/branches/103329/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=8526&bid=103329)
5
+ [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/strtok3/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/strtok3?targetFile=package.json)
6
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/strtok3?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Borewit/strtok3&amp;utm_campaign=Badge_Grade)
7
+ # strtok3
8
+
9
+ A promise based streaming [*tokenizer*](#tokenizer) for [Node.js](http://nodejs.org) and browsers.
10
+ This node module is a successor of [strtok2](https://github.com/Borewit/strtok2).
11
+
12
+ The `strtok3` contains a few methods to turn different input into a [*tokenizer*](#tokenizer). Designed to
13
+ * Support a streaming environment
14
+ * Decoding of binary data, strings and numbers in mind
15
+ * Read [predefined](https://github.com/Borewit/token-types) or custom tokens.
16
+ * Optimized [*tokenizers*](#tokenizer) for reading from [file](#method-strtok3fromfile), [stream](#method-strtok3fromstream) or [buffer](#method-strtok3frombuffer).
17
+
18
+ It can read from:
19
+ * A file (taking a file path as an input)
20
+ * A Node.js [stream](https://nodejs.org/api/stream.html).
21
+ * A [Buffer](https://nodejs.org/api/buffer.html) or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)
22
+ * HTTP chunked transfer provided by [@tokenizer/http](https://github.com/Borewit/tokenizer-http).
23
+ * Chunked [Amazon S3](https://aws.amazon.com/s3) access provided by [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3).
24
+
25
+ ## Installation
26
+
27
+ ```sh
28
+ npm install strtok3
29
+ ```
30
+
31
+ ### Compatibility
32
+
33
+ Module: version 7 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
34
+ JavaScript is compliant with [ECMAScript 2019 (ES10)](https://en.wikipedia.org/wiki/ECMAScript#10th_Edition_%E2%80%93_ECMAScript_2019).
35
+ Requires Node.js ≥ 14.16 engine.
36
+
37
+ ## API
38
+
39
+ Use one of the methods to instantiate an [*abstract tokenizer*](#tokenizer):
40
+ * [strtok3.fromFile](#method-strtok3fromfile)
41
+ * [strtok3.fromStream](#method-strtok3fromstream)
42
+ * [strtok3.fromWeb](#method-strtok3fromwebstream)
43
+ * [strtok3.fromBuffer](#method-strtok3fromBuffer)
44
+ * [strtok3.fromUint8Array](#method-strtok3fromUint8Array)
45
+
46
+ ### strtok3 methods
47
+
48
+ All of the strtok3 methods return a [*tokenizer*](#tokenizer), either directly or via a promise.
49
+
50
+ #### Method `strtok3.fromFile()`
51
+
52
+ | Parameter | Type | Description |
53
+ |-----------|-----------------------|----------------------------|
54
+ | path | Path to file (string) | Path to file to read from |
55
+
56
+ > __Note__: that [file-information](#file-information) is automatically added.
57
+
58
+ Returns, via a promise, a [*tokenizer*](#tokenizer) which can be used to parse a file.
59
+
60
+ ```js
61
+ import * as strtok3 from 'strtok3';
62
+ import * as Token from 'token-types';
63
+
64
+ (async () => {
65
+
66
+ const tokenizer = await strtok3.fromFile("somefile.bin");
67
+ try {
68
+ const myNumber = await tokenizer.readToken(Token.UINT8);
69
+ console.log(`My number: ${myNumber}`);
70
+ } finally {
71
+ tokenizer.close(); // Close the file
72
+ }
73
+ })();
74
+
75
+ ```
76
+
77
+ #### Method `strtok3.fromStream()`
78
+
79
+ Create [*tokenizer*](#tokenizer) from a Node.js [readable stream](https://nodejs.org/api/stream.html#stream_class_stream_readable).
80
+
81
+ | Parameter | Optional | Type | Description |
82
+ |-----------|-----------|-----------------------------------------------------------------------------|--------------------------|
83
+ | stream | no | [Readable](https://nodejs.org/api/stream.html#stream_class_stream_readable) | Stream to read from |
84
+ | fileInfo | yes | [IFileInfo](#IFileInfo) | Provide file information |
85
+
86
+ Returns a Promise providing a [*tokenizer*](#tokenizer).
87
+
88
+ #### Method `strtok3.fromWebStream()`
89
+
90
+ Create [*tokenizer*](#tokenizer) from a [WHATWG ReadableStream](https://nodejs.org/api/webstreams.html#web-streams-api).
91
+
92
+ | Parameter | Optional | Type | Description |
93
+ |----------------|-----------|--------------------------------------------------------------------------|------------------------------------|
94
+ | readableStream | no | [ReadableStream](https://nodejs.org/api/webstreams.html#web-streams-api) | WHATWG ReadableStream to read from |
95
+ | fileInfo | yes | [IFileInfo](#IFileInfo) | Provide file information |
96
+
97
+ Returns a Promise providing a [*tokenizer*](#tokenizer)
98
+
99
+ ```js
100
+ import strtok3 from 'strtok3';
101
+ import * as Token from 'token-types';
102
+
103
+ strtok3.fromWebStream(readableStream).then(tokenizer => {
104
+ return tokenizer.readToken(Token.UINT8).then(myUint8Number => {
105
+ console.log(`My number: ${myUint8Number}`);
106
+ });
107
+ });
108
+ ```
109
+
110
+ #### Method `strtok3.fromBuffer()`
111
+
112
+ | Parameter | Optional | Type | Description |
113
+ |------------|----------|--------------------------------------------------|----------------------------------------|
114
+ | uint8Array | no | [Uint8Array](https://nodejs.org/api/buffer.html) | Uint8Array or Buffer to read from |
115
+ | fileInfo | yes | [IFileInfo](#IFileInfo) | Provide file information |
116
+
117
+ Returns a Promise providing a [*tokenizer*](#tokenizer).
118
+
119
+ ```js
120
+ import * as strtok3 from 'strtok3';
121
+
122
+ const tokenizer = strtok3.fromBuffer(buffer);
123
+
124
+ tokenizer.readToken(Token.UINT8).then(myUint8Number => {
125
+ console.log(`My number: ${myUint8Number}`);
126
+ });
127
+ ```
128
+
129
+ ## Tokenizer
130
+ The tokenizer allows us to *read* or *peek* from the *tokenizer-stream*. The *tokenizer-stream* is an abstraction of a [stream](https://nodejs.org/api/stream.html), file or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
131
+ It can also be translated in chunked reads, as done in [@tokenizer/http](https://github.com/Borewit/tokenizer-http);
132
+
133
+ What is the difference with Nodejs.js stream?
134
+ * The *tokenizer-stream* supports jumping / seeking in a the *tokenizer-stream* using [`tokenizer.ignore()`](#method-tokenizerignore)
135
+ * In addition to *read* methods, it has *peek* methods, to read a ahead and check what is coming.
136
+
137
+ The [tokenizer.position](#attribute-tokenizerposition) keeps tracks of the read position.
138
+
139
+ ### strtok3 attributes
140
+
141
+ #### Attribute `tokenizer.fileInfo`
142
+ Optional attribute describing the file information, see [IFileInfo](#IFileInfo)
143
+
144
+ #### Attribute `tokenizer.position`
145
+ Pointer to the current position in the [*tokenizer*](#tokenizer) stream.
146
+ If a *position* is provided to a *read* or *peek* method, is should be, at least, equal or greater than this value.
147
+
148
+ ### Tokenizer methods
149
+
150
+ There are two kind of methods:
151
+ 1. *read* methods: used to read a *token* of [Buffer](https://nodejs.org/api/buffer.html) from the [*tokenizer*](#tokenizer). The position of the *tokenizer-stream* will advance with the size of the token.
152
+ 2. *peek* methods: same as the read, but it will *not* advance the pointer. It allows to read (peek) ahead.
153
+
154
+ #### Method `tokenizer.readBuffer()`
155
+
156
+ Read buffer from stream.
157
+ `readBuffer(buffer, options?)`
158
+
159
+ | Parameter | Type | Description |
160
+ |------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
161
+ | buffer | [Buffer](https://nodejs.org/api/buffer.html) &#124; Uint8Array | Target buffer to write the data read to |
162
+ | options | [IReadChunkOptions](#ireadchunkoptions) | An integer specifying the number of bytes to read |
163
+
164
+ Return value `Promise<number>` Promise with number of bytes read. The number of bytes read maybe if less, *mayBeLess* flag was set.
165
+
166
+ #### Method `tokenizer.peekBuffer()`
167
+
168
+ Peek (read ahead) buffer from [*tokenizer*](#tokenizer)
169
+ `peekBuffer(buffer, options?)`
170
+
171
+ | Parameter | Type | Description |
172
+ |------------|-----------------------------------------|-----------------------------------------------------|
173
+ | buffer | Buffer &#124; Uint8Array | Target buffer to write the data read (peeked) to. |
174
+ | options | [IReadChunkOptions](#ireadchunkoptions) | An integer specifying the number of bytes to read. | |
175
+
176
+ Return value `Promise<number>` Promise with number of bytes read. The number of bytes read maybe if less, *mayBeLess* flag was set.
177
+
178
+ #### Method `tokenizer.readToken()`
179
+
180
+ Read a *token* from the tokenizer-stream.
181
+ `readToken(token, position?)`
182
+
183
+ | Parameter | Type | Description |
184
+ |------------|-------------------------|---------------------------------------------------------------------------------------------------------------------- |
185
+ | token | [IGetToken](#IGetToken) | Token to read from the tokenizer-stream. |
186
+ | position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
187
+
188
+ Return value `Promise<number>`. Promise with number of bytes read. The number of bytes read maybe if less, *mayBeLess* flag was set.
189
+
190
+ #### Method `tokenizer.peekToken()`
191
+
192
+ Peek a *token* from the [*tokenizer*](#tokenizer).
193
+ `peekToken(token, position?)`
194
+
195
+ | Parameter | Type | Description |
196
+ |------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------|
197
+ | token | [IGetToken<T>](#IGetToken) | Token to read from the tokenizer-stream. |
198
+ | position? | number | Offset where to begin reading within the file. If position is null, data will be read from the current file position. |
199
+
200
+ Return value `Promise<T>` Promise with token value peeked from the [*tokenizer*](#tokenizer).
201
+
202
+ #### Method `tokenizer.readNumber()`
203
+
204
+ Peek a numeric [*token*](#token) from the [*tokenizer*](#tokenizer).
205
+ `readNumber(token)`
206
+
207
+ | Parameter | Type | Description |
208
+ |------------|---------------------------------|----------------------------------------------------|
209
+ | token | [IGetToken<number>](#IGetToken) | Numeric token to read from the tokenizer-stream. |
210
+
211
+ Return value `Promise<number>` Promise with number peeked from the *tokenizer-stream*.
212
+
213
+ #### Method `tokenizer.ignore()`
214
+
215
+ Advance the offset pointer with the number of bytes provided.
216
+ `ignore(length)`
217
+
218
+ | Parameter | Type | Description |
219
+ |------------|--------|----------------------------------------------------------------------|
220
+ | ignore | number | Numeric of bytes to ignore. Will advance the `tokenizer.position` |
221
+
222
+ Return value `Promise<number>` Promise with number peeked from the *tokenizer-stream*.
223
+
224
+ #### Method `tokenizer.close()`
225
+ Clean up resources, such as closing a file pointer if applicable.
226
+
227
+ ### IReadChunkOptions
228
+
229
+ Each attribute is optional:
230
+
231
+ | Attribute | Type | Description |
232
+ |-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
233
+ | offset | number | The offset in the buffer to start writing at; if not provided, start at 0 |
234
+ | length | number | Requested number of bytes to read. |
235
+ | position | number | Position where to peek from the file. If position is null, data will be read from the [current file position](#attribute-tokenizerposition). Position may not be less then [tokenizer.position](#attribute-tokenizerposition) |
236
+ | mayBeLess | boolean | If and only if set, will not throw an EOF error if less then the requested *mayBeLess* could be read. |
237
+
238
+ Example:
239
+ ```js
240
+ tokenizer.peekBuffer(buffer, {mayBeLess: true});
241
+ ```
242
+
243
+ ## IFileInfo
244
+
245
+ File information interface which describes the underlying file, each attribute is optional.
246
+
247
+ | Attribute | Type | Description |
248
+ |-----------|---------|---------------------------------------------------------------------------------------------------|
249
+ | size | number | File size in bytes |
250
+ | mimeType | number | [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of file. |
251
+ | path | number | File path |
252
+ | url | boolean | File URL |
253
+
254
+ ## Token
255
+
256
+ The *token* is basically a description what to read form the [*tokenizer-stream*](#tokenizer).
257
+ A basic set of *token types* can be found here: [*token-types*](https://github.com/Borewit/token-types).
258
+
259
+ A token is something which implements the following interface:
260
+ ```ts
261
+ export interface IGetToken<T> {
262
+
263
+ /**
264
+ * Length in bytes of encoded value
265
+ */
266
+ len: number;
267
+
268
+ /**
269
+ * Decode value from buffer at offset
270
+ * @param buf Buffer to read the decoded value from
271
+ * @param off Decode offset
272
+ */
273
+ get(buf: Uint8Array, off: number): T;
274
+ }
275
+ ```
276
+ The *tokenizer* reads `token.len` bytes from the *tokenizer-stream* into a Buffer.
277
+ The `token.get` will be called with the Buffer. `token.get` is responsible for conversion from the buffer to the desired output type.
278
+
279
+ ## Browser compatibility
280
+ To exclude fs based dependencies, you can use a submodule-import from 'strtok3/lib/core'.
281
+
282
+ | function | 'strtok3' | 'strtok3/lib/core' |
283
+ | ----------------------| --------------------|---------------------|
284
+ | `parseBuffer` | ✓ | ✓ |
285
+ | `parseStream` | ✓ | ✓ |
286
+ | `fromFile` | ✓ | |
287
+
288
+ ### Working with Web-API readable stream
289
+ To convert a [Web-API readable stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStreamDefaultReader) into a [Node.js readable stream]((https://nodejs.org/api/stream.html#stream_readable_streams)), you can use [readable-web-to-node-stream](https://github.com/Borewit/readable-web-to-node-stream) to convert one in another.
290
+
291
+ Example submodule-import:
292
+ ```js
293
+ import * as strtok3core from 'strtok3/core'; // Submodule-import to prevent Node.js specific dependencies
294
+ import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
295
+
296
+ (async () => {
297
+
298
+ const response = await fetch(url);
299
+ const readableWebStream = response.body; // Web-API readable stream
300
+ const nodeStream = new ReadableWebToNodeStream(readableWebStream); // convert to Node.js readable stream
301
+
302
+ const tokenizer = strtok3core.fromStream(nodeStream); // And we now have tokenizer in a web environment
303
+ })();
304
+ ```
305
+
306
+ ## Licence
307
+
308
+ (The MIT License)
309
+
310
+ Copyright (c) 2020 Borewit
311
+
312
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
313
+
314
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
315
+
316
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -58,7 +58,7 @@ export declare abstract class AbstractTokenizer implements ITokenizer {
58
58
  */
59
59
  peekNumber(token: IToken<number>): Promise<number>;
60
60
  /**
61
- * Ignore number of bytes, advances the pointer in under tokenizer-stream.
61
+ * Ignore number of bytes, advances the pointer in under tokenizer-stream.
62
62
  * @param length - Number of bytes to ignore
63
63
  * @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
64
64
  */
@@ -1,5 +1,4 @@
1
1
  import { EndOfStreamError } from 'peek-readable';
2
- import { Buffer } from 'node:buffer';
3
2
  /**
4
3
  * Core tokenizer
5
4
  */
@@ -19,7 +18,7 @@ export class AbstractTokenizer {
19
18
  * @returns Promise with token data
20
19
  */
21
20
  async readToken(token, position = this.position) {
22
- const uint8Array = Buffer.alloc(token.len);
21
+ const uint8Array = new Uint8Array(token.len);
23
22
  const len = await this.readBuffer(uint8Array, { position });
24
23
  if (len < token.len)
25
24
  throw new EndOfStreamError();
@@ -32,7 +31,7 @@ export class AbstractTokenizer {
32
31
  * @returns Promise with token data
33
32
  */
34
33
  async peekToken(token, position = this.position) {
35
- const uint8Array = Buffer.alloc(token.len);
34
+ const uint8Array = new Uint8Array(token.len);
36
35
  const len = await this.peekBuffer(uint8Array, { position });
37
36
  if (len < token.len)
38
37
  throw new EndOfStreamError();
@@ -61,7 +60,7 @@ export class AbstractTokenizer {
61
60
  return token.get(this.numBuffer, 0);
62
61
  }
63
62
  /**
64
- * Ignore number of bytes, advances the pointer in under tokenizer-stream.
63
+ * Ignore number of bytes, advances the pointer in under tokenizer-stream.
65
64
  * @param length - Number of bytes to ignore
66
65
  * @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
67
66
  */
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Module convert fs functions to promise based functions
3
3
  */
4
- /// <reference types="node" />
5
4
  import fs from 'node:fs';
6
5
  export interface IReadResult {
7
6
  bytesRead: number;
@@ -13,6 +12,6 @@ export declare function stat(path: fs.PathLike): Promise<fs.Stats>;
13
12
  export declare function close(fd: number): Promise<void>;
14
13
  export declare function open(path: fs.PathLike, mode: fs.Mode): Promise<number>;
15
14
  export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): Promise<IReadResult>;
16
- export declare function writeFile(path: fs.PathLike, data: Buffer | string): Promise<void>;
17
- export declare function writeFileSync(path: fs.PathLike, data: Buffer | string): void;
18
- export declare function readFile(path: fs.PathLike): Promise<Buffer>;
15
+ export declare function writeFile(path: fs.PathLike, data: Uint8Array | string, options?: fs.WriteFileOptions): Promise<void>;
16
+ export declare function writeFileSync(path: fs.PathLike, data: Uint8Array | string): void;
17
+ export declare function readFile(path: fs.PathLike): Promise<Uint8Array>;
package/lib/FsPromise.js CHANGED
@@ -44,9 +44,9 @@ export async function read(fd, buffer, offset, length, position) {
44
44
  });
45
45
  });
46
46
  }
47
- export async function writeFile(path, data) {
47
+ export async function writeFile(path, data, options = null) {
48
48
  return new Promise((resolve, reject) => {
49
- fs.writeFile(path, data, err => {
49
+ fs.writeFile(path, data, options, err => {
50
50
  if (err)
51
51
  reject(err);
52
52
  else
@@ -1,10 +1,9 @@
1
- /// <reference types="node" />
2
1
  import { AbstractTokenizer } from './AbstractTokenizer.js';
3
- import { Readable } from 'node:stream';
2
+ import { IStreamReader } from 'peek-readable';
4
3
  import { IFileInfo, IReadChunkOptions } from './types.js';
5
4
  export declare class ReadStreamTokenizer extends AbstractTokenizer {
6
5
  private streamReader;
7
- constructor(stream: Readable, fileInfo?: IFileInfo);
6
+ constructor(streamReader: IStreamReader, fileInfo?: IFileInfo);
8
7
  /**
9
8
  * Get file information, an HTTP-client may implement this doing a HEAD request
10
9
  * @return Promise with file information
@@ -1,10 +1,10 @@
1
1
  import { AbstractTokenizer } from './AbstractTokenizer.js';
2
- import { EndOfStreamError, StreamReader } from 'peek-readable';
2
+ import { EndOfStreamError } from 'peek-readable';
3
3
  const maxBufferSize = 256000;
4
4
  export class ReadStreamTokenizer extends AbstractTokenizer {
5
- constructor(stream, fileInfo) {
5
+ constructor(streamReader, fileInfo) {
6
6
  super(fileInfo);
7
- this.streamReader = new StreamReader(stream);
7
+ this.streamReader = streamReader;
8
8
  }
9
9
  /**
10
10
  * Get file information, an HTTP-client may implement this doing a HEAD request
package/lib/core.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- /// <reference types="node" />
2
1
  import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
3
2
  import { Readable } from 'node:stream';
4
3
  import { BufferTokenizer } from './BufferTokenizer.js';
5
4
  import { IFileInfo } from './types.js';
5
+ import type { ReadableStream } from 'node:stream/web';
6
6
  export { EndOfStreamError } from 'peek-readable';
7
7
  export { ITokenizer, IFileInfo } from './types.js';
8
8
  export { IToken, IGetToken } from '@tokenizer/token';
@@ -14,6 +14,14 @@ export { IToken, IGetToken } from '@tokenizer/token';
14
14
  * @returns ReadStreamTokenizer
15
15
  */
16
16
  export declare function fromStream(stream: Readable, fileInfo?: IFileInfo): ReadStreamTokenizer;
17
+ /**
18
+ * Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
19
+ * Will set fileSize, if provided given Stream has set the .path property/
20
+ * @param webStream - Read from Node.js Stream.Readable
21
+ * @param fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
22
+ * @returns ReadStreamTokenizer
23
+ */
24
+ export declare function fromWebStream(webStream: ReadableStream<Uint8Array>, fileInfo?: IFileInfo): ReadStreamTokenizer;
17
25
  /**
18
26
  * Construct ReadStreamTokenizer from given Buffer.
19
27
  * @param uint8Array - Uint8Array to tokenize
package/lib/core.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
2
  import { BufferTokenizer } from './BufferTokenizer.js';
3
+ import { StreamReader, WebStreamReader } from "peek-readable";
3
4
  export { EndOfStreamError } from 'peek-readable';
4
5
  /**
5
6
  * Construct ReadStreamTokenizer from given Stream.
@@ -10,7 +11,18 @@ export { EndOfStreamError } from 'peek-readable';
10
11
  */
11
12
  export function fromStream(stream, fileInfo) {
12
13
  fileInfo = fileInfo ? fileInfo : {};
13
- return new ReadStreamTokenizer(stream, fileInfo);
14
+ return new ReadStreamTokenizer(new StreamReader(stream), fileInfo);
15
+ }
16
+ /**
17
+ * Construct ReadStreamTokenizer from given ReadableStream (WebStream API).
18
+ * Will set fileSize, if provided given Stream has set the .path property/
19
+ * @param webStream - Read from Node.js Stream.Readable
20
+ * @param fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
21
+ * @returns ReadStreamTokenizer
22
+ */
23
+ export function fromWebStream(webStream, fileInfo) {
24
+ fileInfo = fileInfo ? fileInfo : {};
25
+ return new ReadStreamTokenizer(new WebStreamReader(webStream), fileInfo);
14
26
  }
15
27
  /**
16
28
  * Construct ReadStreamTokenizer from given Buffer.
package/lib/index.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- /// <reference types="node" />
2
1
  import { Readable } from 'node:stream';
3
2
  import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
4
3
  import * as core from './core.js';
5
4
  export { fromFile } from './FileTokenizer.js';
6
- export { ITokenizer, EndOfStreamError, fromBuffer, IFileInfo } from './core.js';
5
+ export { ITokenizer, EndOfStreamError, fromBuffer, fromWebStream, IFileInfo } from './core.js';
7
6
  export { IToken, IGetToken } from '@tokenizer/token';
8
7
  /**
9
8
  * Construct ReadStreamTokenizer from given Stream.
package/lib/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as fs from './FsPromise.js';
2
2
  import * as core from './core.js';
3
3
  export { fromFile } from './FileTokenizer.js';
4
- export { EndOfStreamError, fromBuffer } from './core.js';
4
+ export { EndOfStreamError, fromBuffer, fromWebStream } from './core.js';
5
5
  /**
6
6
  * Construct ReadStreamTokenizer from given Stream.
7
7
  * Will set fileSize, if provided given Stream has set the .path property.
package/lib/types.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import { IGetToken } from '@tokenizer/token';
3
2
  export interface IFileInfo {
4
3
  /**
@@ -57,14 +56,14 @@ export interface ITokenizer {
57
56
  * @param options - Read behaviour options
58
57
  * @returns Promise with number of bytes read
59
58
  */
60
- peekBuffer(buffer: Buffer, options?: IReadChunkOptions): Promise<number>;
59
+ peekBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
61
60
  /**
62
61
  * Peek (read ahead) buffer from tokenizer
63
62
  * @param buffer - Target buffer to fill with data peeked from the tokenizer-stream
64
63
  * @param options - Additional read options
65
64
  * @returns Promise with number of bytes read
66
65
  */
67
- readBuffer(buffer: Buffer, options?: IReadChunkOptions): Promise<number>;
66
+ readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
68
67
  /**
69
68
  * Peek a token from the tokenizer-stream.
70
69
  * @param token - Token to peek from the tokenizer-stream.
package/package.json CHANGED
@@ -1,94 +1,95 @@
1
- {
2
- "name": "strtok3",
3
- "version": "7.0.0-alpha.9",
4
- "description": "A promise based streaming tokenizer",
5
- "author": {
6
- "name": "Borewit",
7
- "url": "https://github.com/Borewit"
8
- },
9
- "funding": {
10
- "type": "github",
11
- "url": "https://github.com/sponsors/Borewit"
12
- },
13
- "scripts": {
14
- "clean": "del-cli lib/**/*.js lib/**/*.js.map lib/**/*.d.ts test/**/*.js test/**/*.js.map",
15
- "compile-src": "tsc -p lib",
16
- "compile-test": "tsc -p test",
17
- "compile": "npm run compile-src && npm run compile-test",
18
- "build": "npm run clean && npm run compile",
19
- "eslint": "eslint lib test --ext .ts --ignore-pattern *.d.ts",
20
- "lint-md": "remark -u preset-lint-recommended .",
21
- "lint": "npm run lint-md && npm run eslint",
22
- "fix": "eslint lib test --ext .ts --ignore-pattern *.d.ts --fix",
23
- "test": "mocha",
24
- "test-coverage": "c8 npm run test",
25
- "send-coveralls": "c8 report | coveralls",
26
- "send-codacy": "c8 report --reporter=text-lcov | codacy-coverage",
27
- "start": "npm run compile && npm run lint && npm run cover-test"
28
- },
29
- "engines": {
30
- "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/Borewit/strtok3.git"
35
- },
36
- "license": "MIT",
37
- "type": "module",
38
- "exports": {
39
- ".": {
40
- "node": "./lib/index.js",
41
- "default": "./lib/core.js"
42
- },
43
- "./core": "./lib/core.js"
44
- },
45
- "types": "lib/index.d.ts",
46
- "files": [
47
- "lib/**/*.js",
48
- "lib/**/*.d.ts"
49
- ],
50
- "bugs": {
51
- "url": "https://github.com/Borewit/strtok3/issues"
52
- },
53
- "devDependencies": {
54
- "@types/chai": "^4.3.0",
55
- "@types/debug": "^4.1.7",
56
- "@types/mocha": "^9.0.0",
57
- "@types/node": "^16.11.12",
58
- "@typescript-eslint/eslint-plugin": "^2.34.0",
59
- "@typescript-eslint/eslint-plugin-tslint": "^5.6.0",
60
- "@typescript-eslint/parser": "^2.34.0",
61
- "c8": "^7.10.0",
62
- "chai": "^4.3.4",
63
- "coveralls": "^3.1.1",
64
- "del-cli": "^4.0.1",
65
- "eslint": "^6.8.0",
66
- "eslint-plugin-import": "^2.25.3",
67
- "eslint-plugin-prefer-arrow": "^1.2.3",
68
- "mocha": "^9.1.3",
69
- "remark-cli": "^10.0.1",
70
- "remark-preset-lint-recommended": "^6.1.2",
71
- "token-types": "^4.1.1",
72
- "ts-node": "^10.4.0",
73
- "tslint": "^6.1.3",
74
- "typescript": "^4.5.3"
75
- },
76
- "dependencies": {
77
- "@tokenizer/token": "^0.3.0",
78
- "peek-readable": "^5.0.0-alpha.5"
79
- },
80
- "keywords": [
81
- "tokenizer",
82
- "reader",
83
- "token",
84
- "async",
85
- "promise",
86
- "parser",
87
- "decoder",
88
- "binary",
89
- "endian",
90
- "uint",
91
- "stream",
92
- "streaming"
93
- ]
94
- }
1
+ {
2
+ "name": "strtok3",
3
+ "version": "7.1.0",
4
+ "description": "A promise based streaming tokenizer",
5
+ "author": {
6
+ "name": "Borewit",
7
+ "url": "https://github.com/Borewit"
8
+ },
9
+ "funding": {
10
+ "type": "github",
11
+ "url": "https://github.com/sponsors/Borewit"
12
+ },
13
+ "scripts": {
14
+ "clean": "del-cli lib/**/*.js lib/**/*.js.map lib/**/*.d.ts test/**/*.js test/**/*.js.map",
15
+ "compile-src": "tsc -p lib",
16
+ "compile-test": "tsc -p test",
17
+ "compile": "npm run compile-src && npm run compile-test",
18
+ "build": "npm run clean && npm run compile",
19
+ "eslint": "eslint lib test --ext .ts --ignore-pattern *.d.ts",
20
+ "lint-md": "remark -u preset-lint-recommended .",
21
+ "lint": "npm run lint-md && npm run eslint",
22
+ "fix": "eslint lib test --ext .ts --ignore-pattern *.d.ts --fix",
23
+ "test": "mocha",
24
+ "test-coverage": "c8 npm run test",
25
+ "send-codacy": "c8 report --reporter=text-lcov | codacy-coverage",
26
+ "start": "npm run compile && npm run lint && npm run cover-test"
27
+ },
28
+ "engines": {
29
+ "node": ">=14.16"
30
+ },
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/Borewit/strtok3.git"
34
+ },
35
+ "license": "MIT",
36
+ "type": "module",
37
+ "exports": {
38
+ ".": {
39
+ "node": "./lib/index.js",
40
+ "default": "./lib/core.js"
41
+ },
42
+ "./core": "./lib/core.js"
43
+ },
44
+ "types": "lib/index.d.ts",
45
+ "files": [
46
+ "lib/**/*.js",
47
+ "lib/**/*.d.ts"
48
+ ],
49
+ "bugs": {
50
+ "url": "https://github.com/Borewit/strtok3/issues"
51
+ },
52
+ "devDependencies": {
53
+ "@types/chai": "^4.3.16",
54
+ "@types/debug": "^4.1.12",
55
+ "@types/mocha": "^10.0.7",
56
+ "@types/node": "^20.14.9",
57
+ "@typescript-eslint/eslint-plugin": "^7.15.0",
58
+ "@typescript-eslint/parser": "^7.15.0",
59
+ "c8": "^10.1.2",
60
+ "chai": "^5.1.1",
61
+ "del-cli": "^5.1.0",
62
+ "eslint": "^8.57.0",
63
+ "eslint-config-prettier": "^9.0.0",
64
+ "eslint-import-resolver-typescript": "^3.6.1",
65
+ "eslint-plugin-import": "^2.29.0",
66
+ "eslint-plugin-jsdoc": "^46.8.2",
67
+ "eslint-plugin-node": "^11.1.0",
68
+ "eslint-plugin-unicorn": "^54.0.0",
69
+ "mocha": "^10.6.0",
70
+ "remark-cli": "^12.0.1",
71
+ "remark-preset-lint-recommended": "^7.0.0",
72
+ "token-types": "^6.0.0",
73
+ "ts-node": "^10.9.2",
74
+ "typescript": "^5.5.3",
75
+ "uint8array-extras": "^1.3.0"
76
+ },
77
+ "dependencies": {
78
+ "@tokenizer/token": "^0.3.0",
79
+ "peek-readable": "^5.1.1"
80
+ },
81
+ "keywords": [
82
+ "tokenizer",
83
+ "reader",
84
+ "token",
85
+ "async",
86
+ "promise",
87
+ "parser",
88
+ "decoder",
89
+ "binary",
90
+ "endian",
91
+ "uint",
92
+ "stream",
93
+ "streaming"
94
+ ]
95
+ }