strtok3 7.1.0 → 7.1.1

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 CHANGED
@@ -1,4 +1,5 @@
1
- ![Node.js CI](https://github.com/Borewit/strtok3/workflows/Node.js%20CI/badge.svg)
1
+ [![Node.js CI](https://github.com/Borewit/strtok3/actions/workflows/nodejs-ci.yml/badge.svg?branch=master)](https://github.com/Borewit/strtok3/actions/workflows/nodejs-ci.yml?query=branch%3Amaster)
2
+ [![CodeQL](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml)
2
3
  [![NPM version](https://badge.fury.io/js/strtok3.svg)](https://npmjs.org/package/strtok3)
3
4
  [![npm downloads](http://img.shields.io/npm/dm/strtok3.svg)](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
4
5
  [![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)
@@ -32,7 +33,7 @@ npm install strtok3
32
33
 
33
34
  Module: version 7 migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
34
35
  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
+ Requires Node.js ≥ 16 engine.
36
37
 
37
38
  ## API
38
39
 
@@ -1,8 +1,9 @@
1
1
  import { AbstractTokenizer } from './AbstractTokenizer.js';
2
2
  import { IFileInfo, IReadChunkOptions } from './types.js';
3
+ import { FileHandle } from 'node:fs/promises';
3
4
  export declare class FileTokenizer extends AbstractTokenizer {
4
- private fd;
5
- constructor(fd: number, fileInfo: IFileInfo);
5
+ private fileHandle;
6
+ constructor(fileHandle: FileHandle, fileInfo: IFileInfo);
6
7
  /**
7
8
  * Read buffer from file
8
9
  * @param uint8Array - Uint8Array to write result to
@@ -1,10 +1,10 @@
1
1
  import { AbstractTokenizer } from './AbstractTokenizer.js';
2
2
  import { EndOfStreamError } from 'peek-readable';
3
- import * as fs from './FsPromise.js';
3
+ import { open as fsOpen } from 'node:fs/promises';
4
4
  export class FileTokenizer extends AbstractTokenizer {
5
- constructor(fd, fileInfo) {
5
+ constructor(fileHandle, fileInfo) {
6
6
  super(fileInfo);
7
- this.fd = fd;
7
+ this.fileHandle = fileHandle;
8
8
  }
9
9
  /**
10
10
  * Read buffer from file
@@ -15,7 +15,7 @@ export class FileTokenizer extends AbstractTokenizer {
15
15
  async readBuffer(uint8Array, options) {
16
16
  const normOptions = this.normalizeOptions(uint8Array, options);
17
17
  this.position = normOptions.position;
18
- const res = await fs.read(this.fd, uint8Array, normOptions.offset, normOptions.length, normOptions.position);
18
+ const res = await this.fileHandle.read(uint8Array, normOptions.offset, normOptions.length, normOptions.position);
19
19
  this.position += res.bytesRead;
20
20
  if (res.bytesRead < normOptions.length && (!options || !options.mayBeLess)) {
21
21
  throw new EndOfStreamError();
@@ -30,21 +30,18 @@ export class FileTokenizer extends AbstractTokenizer {
30
30
  */
31
31
  async peekBuffer(uint8Array, options) {
32
32
  const normOptions = this.normalizeOptions(uint8Array, options);
33
- const res = await fs.read(this.fd, uint8Array, normOptions.offset, normOptions.length, normOptions.position);
33
+ const res = await this.fileHandle.read(uint8Array, normOptions.offset, normOptions.length, normOptions.position);
34
34
  if ((!normOptions.mayBeLess) && res.bytesRead < normOptions.length) {
35
35
  throw new EndOfStreamError();
36
36
  }
37
37
  return res.bytesRead;
38
38
  }
39
39
  async close() {
40
- return fs.close(this.fd);
40
+ return this.fileHandle.close();
41
41
  }
42
42
  }
43
43
  export async function fromFile(sourceFilePath) {
44
- const stat = await fs.stat(sourceFilePath);
45
- if (!stat.isFile) {
46
- throw new Error(`File not a file: ${sourceFilePath}`);
47
- }
48
- const fd = await fs.open(sourceFilePath, 'r');
49
- return new FileTokenizer(fd, { path: sourceFilePath, size: stat.size });
44
+ const fileHandle = await fsOpen(sourceFilePath, 'r');
45
+ const stat = await fileHandle.stat();
46
+ return new FileTokenizer(fileHandle, { path: sourceFilePath, size: stat.size });
50
47
  }
package/lib/core.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
- import { Readable } from 'node:stream';
3
2
  import { BufferTokenizer } from './BufferTokenizer.js';
4
3
  import { IFileInfo } from './types.js';
5
4
  import type { ReadableStream } from 'node:stream/web';
5
+ import type { Readable } from 'node:stream';
6
6
  export { EndOfStreamError } from 'peek-readable';
7
7
  export { ITokenizer, IFileInfo } from './types.js';
8
8
  export { IToken, IGetToken } from '@tokenizer/token';
package/lib/core.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { ReadStreamTokenizer } from './ReadStreamTokenizer.js';
2
2
  import { BufferTokenizer } from './BufferTokenizer.js';
3
- import { StreamReader, WebStreamReader } from "peek-readable";
3
+ import { StreamReader, WebStreamReader } from 'peek-readable';
4
4
  export { EndOfStreamError } from 'peek-readable';
5
5
  /**
6
6
  * Construct ReadStreamTokenizer from given Stream.
package/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import * as fs from './FsPromise.js';
1
+ import { stat as fsStat } from 'node:fs/promises';
2
2
  import * as core from './core.js';
3
3
  export { fromFile } from './FileTokenizer.js';
4
4
  export { EndOfStreamError, fromBuffer, fromWebStream } from './core.js';
@@ -12,7 +12,7 @@ export { EndOfStreamError, fromBuffer, fromWebStream } from './core.js';
12
12
  export async function fromStream(stream, fileInfo) {
13
13
  fileInfo = fileInfo ? fileInfo : {};
14
14
  if (stream.path) {
15
- const stat = await fs.stat(stream.path);
15
+ const stat = await fsStat(stream.path);
16
16
  fileInfo.path = stream.path;
17
17
  fileInfo.size = stat.size;
18
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strtok3",
3
- "version": "7.1.0",
3
+ "version": "7.1.1",
4
4
  "description": "A promise based streaming tokenizer",
5
5
  "author": {
6
6
  "name": "Borewit",
@@ -16,7 +16,7 @@
16
16
  "compile-test": "tsc -p test",
17
17
  "compile": "npm run compile-src && npm run compile-test",
18
18
  "build": "npm run clean && npm run compile",
19
- "eslint": "eslint lib test --ext .ts --ignore-pattern *.d.ts",
19
+ "eslint": "eslint lib test",
20
20
  "lint-md": "remark -u preset-lint-recommended .",
21
21
  "lint": "npm run lint-md && npm run eslint",
22
22
  "fix": "eslint lib test --ext .ts --ignore-pattern *.d.ts --fix",
@@ -26,7 +26,7 @@
26
26
  "start": "npm run compile && npm run lint && npm run cover-test"
27
27
  },
28
28
  "engines": {
29
- "node": ">=14.16"
29
+ "node": ">=16"
30
30
  },
31
31
  "repository": {
32
32
  "type": "git",
@@ -50,22 +50,26 @@
50
50
  "url": "https://github.com/Borewit/strtok3/issues"
51
51
  },
52
52
  "devDependencies": {
53
+ "@eslint/compat": "^1.1.1",
54
+ "@eslint/eslintrc": "^3.1.0",
55
+ "@eslint/js": "^9.7.0",
53
56
  "@types/chai": "^4.3.16",
54
57
  "@types/debug": "^4.1.12",
55
58
  "@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
+ "@types/node": "^20.14.10",
60
+ "@typescript-eslint/eslint-plugin": "^7.16.1",
61
+ "@typescript-eslint/parser": "^7.16.1",
59
62
  "c8": "^10.1.2",
60
63
  "chai": "^5.1.1",
61
64
  "del-cli": "^5.1.0",
62
- "eslint": "^8.57.0",
63
- "eslint-config-prettier": "^9.0.0",
65
+ "eslint": "^9.7.0",
66
+ "eslint-config-prettier": "^9.1.0",
64
67
  "eslint-import-resolver-typescript": "^3.6.1",
65
- "eslint-plugin-import": "^2.29.0",
66
- "eslint-plugin-jsdoc": "^46.8.2",
68
+ "eslint-plugin-import": "^2.29.1",
69
+ "eslint-plugin-jsdoc": "^48.7.0",
67
70
  "eslint-plugin-node": "^11.1.0",
68
71
  "eslint-plugin-unicorn": "^54.0.0",
72
+ "global": "^4.4.0",
69
73
  "mocha": "^10.6.0",
70
74
  "remark-cli": "^12.0.1",
71
75
  "remark-preset-lint-recommended": "^7.0.0",
@@ -76,7 +80,7 @@
76
80
  },
77
81
  "dependencies": {
78
82
  "@tokenizer/token": "^0.3.0",
79
- "peek-readable": "^5.1.1"
83
+ "peek-readable": "^5.1.3"
80
84
  },
81
85
  "keywords": [
82
86
  "tokenizer",
@@ -91,5 +95,6 @@
91
95
  "uint",
92
96
  "stream",
93
97
  "streaming"
94
- ]
98
+ ],
99
+ "packageManager": "yarn@4.3.1"
95
100
  }
@@ -1,17 +0,0 @@
1
- /**
2
- * Module convert fs functions to promise based functions
3
- */
4
- import fs from 'node:fs';
5
- export interface IReadResult {
6
- bytesRead: number;
7
- buffer: Uint8Array;
8
- }
9
- export declare const pathExists: typeof fs.existsSync;
10
- export declare const createReadStream: typeof fs.createReadStream;
11
- export declare function stat(path: fs.PathLike): Promise<fs.Stats>;
12
- export declare function close(fd: number): Promise<void>;
13
- export declare function open(path: fs.PathLike, mode: fs.Mode): Promise<number>;
14
- export declare function read(fd: number, buffer: Uint8Array, offset: number, length: number, position: number): Promise<IReadResult>;
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 DELETED
@@ -1,69 +0,0 @@
1
- /**
2
- * Module convert fs functions to promise based functions
3
- */
4
- import fs from 'node:fs';
5
- export const pathExists = fs.existsSync;
6
- export const createReadStream = fs.createReadStream;
7
- export async function stat(path) {
8
- return new Promise((resolve, reject) => {
9
- fs.stat(path, (err, stats) => {
10
- if (err)
11
- reject(err);
12
- else
13
- resolve(stats);
14
- });
15
- });
16
- }
17
- export async function close(fd) {
18
- return new Promise((resolve, reject) => {
19
- fs.close(fd, err => {
20
- if (err)
21
- reject(err);
22
- else
23
- resolve();
24
- });
25
- });
26
- }
27
- export async function open(path, mode) {
28
- return new Promise((resolve, reject) => {
29
- fs.open(path, mode, (err, fd) => {
30
- if (err)
31
- reject(err);
32
- else
33
- resolve(fd);
34
- });
35
- });
36
- }
37
- export async function read(fd, buffer, offset, length, position) {
38
- return new Promise((resolve, reject) => {
39
- fs.read(fd, buffer, offset, length, position, (err, bytesRead, _buffer) => {
40
- if (err)
41
- reject(err);
42
- else
43
- resolve({ bytesRead, buffer: _buffer });
44
- });
45
- });
46
- }
47
- export async function writeFile(path, data, options = null) {
48
- return new Promise((resolve, reject) => {
49
- fs.writeFile(path, data, options, err => {
50
- if (err)
51
- reject(err);
52
- else
53
- resolve();
54
- });
55
- });
56
- }
57
- export function writeFileSync(path, data) {
58
- fs.writeFileSync(path, data);
59
- }
60
- export async function readFile(path) {
61
- return new Promise((resolve, reject) => {
62
- fs.readFile(path, (err, buffer) => {
63
- if (err)
64
- reject(err);
65
- else
66
- resolve(buffer);
67
- });
68
- });
69
- }