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

project-slippi / slippi-js / 19973536637

05 Dec 2025 07:18PM UTC coverage: 81.336% (+0.08%) from 81.254%
19973536637

push

github

web-flow
Refactor SlippiGame to be web-compatible by default (#150)

* use EventTarget instead of event emitter

* fix event emitter shim

* stop using EventEmitter in stats

* it works!

* fix imports and typings

* create two distinct index.ts files for the different environments

* dont use accessor cuz it causes issues or something

* i think this actually works

* use cross env for windows env

* add node subpath to exports

* i think it actually works

* dts is not very configurable so use rollup directly instead

* don't hardcode filenames

* fix lint not working

* update readme to include distinction between web and node exports

* update example to use the node export

* fix windows builds

* separate common from other node exports

* i dont think slpReader should actually be exported

* for typesafety, don't accept string as input on the web

* remove unused dependency

* chore: fix eslint error

* minify for production

* chore(deps): remove unused lodash-es dependency

* chore(deps): remove tslib dependency

* reduce duplication

* reorganise structure

* try to fix windows build

* simplify build config

* add old style exports for backwards compatibility

* simplify browser constructor

* rename node/nodeUtils to just node/utils

* fix lint

* update error message with explicit node import path

* fix missing ws dependency issue with enet

* update package-lock.json

* update date-fns to match launcher version

* simplify buffer input ref creation

* make slpstream web-first

* fix issue with slp parsing expecting a frame

* create a single TextDecoder

* use .subarray() instead of .slice() where possible

* rename TypedEventTarget -> TypedEventEmitter

* try to fix build taking forever

* simplify TypedEventEmitter

* make node event emitters also type-safe

* add a once() method to event emitter

* deps: see if upgrading deps fixes random macos hangs

* working abstract class impl

* add missing getFilePath override

* bundle ubjson with requi... (continued)

694 of 928 branches covered (74.78%)

Branch coverage included in aggregate %.

158 of 178 new or added lines in 16 files covered. (88.76%)

1960 of 2335 relevant lines covered (83.94%)

119971.77 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