@nxtedition/slice 1.1.0 → 1.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/lib/index.d.ts CHANGED
@@ -1,4 +1,9 @@
1
1
  import util from 'node:util';
2
+ export type SliceLike = {
3
+ buffer: Buffer;
4
+ byteOffset: number;
5
+ byteLength: number;
6
+ };
2
7
  export declare class Slice {
3
8
  buffer: Buffer;
4
9
  byteOffset: number;
package/lib/index.js CHANGED
@@ -2,6 +2,12 @@ import util from 'node:util'
2
2
 
3
3
  const EMPTY_BUF = Buffer.alloc(0)
4
4
 
5
+
6
+
7
+
8
+
9
+
10
+
5
11
  export class Slice {
6
12
  buffer = EMPTY_BUF
7
13
  byteOffset = 0
@@ -59,16 +65,6 @@ export class Slice {
59
65
  sourceStart ,
60
66
  sourceEnd ,
61
67
  ) {
62
- if (target instanceof Slice) {
63
- if (targetStart === undefined) {
64
- targetStart = target.byteOffset
65
- } else {
66
- targetStart += target.byteOffset
67
- }
68
-
69
- target = target.buffer
70
- }
71
-
72
68
  if (sourceStart === undefined) {
73
69
  sourceStart = this.byteOffset
74
70
  } else {
@@ -81,6 +77,20 @@ export class Slice {
81
77
  sourceEnd += this.byteOffset
82
78
  }
83
79
 
80
+ let targetEnd
81
+
82
+ if (target instanceof Slice) {
83
+ targetEnd = target.byteOffset + target.byteLength
84
+ if (targetStart === undefined) {
85
+ targetStart = target.byteOffset
86
+ } else {
87
+ targetStart += target.byteOffset
88
+ }
89
+
90
+ target = target.buffer
91
+ sourceEnd = Math.min(sourceEnd, sourceStart + (targetEnd - targetStart))
92
+ }
93
+
84
94
  if (
85
95
  sourceStart === targetStart &&
86
96
  this.buffer.buffer === target.buffer &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/slice",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -30,5 +30,5 @@
30
30
  "tsd": "^0.33.0",
31
31
  "typescript": "^5.9.3"
32
32
  },
33
- "gitHead": "80358629a4abe8d9065ac1d1b92ef378493c2dcb"
33
+ "gitHead": "7c9c7457c885c644c7a1e70ef894d4727ce240d6"
34
34
  }