strtok3 7.0.0-alpha.0 → 7.0.0-alpha.4
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/README.md +4 -5
- package/lib/AbstractTokenizer.d.ts +8 -1
- package/lib/AbstractTokenizer.js +25 -10
- package/lib/BufferTokenizer.d.ts +1 -1
- package/lib/BufferTokenizer.js +5 -5
- package/lib/FileTokenizer.d.ts +3 -4
- package/lib/FileTokenizer.js +11 -31
- package/lib/FsPromise.d.ts +2 -2
- package/lib/FsPromise.js +1 -1
- package/lib/ReadStreamTokenizer.d.ts +5 -5
- package/lib/ReadStreamTokenizer.js +23 -39
- package/lib/core.d.ts +6 -6
- package/lib/core.js +2 -2
- package/lib/index.d.ts +6 -6
- package/lib/index.js +4 -4
- package/package.json +20 -15
package/README.md
CHANGED
|
@@ -48,7 +48,7 @@ All of the strtok3 methods return a [*tokenizer*](#tokenizer), either directly o
|
|
|
48
48
|
|-----------|-----------------------|----------------------------|
|
|
49
49
|
| path | Path to file (string) | Path to file to read from |
|
|
50
50
|
|
|
51
|
-
|
|
51
|
+
> __Note__: that [file-information](#file-information) is automatically added.
|
|
52
52
|
|
|
53
53
|
Returns, via a promise, a [*tokenizer*](#tokenizer) which can be used to parse a file.
|
|
54
54
|
|
|
@@ -131,10 +131,9 @@ If a *position* is provided to a *read* or *peek* method, is should be, at least
|
|
|
131
131
|
|
|
132
132
|
### Tokenizer methods
|
|
133
133
|
|
|
134
|
-
There are
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
* *peek* methods: same as the read, but it will *not* advance the pointer. It allows to read (peek) ahead.
|
|
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.
|
|
138
137
|
|
|
139
138
|
#### Method `tokenizer.readBuffer()`
|
|
140
139
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { ITokenizer, IFileInfo, IReadChunkOptions } from './types';
|
|
2
2
|
import { IGetToken, IToken } from '@tokenizer/token';
|
|
3
|
+
interface INormalizedReadChunkOptions extends IReadChunkOptions {
|
|
4
|
+
offset: number;
|
|
5
|
+
length: number;
|
|
6
|
+
position: number;
|
|
7
|
+
mayBeLess?: boolean;
|
|
8
|
+
}
|
|
3
9
|
/**
|
|
4
10
|
* Core tokenizer
|
|
5
11
|
*/
|
|
@@ -58,5 +64,6 @@ export declare abstract class AbstractTokenizer implements ITokenizer {
|
|
|
58
64
|
*/
|
|
59
65
|
ignore(length: number): Promise<number>;
|
|
60
66
|
close(): Promise<void>;
|
|
61
|
-
protected normalizeOptions(uint8Array: Uint8Array, options?: IReadChunkOptions):
|
|
67
|
+
protected normalizeOptions(uint8Array: Uint8Array, options?: IReadChunkOptions): INormalizedReadChunkOptions;
|
|
62
68
|
}
|
|
69
|
+
export {};
|
package/lib/AbstractTokenizer.js
CHANGED
|
@@ -65,21 +65,36 @@ export class AbstractTokenizer {
|
|
|
65
65
|
* @return resolves the number of bytes ignored, equals length if this available, otherwise the number of bytes available
|
|
66
66
|
*/
|
|
67
67
|
async ignore(length) {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.position += bytesLeft;
|
|
75
|
-
return bytesLeft;
|
|
68
|
+
if (this.fileInfo.size !== undefined) {
|
|
69
|
+
const bytesLeft = this.fileInfo.size - this.position;
|
|
70
|
+
if (length > bytesLeft) {
|
|
71
|
+
this.position += bytesLeft;
|
|
72
|
+
return bytesLeft;
|
|
73
|
+
}
|
|
76
74
|
}
|
|
75
|
+
this.position += length;
|
|
76
|
+
return length;
|
|
77
77
|
}
|
|
78
78
|
async close() {
|
|
79
79
|
// empty
|
|
80
80
|
}
|
|
81
81
|
normalizeOptions(uint8Array, options) {
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
if (options && options.position !== undefined && options.position < this.position) {
|
|
83
|
+
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
|
84
|
+
}
|
|
85
|
+
if (options) {
|
|
86
|
+
return {
|
|
87
|
+
mayBeLess: options.mayBeLess === true,
|
|
88
|
+
offset: options.offset ? options.offset : 0,
|
|
89
|
+
length: options.length ? options.length : (uint8Array.length - (options.offset ? options.offset : 0)),
|
|
90
|
+
position: options.position ? options.position : this.position
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
mayBeLess: false,
|
|
95
|
+
offset: 0,
|
|
96
|
+
length: uint8Array.length,
|
|
97
|
+
position: this.position
|
|
98
|
+
};
|
|
84
99
|
}
|
|
85
100
|
}
|
package/lib/BufferTokenizer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { IFileInfo, IReadChunkOptions } from './types';
|
|
2
|
-
import { AbstractTokenizer } from './AbstractTokenizer';
|
|
2
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
3
3
|
export declare class BufferTokenizer extends AbstractTokenizer {
|
|
4
4
|
private uint8Array;
|
|
5
5
|
/**
|
package/lib/BufferTokenizer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { EndOfStreamError } from 'peek-readable';
|
|
2
|
-
import { AbstractTokenizer } from './AbstractTokenizer';
|
|
2
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
3
3
|
export class BufferTokenizer extends AbstractTokenizer {
|
|
4
4
|
/**
|
|
5
5
|
* Construct BufferTokenizer
|
|
@@ -35,13 +35,13 @@ export class BufferTokenizer extends AbstractTokenizer {
|
|
|
35
35
|
* @returns {Promise<number>}
|
|
36
36
|
*/
|
|
37
37
|
async peekBuffer(uint8Array, options) {
|
|
38
|
-
|
|
39
|
-
const bytes2read = Math.min(this.uint8Array.length -
|
|
40
|
-
if ((!
|
|
38
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
39
|
+
const bytes2read = Math.min(this.uint8Array.length - normOptions.position, normOptions.length);
|
|
40
|
+
if ((!normOptions.mayBeLess) && bytes2read < normOptions.length) {
|
|
41
41
|
throw new EndOfStreamError();
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
|
-
uint8Array.set(this.uint8Array.subarray(
|
|
44
|
+
uint8Array.set(this.uint8Array.subarray(normOptions.position, normOptions.position + bytes2read), normOptions.offset);
|
|
45
45
|
return bytes2read;
|
|
46
46
|
}
|
|
47
47
|
}
|
package/lib/FileTokenizer.d.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
import { AbstractTokenizer } from './AbstractTokenizer';
|
|
1
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
3
2
|
import { IFileInfo, IReadChunkOptions } from './types';
|
|
4
3
|
export declare class FileTokenizer extends AbstractTokenizer {
|
|
5
4
|
private fd;
|
|
6
5
|
constructor(fd: number, fileInfo: IFileInfo);
|
|
7
6
|
/**
|
|
8
7
|
* Read buffer from file
|
|
9
|
-
* @param
|
|
8
|
+
* @param uint8Array - Uint8Array to write result to
|
|
10
9
|
* @param options - Read behaviour options
|
|
11
10
|
* @returns Promise number of bytes read
|
|
12
11
|
*/
|
|
13
|
-
readBuffer(
|
|
12
|
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
|
14
13
|
/**
|
|
15
14
|
* Peek buffer from file
|
|
16
15
|
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
package/lib/FileTokenizer.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AbstractTokenizer } from './AbstractTokenizer';
|
|
1
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
2
2
|
import { EndOfStreamError } from 'peek-readable';
|
|
3
|
-
import * as fs from './FsPromise';
|
|
3
|
+
import * as fs from './FsPromise.js';
|
|
4
4
|
export class FileTokenizer extends AbstractTokenizer {
|
|
5
5
|
constructor(fd, fileInfo) {
|
|
6
6
|
super(fileInfo);
|
|
@@ -8,36 +8,16 @@ export class FileTokenizer extends AbstractTokenizer {
|
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Read buffer from file
|
|
11
|
-
* @param
|
|
11
|
+
* @param uint8Array - Uint8Array to write result to
|
|
12
12
|
* @param options - Read behaviour options
|
|
13
13
|
* @returns Promise number of bytes read
|
|
14
14
|
*/
|
|
15
|
-
async readBuffer(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (options.position) {
|
|
20
|
-
if (options.position < this.position) {
|
|
21
|
-
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
|
22
|
-
}
|
|
23
|
-
this.position = options.position;
|
|
24
|
-
}
|
|
25
|
-
if (Number.isInteger(options.length)) {
|
|
26
|
-
length = options.length;
|
|
27
|
-
}
|
|
28
|
-
else {
|
|
29
|
-
length -= options.offset || 0;
|
|
30
|
-
}
|
|
31
|
-
if (options.offset) {
|
|
32
|
-
offset = options.offset;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (length === 0) {
|
|
36
|
-
return Promise.resolve(0);
|
|
37
|
-
}
|
|
38
|
-
const res = await fs.read(this.fd, buffer, offset, length, this.position);
|
|
15
|
+
async readBuffer(uint8Array, options) {
|
|
16
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
17
|
+
this.position = normOptions.position;
|
|
18
|
+
const res = await fs.read(this.fd, uint8Array, normOptions.offset, normOptions.length, normOptions.position);
|
|
39
19
|
this.position += res.bytesRead;
|
|
40
|
-
if (res.bytesRead < length && (!options || !options.mayBeLess)) {
|
|
20
|
+
if (res.bytesRead < normOptions.length && (!options || !options.mayBeLess)) {
|
|
41
21
|
throw new EndOfStreamError();
|
|
42
22
|
}
|
|
43
23
|
return res.bytesRead;
|
|
@@ -49,9 +29,9 @@ export class FileTokenizer extends AbstractTokenizer {
|
|
|
49
29
|
* @returns Promise number of bytes read
|
|
50
30
|
*/
|
|
51
31
|
async peekBuffer(uint8Array, options) {
|
|
52
|
-
|
|
53
|
-
const res = await fs.read(this.fd, uint8Array,
|
|
54
|
-
if ((!
|
|
32
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
33
|
+
const res = await fs.read(this.fd, uint8Array, normOptions.offset, normOptions.length, normOptions.position);
|
|
34
|
+
if ((!normOptions.mayBeLess) && res.bytesRead < normOptions.length) {
|
|
55
35
|
throw new EndOfStreamError();
|
|
56
36
|
}
|
|
57
37
|
return res.bytesRead;
|
package/lib/FsPromise.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Module convert fs functions to promise based functions
|
|
3
3
|
*/
|
|
4
4
|
/// <reference types="node" />
|
|
5
|
-
import
|
|
5
|
+
import fs from 'node:fs';
|
|
6
6
|
export interface IReadResult {
|
|
7
7
|
bytesRead: number;
|
|
8
8
|
buffer: Uint8Array;
|
|
@@ -11,7 +11,7 @@ export declare const pathExists: typeof fs.existsSync;
|
|
|
11
11
|
export declare const createReadStream: typeof fs.createReadStream;
|
|
12
12
|
export declare function stat(path: fs.PathLike): Promise<fs.Stats>;
|
|
13
13
|
export declare function close(fd: number): Promise<void>;
|
|
14
|
-
export declare function open(path: fs.PathLike, mode
|
|
14
|
+
export declare function open(path: fs.PathLike, mode: fs.Mode): Promise<number>;
|
|
15
15
|
export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): Promise<IReadResult>;
|
|
16
16
|
export declare function writeFile(path: fs.PathLike, data: Buffer | string): Promise<void>;
|
|
17
17
|
export declare function writeFileSync(path: fs.PathLike, data: Buffer | string): void;
|
package/lib/FsPromise.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { AbstractTokenizer } from './AbstractTokenizer';
|
|
3
|
-
import
|
|
2
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
4
|
import { IFileInfo, IReadChunkOptions } from './types';
|
|
5
5
|
export declare class ReadStreamTokenizer extends AbstractTokenizer {
|
|
6
6
|
private streamReader;
|
|
7
|
-
constructor(stream:
|
|
7
|
+
constructor(stream: Readable, fileInfo?: IFileInfo);
|
|
8
8
|
/**
|
|
9
9
|
* Get file information, an HTTP-client may implement this doing a HEAD request
|
|
10
10
|
* @return Promise with file information
|
|
@@ -12,11 +12,11 @@ export declare class ReadStreamTokenizer extends AbstractTokenizer {
|
|
|
12
12
|
getFileInfo(): Promise<IFileInfo>;
|
|
13
13
|
/**
|
|
14
14
|
* Read buffer from tokenizer
|
|
15
|
-
* @param
|
|
15
|
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
16
16
|
* @param options - Read behaviour options
|
|
17
17
|
* @returns Promise with number of bytes read
|
|
18
18
|
*/
|
|
19
|
-
readBuffer(
|
|
19
|
+
readBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
|
|
20
20
|
/**
|
|
21
21
|
* Peek (read ahead) buffer from tokenizer
|
|
22
22
|
* @param uint8Array - Uint8Array (or Buffer) to write data to
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AbstractTokenizer } from './AbstractTokenizer';
|
|
1
|
+
import { AbstractTokenizer } from './AbstractTokenizer.js';
|
|
2
2
|
import { EndOfStreamError, StreamReader } from 'peek-readable';
|
|
3
3
|
const maxBufferSize = 256000;
|
|
4
4
|
export class ReadStreamTokenizer extends AbstractTokenizer {
|
|
@@ -15,42 +15,26 @@ export class ReadStreamTokenizer extends AbstractTokenizer {
|
|
|
15
15
|
}
|
|
16
16
|
/**
|
|
17
17
|
* Read buffer from tokenizer
|
|
18
|
-
* @param
|
|
18
|
+
* @param uint8Array - Target Uint8Array to fill with data read from the tokenizer-stream
|
|
19
19
|
* @param options - Read behaviour options
|
|
20
20
|
* @returns Promise with number of bytes read
|
|
21
21
|
*/
|
|
22
|
-
async readBuffer(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
else {
|
|
32
|
-
length -= options.offset || 0;
|
|
33
|
-
}
|
|
34
|
-
if (options.position) {
|
|
35
|
-
const skipBytes = options.position - this.position;
|
|
36
|
-
if (skipBytes > 0) {
|
|
37
|
-
await this.ignore(skipBytes);
|
|
38
|
-
return this.readBuffer(buffer, options);
|
|
39
|
-
}
|
|
40
|
-
else if (skipBytes < 0) {
|
|
41
|
-
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (options.offset) {
|
|
45
|
-
offset = options.offset;
|
|
46
|
-
}
|
|
22
|
+
async readBuffer(uint8Array, options) {
|
|
23
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
24
|
+
const skipBytes = normOptions.position - this.position;
|
|
25
|
+
if (skipBytes > 0) {
|
|
26
|
+
await this.ignore(skipBytes);
|
|
27
|
+
return this.readBuffer(uint8Array, options);
|
|
28
|
+
}
|
|
29
|
+
else if (skipBytes < 0) {
|
|
30
|
+
throw new Error('`options.position` must be equal or greater than `tokenizer.position`');
|
|
47
31
|
}
|
|
48
|
-
if (length === 0) {
|
|
32
|
+
if (normOptions.length === 0) {
|
|
49
33
|
return 0;
|
|
50
34
|
}
|
|
51
|
-
const bytesRead = await this.streamReader.read(
|
|
35
|
+
const bytesRead = await this.streamReader.read(uint8Array, normOptions.offset, normOptions.length);
|
|
52
36
|
this.position += bytesRead;
|
|
53
|
-
if ((!options || !options.mayBeLess) && bytesRead < length) {
|
|
37
|
+
if ((!options || !options.mayBeLess) && bytesRead < normOptions.length) {
|
|
54
38
|
throw new EndOfStreamError();
|
|
55
39
|
}
|
|
56
40
|
return bytesRead;
|
|
@@ -62,23 +46,23 @@ export class ReadStreamTokenizer extends AbstractTokenizer {
|
|
|
62
46
|
* @returns Promise with number of bytes peeked
|
|
63
47
|
*/
|
|
64
48
|
async peekBuffer(uint8Array, options) {
|
|
65
|
-
|
|
49
|
+
const normOptions = this.normalizeOptions(uint8Array, options);
|
|
66
50
|
let bytesRead = 0;
|
|
67
|
-
if (
|
|
68
|
-
const skipBytes =
|
|
51
|
+
if (normOptions.position) {
|
|
52
|
+
const skipBytes = normOptions.position - this.position;
|
|
69
53
|
if (skipBytes > 0) {
|
|
70
|
-
const skipBuffer = new Uint8Array(
|
|
71
|
-
bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess:
|
|
72
|
-
uint8Array.set(skipBuffer.subarray(skipBytes),
|
|
54
|
+
const skipBuffer = new Uint8Array(normOptions.length + skipBytes);
|
|
55
|
+
bytesRead = await this.peekBuffer(skipBuffer, { mayBeLess: normOptions.mayBeLess });
|
|
56
|
+
uint8Array.set(skipBuffer.subarray(skipBytes), normOptions.offset);
|
|
73
57
|
return bytesRead - skipBytes;
|
|
74
58
|
}
|
|
75
59
|
else if (skipBytes < 0) {
|
|
76
60
|
throw new Error('Cannot peek from a negative offset in a stream');
|
|
77
61
|
}
|
|
78
62
|
}
|
|
79
|
-
if (
|
|
63
|
+
if (normOptions.length > 0) {
|
|
80
64
|
try {
|
|
81
|
-
bytesRead = await this.streamReader.peek(uint8Array,
|
|
65
|
+
bytesRead = await this.streamReader.peek(uint8Array, normOptions.offset, normOptions.length);
|
|
82
66
|
}
|
|
83
67
|
catch (err) {
|
|
84
68
|
if (options && options.mayBeLess && err instanceof EndOfStreamError) {
|
|
@@ -86,7 +70,7 @@ export class ReadStreamTokenizer extends AbstractTokenizer {
|
|
|
86
70
|
}
|
|
87
71
|
throw err;
|
|
88
72
|
}
|
|
89
|
-
if ((!
|
|
73
|
+
if ((!normOptions.mayBeLess) && bytesRead < normOptions.length) {
|
|
90
74
|
throw new EndOfStreamError();
|
|
91
75
|
}
|
|
92
76
|
}
|
package/lib/core.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ReadStreamTokenizer } from './ReadStreamTokenizer';
|
|
3
|
-
import
|
|
4
|
-
import { BufferTokenizer } from './BufferTokenizer';
|
|
5
|
-
import { IFileInfo } from './types';
|
|
2
|
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { BufferTokenizer } from './BufferTokenizer.js';
|
|
5
|
+
import { IFileInfo } from './types.js';
|
|
6
6
|
export { EndOfStreamError } from 'peek-readable';
|
|
7
|
-
export { ITokenizer, IFileInfo } from './types';
|
|
7
|
+
export { ITokenizer, IFileInfo } from './types.js';
|
|
8
8
|
export { IToken, IGetToken } from '@tokenizer/token';
|
|
9
9
|
/**
|
|
10
10
|
* Construct ReadStreamTokenizer from given Stream.
|
|
@@ -13,7 +13,7 @@ export { IToken, IGetToken } from '@tokenizer/token';
|
|
|
13
13
|
* @param fileInfo - Pass the file information, like size and MIME-type of the correspnding stream.
|
|
14
14
|
* @returns ReadStreamTokenizer
|
|
15
15
|
*/
|
|
16
|
-
export declare function fromStream(stream:
|
|
16
|
+
export declare function fromStream(stream: Readable, fileInfo?: IFileInfo): ReadStreamTokenizer;
|
|
17
17
|
/**
|
|
18
18
|
* Construct ReadStreamTokenizer from given Buffer.
|
|
19
19
|
* @param uint8Array - Uint8Array to tokenize
|
package/lib/core.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReadStreamTokenizer } from './ReadStreamTokenizer';
|
|
2
|
-
import { BufferTokenizer } from './BufferTokenizer';
|
|
1
|
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
2
|
+
import { BufferTokenizer } from './BufferTokenizer.js';
|
|
3
3
|
export { EndOfStreamError } from 'peek-readable';
|
|
4
4
|
/**
|
|
5
5
|
* Construct ReadStreamTokenizer from given Stream.
|
package/lib/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import
|
|
3
|
-
import { ReadStreamTokenizer } from './ReadStreamTokenizer';
|
|
4
|
-
import * as core from './core';
|
|
5
|
-
export { fromFile } from './FileTokenizer';
|
|
6
|
-
export { ITokenizer, EndOfStreamError, fromBuffer, IFileInfo } from './core';
|
|
2
|
+
import { Readable } from 'node:stream';
|
|
3
|
+
import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
|
|
4
|
+
import * as core from './core.js';
|
|
5
|
+
export { fromFile } from './FileTokenizer.js';
|
|
6
|
+
export { ITokenizer, EndOfStreamError, fromBuffer, IFileInfo } from './core.js';
|
|
7
7
|
export { IToken, IGetToken } from '@tokenizer/token';
|
|
8
8
|
/**
|
|
9
9
|
* Construct ReadStreamTokenizer from given Stream.
|
|
@@ -12,4 +12,4 @@ export { IToken, IGetToken } from '@tokenizer/token';
|
|
|
12
12
|
* @param fileInfo - Pass additional file information to the tokenizer
|
|
13
13
|
* @returns Tokenizer
|
|
14
14
|
*/
|
|
15
|
-
export declare function fromStream(stream:
|
|
15
|
+
export declare function fromStream(stream: Readable, fileInfo?: core.IFileInfo): Promise<ReadStreamTokenizer>;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import * as fs from './FsPromise';
|
|
2
|
-
import * as core from './core';
|
|
3
|
-
export { fromFile } from './FileTokenizer';
|
|
4
|
-
export { EndOfStreamError, fromBuffer } from './core';
|
|
1
|
+
import * as fs from './FsPromise.js';
|
|
2
|
+
import * as core from './core.js';
|
|
3
|
+
export { fromFile } from './FileTokenizer.js';
|
|
4
|
+
export { EndOfStreamError, fromBuffer } 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "strtok3",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.4",
|
|
4
4
|
"description": "A promise based streaming tokenizer",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Borewit",
|
|
@@ -19,14 +19,15 @@
|
|
|
19
19
|
"eslint": "eslint lib test --ext .ts --ignore-pattern *.d.ts",
|
|
20
20
|
"lint-md": "remark -u preset-lint-recommended .",
|
|
21
21
|
"lint": "npm run lint-md && npm run eslint",
|
|
22
|
-
"
|
|
23
|
-
"test
|
|
24
|
-
"
|
|
25
|
-
"send-
|
|
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 --reporter=text-lcov | coveralls",
|
|
26
|
+
"send-codacy": "c8 report --reporter=text-lcov | codacy-coverage",
|
|
26
27
|
"start": "npm run compile && npm run lint && npm run cover-test"
|
|
27
28
|
},
|
|
28
29
|
"engines": {
|
|
29
|
-
"node": "
|
|
30
|
+
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
|
|
30
31
|
},
|
|
31
32
|
"repository": {
|
|
32
33
|
"type": "git",
|
|
@@ -34,8 +35,12 @@
|
|
|
34
35
|
},
|
|
35
36
|
"license": "MIT",
|
|
36
37
|
"main": "lib/index.js",
|
|
38
|
+
"type": "module",
|
|
37
39
|
"exports": {
|
|
38
|
-
".":
|
|
40
|
+
".": {
|
|
41
|
+
"node": "./lib/index.js",
|
|
42
|
+
"default": "./lib/core.js"
|
|
43
|
+
},
|
|
39
44
|
"./core": "./lib/core.js"
|
|
40
45
|
},
|
|
41
46
|
"types": "lib/index.d.ts",
|
|
@@ -49,30 +54,30 @@
|
|
|
49
54
|
"devDependencies": {
|
|
50
55
|
"@tokenizer/token": "^0.3.0",
|
|
51
56
|
"@types/chai": "^4.2.21",
|
|
52
|
-
"@types/debug": "^4.1.
|
|
53
|
-
"@types/mocha": "^
|
|
54
|
-
"@types/node": "^16.
|
|
57
|
+
"@types/debug": "^4.1.7",
|
|
58
|
+
"@types/mocha": "^9.0.0",
|
|
59
|
+
"@types/node": "^16.4.7",
|
|
55
60
|
"@typescript-eslint/eslint-plugin": "^2.34.0",
|
|
56
|
-
"@typescript-eslint/eslint-plugin-tslint": "^4.28.
|
|
61
|
+
"@typescript-eslint/eslint-plugin-tslint": "^4.28.5",
|
|
57
62
|
"@typescript-eslint/parser": "^2.34.0",
|
|
63
|
+
"c8": "^7.8.0",
|
|
58
64
|
"chai": "^4.3.4",
|
|
59
65
|
"coveralls": "^3.1.1",
|
|
60
66
|
"del-cli": "^4.0.1",
|
|
61
67
|
"eslint": "^6.8.0",
|
|
62
68
|
"eslint-plugin-import": "^2.23.4",
|
|
63
69
|
"eslint-plugin-prefer-arrow": "^1.2.3",
|
|
64
|
-
"mocha": "^9.0.
|
|
65
|
-
"nyc": "^15.1.0",
|
|
70
|
+
"mocha": "^9.0.3",
|
|
66
71
|
"remark-cli": "^9.0.0",
|
|
67
72
|
"remark-preset-lint-recommended": "^5.0.0",
|
|
68
|
-
"source-map-support": "^0.5.16",
|
|
69
73
|
"token-types": "^4.1.0",
|
|
70
74
|
"ts-node": "^10.1.0",
|
|
71
75
|
"tslint": "^6.1.3",
|
|
72
76
|
"typescript": "^4.3.5"
|
|
73
77
|
},
|
|
74
78
|
"dependencies": {
|
|
75
|
-
"
|
|
79
|
+
"@tokenizer/token": "^0.3.0",
|
|
80
|
+
"peek-readable": "^5.0.0-alpha.4"
|
|
76
81
|
},
|
|
77
82
|
"keywords": [
|
|
78
83
|
"tokenizer",
|