split-frames 2.5.1 → 2.7.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,4 +1,4 @@
1
- Copyright (c) 2024, Sébastien Vidal
1
+ Copyright (c) 2026, Sébastien Vidal
2
2
 
3
3
  Permission to use, copy, modify, and/or distribute this software for any
4
4
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -1,13 +1,18 @@
1
1
  # split-frames
2
2
  Split Buffer frames from streams
3
3
 
4
- [![Build Status](https://api.travis-ci.org/Psychopoulet/split-frames.svg?branch=master)](https://travis-ci.org/Psychopoulet/split-frames)
5
- [![Coverage Status](https://coveralls.io/repos/github/Psychopoulet/split-frames/badge.svg?branch=master)](https://coveralls.io/github/Psychopoulet/split-frames)
6
- [![Dependency Status](https://david-dm.org/Psychopoulet/split-frames/status.svg)](https://david-dm.org/Psychopoulet/split-frames)
7
- [![Dev dependency Status](https://david-dm.org/Psychopoulet/split-frames/dev-status.svg)](https://david-dm.org/Psychopoulet/split-frames?type=dev)
4
+ [![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_split-frames&metric=ncloc)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
8
5
  [![Issues](https://img.shields.io/github/issues/Psychopoulet/split-frames.svg)](https://github.com/Psychopoulet/split-frames/issues)
9
6
  [![Pull requests](https://img.shields.io/github/issues-pr/Psychopoulet/split-frames.svg)](https://github.com/Psychopoulet/split-frames/pulls)
10
7
 
8
+ [![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_split-frames&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
9
+ [![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_split-frames&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
10
+ [![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_split-frames&metric=sqale_rating)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
11
+ [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_split-frames&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
12
+ [![Bugs](https://sonarcloud.io/api/project_badges/measure?project=Psychopoulet_split-frames&metric=bugs)](https://sonarcloud.io/summary/new_code?id=Psychopoulet_split-frames)
13
+
14
+ [![Known Vulnerabilities](https://snyk.io/test/github/Psychopoulet/split-frames/badge.svg)](https://snyk.io/test/github/Psychopoulet/split-frames)
15
+
11
16
  ## Installation
12
17
 
13
18
  ```bash
@@ -33,7 +33,7 @@ export default class SplitFrames extends Transform {
33
33
  protected _controlBits: iConf["controlBits"];
34
34
  protected _digester: (enc?: BufferEncoding) => void;
35
35
  constructor(options?: iOptions);
36
- _transform(chunk: Buffer, enc: BufferEncoding, cb: (err?: Error | null, data?: any) => void): void;
36
+ _transform(chunk: Buffer, enc: BufferEncoding, cb: (err?: Error | null, data?: unknown) => void): void;
37
37
  protected _chooseDigester(): (enc?: BufferEncoding) => void;
38
38
  protected _digest(enc?: BufferEncoding): void;
39
39
  private _digestNoStartNoEnd;
@@ -1,15 +1,34 @@
1
1
  "use strict";
2
- // deps
2
+ /*
3
+ eslint-disable no-unmodified-loop-condition
4
+ */
5
+ // => no-unmodified-loop-condition is disabled to allow data generation in a loop (_digestStartAndEnd)
3
6
  var __importDefault = (this && this.__importDefault) || function (mod) {
4
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
8
  };
6
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
+ // deps
7
11
  // natives
8
12
  const node_stream_1 = require("node:stream");
9
13
  // locals
10
14
  const initData_1 = __importDefault(require("./checkers/initData"));
11
15
  // module
12
16
  class SplitFrames extends node_stream_1.Transform {
17
+ // attributes
18
+ // protected
19
+ _frame;
20
+ _digesting;
21
+ _timeoutDigest;
22
+ // from params
23
+ _startWith;
24
+ _startTimeout;
25
+ _endWith;
26
+ _escapeWith;
27
+ _escaped;
28
+ _specifics;
29
+ _controlBits;
30
+ // dynamic digester
31
+ _digester;
13
32
  // constructor
14
33
  constructor(options) {
15
34
  super();
@@ -41,20 +60,16 @@ class SplitFrames extends node_stream_1.Transform {
41
60
  }
42
61
  // protected
43
62
  _chooseDigester() {
44
- let digester = undefined;
45
63
  if (undefined === this._startWith && undefined === this._endWith) {
46
- digester = this._digestNoStartNoEnd;
64
+ return this._digestNoStartNoEnd.bind(this);
47
65
  }
48
66
  else if (undefined !== this._startWith && undefined === this._endWith) {
49
- digester = this._digestStartOnly;
67
+ return this._digestStartOnly.bind(this);
50
68
  }
51
69
  else if (undefined === this._startWith && undefined !== this._endWith) {
52
- digester = this._digestEndOnly;
53
- }
54
- else {
55
- digester = this._digestStartAndEnd;
70
+ return this._digestEndOnly.bind(this);
56
71
  }
57
- return digester;
72
+ return this._digestStartAndEnd.bind(this);
58
73
  }
59
74
  _digest(enc) {
60
75
  if (!this._frame.length) {
@@ -166,7 +181,8 @@ class SplitFrames extends node_stream_1.Transform {
166
181
  this._frame = Buffer.from(this._frame.slice(size, this._frame.length));
167
182
  }
168
183
  });
169
- if (found) {
184
+ // disabled due to malfunction
185
+ if (found) { // eslint-disable-line @typescript-eslint/no-unnecessary-condition
170
186
  this._extractSpecifics();
171
187
  }
172
188
  }
@@ -206,7 +222,7 @@ class SplitFrames extends node_stream_1.Transform {
206
222
  this._frame = Buffer.from(this._frame.slice(firstEnd.end, this._frame.length));
207
223
  // search specifics
208
224
  let foundSpecific = false;
209
- for (let i = 0; i < KEYS.length && !foundSpecific; ++i) {
225
+ for (let i = 0; i < KEYS.length; ++i) {
210
226
  if (-1 < this._searchTags(this._specifics[KEYS[i]])) {
211
227
  foundSpecific = true;
212
228
  break;
@@ -359,8 +375,7 @@ class SplitFrames extends node_stream_1.Transform {
359
375
  for (let i = 0; i < tags.length; ++i) {
360
376
  // number | Buffer
361
377
  if ("number" === typeof tags[i]
362
- || ("object" === typeof tags[i]
363
- && tags[i] instanceof Buffer)) {
378
+ || ("object" === typeof tags[i] && tags[i] instanceof Buffer)) {
364
379
  const _foundAt = this._frame.indexOf(tags[i], beginAt);
365
380
  if (-1 < _foundAt && (-1 >= foundAt || _foundAt < foundAt)) {
366
381
  foundAt = _foundAt;
@@ -9,10 +9,12 @@ function checkTagsValidity(tags) {
9
9
  result = false;
10
10
  }
11
11
  else if ("object" === typeof tags && tags instanceof Array) {
12
- for (let i = 0; i < tags.length; ++i) {
13
- if ("number" !== typeof tags[i] && "object" !== typeof tags[i] && !(tags[i] instanceof Buffer)) {
14
- result = false;
15
- break;
12
+ for (const tag of tags) {
13
+ if ("number" !== typeof tag) {
14
+ if ("object" !== typeof tag || !(tag instanceof Buffer)) {
15
+ result = false;
16
+ break;
17
+ }
16
18
  }
17
19
  }
18
20
  }
@@ -15,75 +15,80 @@ const ALLOWED_CONTROL_BITS_OPTIONS = [
15
15
  ];
16
16
  // module
17
17
  function initData(options) {
18
- const result = {
19
- "startWith": undefined,
20
- "startTimeout": 200,
21
- "endWith": undefined,
22
- "escapeWith": undefined,
23
- "escaped": [],
24
- "specifics": {},
25
- "controlBits": "none"
26
- };
27
- if ("undefined" !== typeof options) {
28
- if ("object" !== typeof options) {
29
- throw new TypeError("parameter sended is not an object");
30
- }
31
- else if ("undefined" !== typeof options.startWith && !(0, checkTagsValidity_1.default)(options.startWith)) {
32
- throw new TypeError("startWith parameter sended is not a number, Buffer, or an Array of numbers");
33
- }
34
- else if ("undefined" !== typeof options.startTimeout && "number" !== typeof options.startTimeout) {
35
- throw new TypeError("startTimeout parameter sended is not a number");
36
- }
37
- else if ("undefined" !== typeof options.endWith && !(0, checkTagsValidity_1.default)(options.endWith)) {
38
- throw new TypeError("endWith parameter sended is not a number, Buffer, or an Array of numbers");
39
- }
40
- else if ("undefined" !== typeof options.escapeWith && "number" !== typeof options.escapeWith) {
41
- throw new TypeError("escapeWith parameter sended is not a number");
42
- }
43
- else if ("undefined" !== typeof options.specifics && "object" !== typeof options.specifics) {
44
- throw new TypeError("escapeWith parameter sended is not an object");
45
- }
46
- else if ("undefined" !== typeof options.controlBits && "string" !== typeof options.controlBits) {
47
- throw new TypeError("controlBits parameter sended is not a string");
48
- }
49
- else if ("undefined" !== typeof options.controlBits && !ALLOWED_CONTROL_BITS_OPTIONS.includes(options.controlBits)) {
50
- throw new Error("controlBits option sended is not in [ \"" + ALLOWED_CONTROL_BITS_OPTIONS.join("\", \"") + "\" ]");
18
+ if ("undefined" === typeof options) {
19
+ return {
20
+ "startTimeout": 200,
21
+ "escaped": [],
22
+ "specifics": {},
23
+ "controlBits": "none"
24
+ };
25
+ }
26
+ if ("object" !== typeof options) {
27
+ throw new TypeError("parameter is not an object");
28
+ }
29
+ else if ("undefined" !== typeof options.startWith && !(0, checkTagsValidity_1.default)(options.startWith)) {
30
+ throw new TypeError("startWith parameter is not a number, Buffer, or an Array of numbers");
31
+ }
32
+ else if ("undefined" !== typeof options.startTimeout && "number" !== typeof options.startTimeout) {
33
+ throw new TypeError("startTimeout parameter is not a number");
34
+ }
35
+ else if ("undefined" !== typeof options.endWith && !(0, checkTagsValidity_1.default)(options.endWith)) {
36
+ throw new TypeError("endWith parameter is not a number, Buffer, or an Array of numbers");
37
+ }
38
+ else if ("undefined" !== typeof options.escapeWith && "number" !== typeof options.escapeWith) {
39
+ throw new TypeError("escapeWith parameter is not a number");
40
+ }
41
+ else if ("undefined" !== typeof options.escaped) {
42
+ if (!(0, checkTagsValidity_1.default)(options.escaped)) {
43
+ throw new TypeError("escaped parameter is not a number, Buffer, or an Array of numbers");
51
44
  }
52
- else {
53
- result.startWith = "undefined" !== typeof options.startWith ? options.startWith : undefined;
54
- result.endWith = "undefined" !== typeof options.endWith ? options.endWith : undefined;
55
- if ("undefined" !== typeof options.startTimeout) {
56
- result.startTimeout = options.startTimeout;
57
- }
58
- result.escapeWith = "undefined" !== typeof options.escapeWith ? options.escapeWith : undefined;
59
- if ("undefined" !== typeof options.escaped) {
60
- result.escaped = options.escaped;
61
- }
62
- for (let i = 0; i < result.escaped.length; ++i) {
63
- if ("number" !== typeof result.escaped[i]) {
64
- throw new TypeError("escaped parameter n°" + i + " sended is not a number");
45
+ if (Array.isArray(options.escaped)) {
46
+ for (let i = 0; i < options.escaped.length; ++i) {
47
+ if ("number" !== typeof options.escaped[i]) {
48
+ throw new TypeError("escaped parameter n°" + i + " is not a number");
65
49
  }
66
50
  }
67
- if ("object" === typeof options.specifics) {
68
- const specifics = options.specifics;
69
- Object.keys(specifics).forEach((key) => {
70
- if ("undefined" !== typeof specifics[key]) {
71
- if (!(0, checkTagsValidity_1.default)(specifics[key])) {
72
- throw new Error("\"" + specifics[key] + "\" specifics option"
73
- + " sended is not a number, or an Array of numbers");
74
- }
75
- else if (undefined !== specifics[key]
76
- && undefined !== result.startWith
77
- && undefined === result.endWith) {
78
- throw new Error("If you want to use \"" + specifics[key] + "\" specific option,"
79
- + " you have to use \"endWith\" option");
80
- }
81
- }
82
- });
83
- }
84
- result.specifics = "undefined" !== typeof options.specifics ? options.specifics : {};
85
- result.controlBits = "undefined" !== typeof options.controlBits ? options.controlBits : "none";
86
51
  }
87
52
  }
53
+ else if ("undefined" !== typeof options.specifics && "object" !== typeof options.specifics) {
54
+ throw new TypeError("specifics parameter is not an object");
55
+ }
56
+ else if ("undefined" !== typeof options.controlBits && "string" !== typeof options.controlBits) {
57
+ throw new TypeError("controlBits parameter is not a string");
58
+ }
59
+ else if ("undefined" !== typeof options.controlBits && !ALLOWED_CONTROL_BITS_OPTIONS.includes(options.controlBits)) {
60
+ throw new Error("controlBits option is not in [ \"" + ALLOWED_CONTROL_BITS_OPTIONS.join("\", \"") + "\" ]");
61
+ }
62
+ const result = {
63
+ "startTimeout": options.startTimeout ?? 200,
64
+ "escaped": options.escaped ?? [],
65
+ "specifics": options.specifics ?? {},
66
+ "controlBits": options.controlBits ?? "none"
67
+ };
68
+ if ("undefined" !== typeof options.startWith) {
69
+ result.startWith = options.startWith;
70
+ }
71
+ if ("undefined" !== typeof options.endWith) {
72
+ result.endWith = options.endWith;
73
+ }
74
+ if ("undefined" !== typeof options.escapeWith) {
75
+ result.escapeWith = options.escapeWith;
76
+ }
77
+ if ("object" === typeof options.specifics) {
78
+ const specifics = options.specifics;
79
+ Object.keys(specifics).forEach((key) => {
80
+ if ("undefined" !== typeof specifics[key]) {
81
+ if (!(0, checkTagsValidity_1.default)(specifics[key])) {
82
+ throw new Error("\"" + String(specifics[key]) + "\" specifics option"
83
+ + " is not a number, or an Array of numbers");
84
+ }
85
+ else if ("undefined" !== typeof result.startWith
86
+ && "undefined" === typeof result.endWith) {
87
+ throw new Error("If you want to use \"" + String(specifics[key]) + "\" specific option,"
88
+ + " you have to use \"endWith\" option");
89
+ }
90
+ }
91
+ });
92
+ }
88
93
  return result;
89
94
  }
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
+
2
3
  "name": "split-frames",
3
- "version": "2.5.1",
4
- "description": "Split Buffer frames from streams",
4
+ "version": "2.7.0",
5
+ "description": "Split Buffer frames from streams.",
6
+
5
7
  "type": "commonjs",
6
8
  "typings": "./lib/cjs/main.d.cts",
9
+
7
10
  "main": "./lib/cjs/main.cjs",
8
11
  "exports": {
9
12
  ".": {
@@ -13,43 +16,55 @@
13
16
  }
14
17
  }
15
18
  },
19
+
16
20
  "scripts": {
17
- "prepare": "husky",
18
- "clean": "npx rimraf lib/cjs",
19
- "build": "npm run-script clean && npx tsc --project \"./tsconfig.json\"",
20
- "lint": "npx eslint --config .eslintrc-src.js --ext .cts,.ts ./lib/src/**/* && npx eslint --config .eslintrc-tests.js ./bin/*.js ./test/**/*.js",
21
- "check-requires": "npx used-deps-analyzer \"./package.json\" \"./lib/src\" --no-dev --overkill \"fs-extra\" \"node-promfs\"",
22
- "check-updates": "npx check-version-modules",
23
- "unit-tests": "npm run-script build && npx nyc --reporter=html --reporter=text mocha",
24
- "tests": "npm run-script lint && npm run-script check-requires && npm run-script check-updates && npm run-script unit-tests"
21
+
22
+ "prepare": "npx husky || true",
23
+
24
+ "lint-back": "npx eslint --config .eslintrc-back.js --ext .ts,.cts,.mts ./lib/src/**/*",
25
+ "lint-tests": "npx eslint --config .eslintrc-tests.js --ext .js,.cjs,.mjs ./test/**/*",
26
+ "lint": "npm run lint-back && npm run lint-tests",
27
+
28
+ "clean-back": "npx rimraf ./lib/cjs",
29
+ "clean": "npm run clean-back",
30
+
31
+ "build-back": "npm run clean-back && npx tsc --project ./tsconfig.json",
32
+ "build": "npm run build-back",
33
+
34
+ "check-requires": "npx used-deps-analyzer ./package.json ./lib/src --no-dev",
35
+ "check-updates": "npx check-version-modules --no-fail-at-major --fail-at-minor --fail-at-patch",
36
+ "unit-tests": "npx mocha",
37
+ "unit-tests-local": "npx nyc --reporter=html --reporter=text mocha",
38
+
39
+ "tests": "npm run lint && npm run check-requires && npm run check-updates && npm run build && npm run unit-tests-local"
40
+
25
41
  },
42
+
26
43
  "files": [
27
- "/bin",
28
- "/lib/cjs",
29
- "/public"
44
+ "lib/cjs"
30
45
  ],
31
46
  "engines": {
32
- "node": ">=16.0.0"
47
+ "node": ">=22.22.0"
33
48
  },
49
+
34
50
  "dependencies": {},
35
51
  "devDependencies": {
36
- "@types/node": "22.7.8",
37
- "check-version-modules": "2.1.2",
52
+ "@types/node": "25.6.0",
53
+ "check-version-modules": "2.3.0",
38
54
  "colors": "1.4.0",
39
55
  "eslint-plugin-personnallinter": "git+ssh://git@github.com/Psychopoulet/eslint-plugin-personnallinter",
40
- "husky": "9.1.6",
41
- "mocha": "10.7.3",
42
- "nyc": "17.1.0",
43
- "rimraf": "6.0.1",
44
- "typescript": "5.6.3",
45
- "used-deps-analyzer": "0.1.8"
56
+ "husky": "9.1.7",
57
+ "mocha": "11.7.5",
58
+ "nyc": "18.0.0",
59
+ "rimraf": "6.1.3",
60
+ "typescript": "5.9.3",
61
+ "used-deps-analyzer": "0.3.0"
46
62
  },
47
- "optionalDependencies": {},
63
+
48
64
  "husky": {
49
65
  "hooks": {
50
- "pre-commit": "npm run-script lint",
51
- "pre-push": "npm run-script unit-tests",
52
- "pre-receive": "npm run-script tests"
66
+ "pre-commit": "npm run lint",
67
+ "pre-push": "npm run build && npm run unit-tests-local"
53
68
  }
54
69
  },
55
70
  "keywords": [
@@ -84,12 +99,14 @@
84
99
  }
85
100
  ],
86
101
  "license": "ISC",
102
+
87
103
  "homepage": "https://github.com/Psychopoulet/split-frames#readme",
88
104
  "repository": {
89
105
  "type": "git",
90
- "url": "git://github.com/Psychopoulet/split-frames"
106
+ "url": "git://github.com/Psychopoulet/split-frames.git"
91
107
  },
92
108
  "bugs": {
93
109
  "url": "https://github.com/Psychopoulet/split-frames/issues"
94
110
  }
111
+
95
112
  }