strtok3 7.0.0-alpha.2 → 7.0.0-alpha.6

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/lib/core.js CHANGED
@@ -1,23 +1,23 @@
1
- import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
- import { BufferTokenizer } from './BufferTokenizer.js';
3
- export { EndOfStreamError } from 'peek-readable';
4
- /**
5
- * Construct ReadStreamTokenizer from given Stream.
6
- * Will set fileSize, if provided given Stream has set the .path property/
7
- * @param stream - Read from Node.js Stream.Readable
8
- * @param fileInfo - Pass the file information, like size and MIME-type of the correspnding stream.
9
- * @returns ReadStreamTokenizer
10
- */
11
- export function fromStream(stream, fileInfo) {
12
- fileInfo = fileInfo ? fileInfo : {};
13
- return new ReadStreamTokenizer(stream, fileInfo);
14
- }
15
- /**
16
- * Construct ReadStreamTokenizer from given Buffer.
17
- * @param uint8Array - Uint8Array to tokenize
18
- * @param fileInfo - Pass additional file information to the tokenizer
19
- * @returns BufferTokenizer
20
- */
21
- export function fromBuffer(uint8Array, fileInfo) {
22
- return new BufferTokenizer(uint8Array, fileInfo);
23
- }
1
+ import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
+ import { BufferTokenizer } from './BufferTokenizer.js';
3
+ export { EndOfStreamError } from 'peek-readable';
4
+ /**
5
+ * Construct ReadStreamTokenizer from given Stream.
6
+ * Will set fileSize, if provided given Stream has set the .path property/
7
+ * @param stream - Read from Node.js Stream.Readable
8
+ * @param fileInfo - Pass the file information, like size and MIME-type of the corresponding stream.
9
+ * @returns ReadStreamTokenizer
10
+ */
11
+ export function fromStream(stream, fileInfo) {
12
+ fileInfo = fileInfo ? fileInfo : {};
13
+ return new ReadStreamTokenizer(stream, fileInfo);
14
+ }
15
+ /**
16
+ * Construct ReadStreamTokenizer from given Buffer.
17
+ * @param uint8Array - Uint8Array to tokenize
18
+ * @param fileInfo - Pass additional file information to the tokenizer
19
+ * @returns BufferTokenizer
20
+ */
21
+ export function fromBuffer(uint8Array, fileInfo) {
22
+ return new BufferTokenizer(uint8Array, fileInfo);
23
+ }
package/lib/index.d.ts CHANGED
@@ -1,15 +1,15 @@
1
- /// <reference types="node" />
2
- import * as Stream from '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
- export { IToken, IGetToken } from '@tokenizer/token';
8
- /**
9
- * Construct ReadStreamTokenizer from given Stream.
10
- * Will set fileSize, if provided given Stream has set the .path property.
11
- * @param stream - Node.js Stream.Readable
12
- * @param fileInfo - Pass additional file information to the tokenizer
13
- * @returns Tokenizer
14
- */
15
- export declare function fromStream(stream: Stream.Readable, fileInfo?: core.IFileInfo): Promise<ReadStreamTokenizer>;
1
+ /// <reference types="node" />
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
+ export { IToken, IGetToken } from '@tokenizer/token';
8
+ /**
9
+ * Construct ReadStreamTokenizer from given Stream.
10
+ * Will set fileSize, if provided given Stream has set the .path property.
11
+ * @param stream - Node.js Stream.Readable
12
+ * @param fileInfo - Pass additional file information to the tokenizer
13
+ * @returns Tokenizer
14
+ */
15
+ export declare function fromStream(stream: Readable, fileInfo?: core.IFileInfo): Promise<ReadStreamTokenizer>;
package/lib/index.js CHANGED
@@ -1,20 +1,20 @@
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
- /**
6
- * Construct ReadStreamTokenizer from given Stream.
7
- * Will set fileSize, if provided given Stream has set the .path property.
8
- * @param stream - Node.js Stream.Readable
9
- * @param fileInfo - Pass additional file information to the tokenizer
10
- * @returns Tokenizer
11
- */
12
- export async function fromStream(stream, fileInfo) {
13
- fileInfo = fileInfo ? fileInfo : {};
14
- if (stream.path) {
15
- const stat = await fs.stat(stream.path);
16
- fileInfo.path = stream.path;
17
- fileInfo.size = stat.size;
18
- }
19
- return core.fromStream(stream, fileInfo);
20
- }
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
+ /**
6
+ * Construct ReadStreamTokenizer from given Stream.
7
+ * Will set fileSize, if provided given Stream has set the .path property.
8
+ * @param stream - Node.js Stream.Readable
9
+ * @param fileInfo - Pass additional file information to the tokenizer
10
+ * @returns Tokenizer
11
+ */
12
+ export async function fromStream(stream, fileInfo) {
13
+ fileInfo = fileInfo ? fileInfo : {};
14
+ if (stream.path) {
15
+ const stat = await fs.stat(stream.path);
16
+ fileInfo.path = stream.path;
17
+ fileInfo.size = stat.size;
18
+ }
19
+ return core.fromStream(stream, fileInfo);
20
+ }
package/lib/types.d.ts CHANGED
@@ -1,103 +1,103 @@
1
- /// <reference types="node" />
2
- import { IGetToken } from '@tokenizer/token';
3
- export interface IFileInfo {
4
- /**
5
- * File size in bytes
6
- */
7
- size?: number;
8
- /**
9
- * MIME-type of file
10
- */
11
- mimeType?: string;
12
- /**
13
- * File path
14
- */
15
- path?: string;
16
- /**
17
- * File URL
18
- */
19
- url?: string;
20
- }
21
- export interface IReadChunkOptions {
22
- /**
23
- * The offset in the buffer to start writing at; default is 0
24
- */
25
- offset?: number;
26
- /**
27
- * Number of bytes to read.
28
- */
29
- length?: number;
30
- /**
31
- * Position where to begin reading from the file.
32
- * Default it is `tokenizer.position`.
33
- * Position may not be less then `tokenizer.position`.
34
- */
35
- position?: number;
36
- /**
37
- * If set, will not throw an EOF error if not all of the requested data could be read
38
- */
39
- mayBeLess?: boolean;
40
- }
41
- /**
42
- * The tokenizer allows us to read or peek from the tokenizer-stream.
43
- * The tokenizer-stream is an abstraction of a stream, file or Buffer.
44
- */
45
- export interface ITokenizer {
46
- /**
47
- * Provide access to information of the underlying information stream or file.
48
- */
49
- fileInfo: IFileInfo;
50
- /**
51
- * Offset in bytes (= number of bytes read) since beginning of file or stream
52
- */
53
- position: number;
54
- /**
55
- * Peek (read ahead) buffer from tokenizer
56
- * @param buffer - Target buffer to fill with data peek from the tokenizer-stream
57
- * @param options - Read behaviour options
58
- * @returns Promise with number of bytes read
59
- */
60
- peekBuffer(buffer: Buffer, options?: IReadChunkOptions): Promise<number>;
61
- /**
62
- * Peek (read ahead) buffer from tokenizer
63
- * @param buffer - Target buffer to fill with data peeked from the tokenizer-stream
64
- * @param options - Additional read options
65
- * @returns Promise with number of bytes read
66
- */
67
- readBuffer(buffer: Buffer, options?: IReadChunkOptions): Promise<number>;
68
- /**
69
- * Peek a token from the tokenizer-stream.
70
- * @param token - Token to peek from the tokenizer-stream.
71
- * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
72
- * @param maybeless - If set, will not throw an EOF error if the less then the requested length could be read.
73
- */
74
- peekToken<T>(token: IGetToken<T>, position?: number | null, maybeless?: boolean): Promise<T>;
75
- /**
76
- * Read a token from the tokenizer-stream.
77
- * @param token - Token to peek from the tokenizer-stream.
78
- * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
79
- */
80
- readToken<T>(token: IGetToken<T>, position?: number): Promise<T>;
81
- /**
82
- * Peek a numeric token from the stream
83
- * @param token - Numeric token
84
- * @returns Promise with number
85
- */
86
- peekNumber(token: IGetToken<number>): Promise<number>;
87
- /**
88
- * Read a numeric token from the stream
89
- * @param token - Numeric token
90
- * @returns Promise with number
91
- */
92
- readNumber(token: IGetToken<number>): Promise<number>;
93
- /**
94
- * Ignore given number of bytes
95
- * @param length - Number of bytes ignored
96
- */
97
- ignore(length: number): Promise<number>;
98
- /**
99
- * Clean up resources.
100
- * It does not close the stream for StreamReader, but is does close the file-descriptor.
101
- */
102
- close(): Promise<void>;
103
- }
1
+ /// <reference types="node" />
2
+ import { IGetToken } from '@tokenizer/token';
3
+ export interface IFileInfo {
4
+ /**
5
+ * File size in bytes
6
+ */
7
+ size?: number;
8
+ /**
9
+ * MIME-type of file
10
+ */
11
+ mimeType?: string;
12
+ /**
13
+ * File path
14
+ */
15
+ path?: string;
16
+ /**
17
+ * File URL
18
+ */
19
+ url?: string;
20
+ }
21
+ export interface IReadChunkOptions {
22
+ /**
23
+ * The offset in the buffer to start writing at; default is 0
24
+ */
25
+ offset?: number;
26
+ /**
27
+ * Number of bytes to read.
28
+ */
29
+ length?: number;
30
+ /**
31
+ * Position where to begin reading from the file.
32
+ * Default it is `tokenizer.position`.
33
+ * Position may not be less then `tokenizer.position`.
34
+ */
35
+ position?: number;
36
+ /**
37
+ * If set, will not throw an EOF error if not all of the requested data could be read
38
+ */
39
+ mayBeLess?: boolean;
40
+ }
41
+ /**
42
+ * The tokenizer allows us to read or peek from the tokenizer-stream.
43
+ * The tokenizer-stream is an abstraction of a stream, file or Buffer.
44
+ */
45
+ export interface ITokenizer {
46
+ /**
47
+ * Provide access to information of the underlying information stream or file.
48
+ */
49
+ fileInfo: IFileInfo;
50
+ /**
51
+ * Offset in bytes (= number of bytes read) since beginning of file or stream
52
+ */
53
+ position: number;
54
+ /**
55
+ * Peek (read ahead) buffer from tokenizer
56
+ * @param buffer - Target buffer to fill with data peek from the tokenizer-stream
57
+ * @param options - Read behaviour options
58
+ * @returns Promise with number of bytes read
59
+ */
60
+ peekBuffer(buffer: Buffer, options?: IReadChunkOptions): Promise<number>;
61
+ /**
62
+ * Peek (read ahead) buffer from tokenizer
63
+ * @param buffer - Target buffer to fill with data peeked from the tokenizer-stream
64
+ * @param options - Additional read options
65
+ * @returns Promise with number of bytes read
66
+ */
67
+ readBuffer(buffer: Buffer, options?: IReadChunkOptions): Promise<number>;
68
+ /**
69
+ * Peek a token from the tokenizer-stream.
70
+ * @param token - Token to peek from the tokenizer-stream.
71
+ * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
72
+ * @param maybeless - If set, will not throw an EOF error if the less then the requested length could be read.
73
+ */
74
+ peekToken<T>(token: IGetToken<T>, position?: number | null, maybeless?: boolean): Promise<T>;
75
+ /**
76
+ * Read a token from the tokenizer-stream.
77
+ * @param token - Token to peek from the tokenizer-stream.
78
+ * @param position - Offset where to begin reading within the file. If position is null, data will be read from the current file position.
79
+ */
80
+ readToken<T>(token: IGetToken<T>, position?: number): Promise<T>;
81
+ /**
82
+ * Peek a numeric token from the stream
83
+ * @param token - Numeric token
84
+ * @returns Promise with number
85
+ */
86
+ peekNumber(token: IGetToken<number>): Promise<number>;
87
+ /**
88
+ * Read a numeric token from the stream
89
+ * @param token - Numeric token
90
+ * @returns Promise with number
91
+ */
92
+ readNumber(token: IGetToken<number>): Promise<number>;
93
+ /**
94
+ * Ignore given number of bytes
95
+ * @param length - Number of bytes ignored
96
+ */
97
+ ignore(length: number): Promise<number>;
98
+ /**
99
+ * Clean up resources.
100
+ * It does not close the stream for StreamReader, but is does close the file-descriptor.
101
+ */
102
+ close(): Promise<void>;
103
+ }
package/lib/types.js CHANGED
@@ -1 +1 @@
1
- export {};
1
+ export {};
package/package.json CHANGED
@@ -1,105 +1,108 @@
1
- {
2
- "name": "strtok3",
3
- "version": "7.0.0-alpha.2",
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
- "fix": "eslint lib test --ext .ts --ignore-pattern *.d.ts --fix",
21
- "lint-md": "remark -u preset-lint-recommended .",
22
- "lint": "npm run lint-md && npm run eslint",
23
- "test": "mocha",
24
- "test-coverage": "nyc npm run test",
25
- "send-coveralls": "nyc report --reporter=text-lcov | coveralls",
26
- "send-codacy": "nyc 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"
31
- },
32
- "repository": {
33
- "type": "git",
34
- "url": "https://github.com/Borewit/strtok3.git"
35
- },
36
- "license": "MIT",
37
- "main": "lib/index.js",
38
- "type": "module",
39
- "exports": {
40
- ".": "./lib/index.js",
41
- "./core": "./lib/core.js"
42
- },
43
- "types": "lib/index.d.ts",
44
- "files": [
45
- "lib/**/*.js",
46
- "lib/**/*.d.ts"
47
- ],
48
- "bugs": {
49
- "url": "https://github.com/Borewit/strtok3/issues"
50
- },
51
- "devDependencies": {
52
- "@tokenizer/token": "^0.3.0",
53
- "@types/chai": "^4.2.21",
54
- "@types/debug": "^4.1.6",
55
- "@types/mocha": "^8.2.3",
56
- "@types/node": "^16.3.3",
57
- "@typescript-eslint/eslint-plugin": "^2.34.0",
58
- "@typescript-eslint/eslint-plugin-tslint": "^4.28.3",
59
- "@typescript-eslint/parser": "^2.34.0",
60
- "chai": "^4.3.4",
61
- "coveralls": "^3.1.1",
62
- "del-cli": "^4.0.1",
63
- "eslint": "^6.8.0",
64
- "eslint-plugin-import": "^2.23.4",
65
- "eslint-plugin-prefer-arrow": "^1.2.3",
66
- "mocha": "^9.0.3",
67
- "nyc": "^15.1.0",
68
- "remark-cli": "^9.0.0",
69
- "remark-preset-lint-recommended": "^5.0.0",
70
- "token-types": "^4.1.0",
71
- "ts-node": "^10.1.0",
72
- "tslint": "^6.1.3",
73
- "typescript": "^4.3.5"
74
- },
75
- "dependencies": {
76
- "peek-readable": "^5.0.0-alpha.2"
77
- },
78
- "keywords": [
79
- "tokenizer",
80
- "reader",
81
- "token",
82
- "async",
83
- "promise",
84
- "parser",
85
- "decoder",
86
- "binary",
87
- "endian",
88
- "uint",
89
- "stream",
90
- "streaming"
91
- ],
92
- "nyc": {
93
- "check-coverage": false,
94
- "extension": [
95
- ".ts"
96
- ],
97
- "sourceMap": true,
98
- "instrument": true,
99
- "reporter": [
100
- "lcov",
101
- "text"
102
- ],
103
- "report-dir": "coverage"
104
- }
105
- }
1
+ {
2
+ "name": "strtok3",
3
+ "version": "7.0.0-alpha.6",
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 --reporter=text-lcov | 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
+ "main": "lib/index.js",
38
+ "type": "module",
39
+ "exports": {
40
+ ".": {
41
+ "node": "./lib/index.js",
42
+ "default": "./lib/core.js"
43
+ },
44
+ "./core": "./lib/core.js"
45
+ },
46
+ "types": "lib/index.d.ts",
47
+ "files": [
48
+ "lib/**/*.js",
49
+ "lib/**/*.d.ts"
50
+ ],
51
+ "bugs": {
52
+ "url": "https://github.com/Borewit/strtok3/issues"
53
+ },
54
+ "devDependencies": {
55
+ "@types/chai": "^4.3.0",
56
+ "@types/debug": "^4.1.7",
57
+ "@types/mocha": "^9.0.0",
58
+ "@types/node": "^16.11.12",
59
+ "@typescript-eslint/eslint-plugin": "^2.34.0",
60
+ "@typescript-eslint/eslint-plugin-tslint": "^5.6.0",
61
+ "@typescript-eslint/parser": "^2.34.0",
62
+ "c8": "^7.10.0",
63
+ "chai": "^4.3.4",
64
+ "coveralls": "^3.1.1",
65
+ "del-cli": "^4.0.1",
66
+ "eslint": "^6.8.0",
67
+ "eslint-plugin-import": "^2.25.3",
68
+ "eslint-plugin-prefer-arrow": "^1.2.3",
69
+ "mocha": "^9.1.3",
70
+ "remark-cli": "^10.0.1",
71
+ "remark-preset-lint-recommended": "^6.1.2",
72
+ "token-types": "^4.1.1",
73
+ "ts-node": "^10.4.0",
74
+ "tslint": "^6.1.3",
75
+ "typescript": "^4.5.3"
76
+ },
77
+ "dependencies": {
78
+ "@tokenizer/token": "^0.3.0",
79
+ "peek-readable": "^5.0.0-alpha.4"
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
+ "nyc": {
96
+ "check-coverage": false,
97
+ "extension": [
98
+ ".ts"
99
+ ],
100
+ "sourceMap": true,
101
+ "instrument": true,
102
+ "reporter": [
103
+ "lcov",
104
+ "text"
105
+ ],
106
+ "report-dir": "coverage"
107
+ }
108
+ }