cafe-utility 22.4.0 → 23.0.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/index.d.ts CHANGED
@@ -538,6 +538,11 @@ declare function findLines(grid: Truthy[][], tileSize: number): Line[];
538
538
  declare function getLineIntersectionPoint(line1Start: Point, line1End: Point, line2Start: Point, line2End: Point): Point | null;
539
539
  declare function raycast(origin: Point, lines: Line[], angle: number): Point | null;
540
540
  declare function raycastCircle(origin: Point, lines: Line[], corners: Point[]): Point[];
541
+ export declare class PubSubChannel<T> {
542
+ private subscribers;
543
+ subscribe(callback: (data: unknown) => void): () => void;
544
+ publish(data: T): void;
545
+ }
541
546
  export declare const Binary: {
542
547
  hexToUint8Array: typeof hexToUint8Array;
543
548
  uint8ArrayToHex: typeof uint8ArrayToHex;
package/index.js CHANGED
@@ -13,6 +13,7 @@ Object.defineProperty(exports, '__esModule', { value: !0 }),
13
13
  exports.Arrays =
14
14
  exports.Random =
15
15
  exports.Binary =
16
+ exports.PubSubChannel =
16
17
  exports.Optional =
17
18
  void 0)
18
19
  async function invertPromise(n) {
@@ -2347,22 +2348,39 @@ function raycastCircle(n, t, e) {
2347
2348
  }
2348
2349
  return i
2349
2350
  }
2350
- ;(exports.Binary = {
2351
- hexToUint8Array,
2352
- uint8ArrayToHex,
2353
- base64ToUint8Array,
2354
- uint8ArrayToBase64,
2355
- log2Reduce,
2356
- partition,
2357
- concatBytes,
2358
- merkleStart,
2359
- merkleAppend,
2360
- merkleFinalize,
2361
- numberToUint64LE,
2362
- uint64LEToNumber,
2363
- numberToUint64BE,
2364
- uint64BEToNumber
2365
- }),
2351
+ class PubSubChannel {
2352
+ constructor() {
2353
+ this.subscribers = []
2354
+ }
2355
+ subscribe(t) {
2356
+ return (
2357
+ this.subscribers.push(t),
2358
+ () => {
2359
+ this.subscribers = this.subscribers.filter(e => e !== t)
2360
+ }
2361
+ )
2362
+ }
2363
+ publish(t) {
2364
+ this.subscribers.forEach(e => e(t))
2365
+ }
2366
+ }
2367
+ ;(exports.PubSubChannel = PubSubChannel),
2368
+ (exports.Binary = {
2369
+ hexToUint8Array,
2370
+ uint8ArrayToHex,
2371
+ base64ToUint8Array,
2372
+ uint8ArrayToBase64,
2373
+ log2Reduce,
2374
+ partition,
2375
+ concatBytes,
2376
+ merkleStart,
2377
+ merkleAppend,
2378
+ merkleFinalize,
2379
+ numberToUint64LE,
2380
+ uint64LEToNumber,
2381
+ numberToUint64BE,
2382
+ uint64BEToNumber
2383
+ }),
2366
2384
  (exports.Random = {
2367
2385
  intBetween,
2368
2386
  floatBetween,
package/module.mjs CHANGED
@@ -15,3 +15,4 @@ export const System = utility.System
15
15
  export const Types = utility.Types
16
16
  export const Optional = utility.Optional
17
17
  export const Vector = utility.Vector
18
+ export const PubSubChannel = utility.PubSubChannel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cafe-utility",
3
- "version": "22.4.0",
3
+ "version": "23.0.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "exports": {