• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

project-slippi / slippi-js / 19535476215

20 Nov 2025 11:34AM UTC coverage: 81.464% (+0.07%) from 81.39%
19535476215

Pull #150

github

web-flow
Merge 8cbb96535 into 02a2c65e6
Pull Request #150: Refactor SlippiGame to be web-compatible by default

693 of 926 branches covered (74.84%)

Branch coverage included in aggregate %.

162 of 181 new or added lines in 14 files covered. (89.5%)

1966 of 2338 relevant lines covered (84.09%)

122860.25 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

82.35
/src/common/utils/bufferHelpers.ts
1
export type BinaryLike = ArrayBuffer | ArrayBufferView; // works for Buffer, Uint8Array, etc.
2

3
export function byteLength(data: BinaryLike): number {
12✔
4
  if (data instanceof ArrayBuffer) {
18,693✔
5
    return data.byteLength;
30✔
6
  }
7
  return data.byteLength; // ArrayBufferView (includes Buffer)
18,663✔
8
}
9

10
export function asUint8Array(data: BinaryLike): Uint8Array {
12✔
11
  if (data instanceof Uint8Array) {
37,266✔
12
    return data;
37,238✔
13
  }
14
  if (data instanceof ArrayBuffer) {
28✔
15
    return new Uint8Array(data);
28✔
16
  }
NEW
17
  return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
×
18
}
19

20
/**
21
 * Cross-platform copy, mirroring Buffer.copy's signature.
22
 * Returns the number of bytes copied.
23
 */
24
export function bufferCopy(
12✔
25
  src: BinaryLike,
26
  dst: BinaryLike,
27
  targetStart = 0,
×
28
  sourceStart = 0,
×
29
  sourceEnd?: number,
30
): number {
31
  const s = asUint8Array(src);
18,633✔
32
  const d = asUint8Array(dst);
18,633✔
33

34
  const sLen = s.length;
18,633✔
35
  const ss = Math.max(0, Math.min(sourceStart, sLen));
18,633✔
36
  const se = sourceEnd === undefined ? sLen : Math.max(ss, Math.min(sourceEnd, sLen));
18,633!
37
  const ts = Math.max(0, Math.min(targetStart, d.length));
18,633✔
38

39
  const toCopy = Math.min(se - ss, d.length - ts);
18,633✔
40
  if (toCopy <= 0) {
18,633!
NEW
41
    return 0;
×
42
  }
43

44
  // Handles overlap correctly per TypedArray.set semantics
45
  d.set(s.subarray(ss, ss + toCopy), ts);
18,633✔
46
  return toCopy;
18,633✔
47
}
48

49
/** Cross-platform test for Buffer, ArrayBuffer, or typed array */
50
export function isBufferLike(x: unknown): x is BinaryLike {
12✔
51
  return (
4✔
52
    x instanceof ArrayBuffer || ArrayBuffer.isView(x) // true for all TypedArrays and Node Buffers
7✔
53
  );
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc