@dra2020/baseclient 1.0.21 → 1.0.22

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.
@@ -0,0 +1 @@
1
+ export * from './emit';
@@ -0,0 +1,7 @@
1
+ export declare class Emit {
2
+ onList: any;
3
+ constructor();
4
+ on(eventName: string, cb: any): void;
5
+ emit(eventName: string, arg1?: any, arg2?: any, arg3?: any): void;
6
+ off(eventName: string, cb: any): void;
7
+ }
@@ -69,6 +69,7 @@ export declare class BinTrie {
69
69
  constructor(coder: Coder);
70
70
  static fromBuffer(coder: Coder, ab: ArrayBuffer): BinTrie;
71
71
  get(key: string): string;
72
+ forEach(cb: (k: string, v: string) => void): void;
72
73
  }
73
74
  export interface BinTrieOptions {
74
75
  dedup?: boolean;
package/lib/all/all.ts CHANGED
@@ -19,3 +19,5 @@ import { FilterExpr } from '../filterexpr/all';
19
19
  export { FilterExpr }
20
20
  import * as G from '../geo/all';
21
21
  export { G };
22
+ import * as Emit from '../emit/all';
23
+ export { Emit };
@@ -0,0 +1 @@
1
+ export * from './emit';
@@ -0,0 +1,40 @@
1
+ export class Emit
2
+ {
3
+ onList: any;
4
+
5
+ constructor()
6
+ {
7
+ this.onList = {};
8
+ }
9
+
10
+ on(eventName: string, cb: any): void
11
+ {
12
+ let aCB: any = this.onList[eventName];
13
+ if (aCB === undefined)
14
+ {
15
+ aCB = [];
16
+ this.onList[eventName] = aCB;
17
+ }
18
+ aCB.push(cb);
19
+ }
20
+
21
+ emit(eventName: string, arg1?: any, arg2?: any, arg3?: any): void
22
+ {
23
+ let aCB: any[] = this.onList[eventName];
24
+ if (aCB !== undefined)
25
+ for (let i: number = 0; i < aCB.length; i++)
26
+ (aCB[i])(arg1, arg2, arg3);
27
+ }
28
+
29
+ off(eventName: string, cb: any): void
30
+ {
31
+ let aCB: any = this.onList[eventName];
32
+ if (aCB !== undefined)
33
+ for (let i: number = 0; i < aCB.length; i++)
34
+ if (aCB[i] === cb)
35
+ {
36
+ aCB.splice(i, 1);
37
+ break;
38
+ }
39
+ }
40
+ }
@@ -57,6 +57,8 @@ Util.setCoder({ encoder: new u.TextEncoder(), decoder: new u.TextDecoder('utf-8'
57
57
  Util.setCoder({ encoder: new TextEncoder(), decoder: new TextDecoder('utf-8') });
58
58
  */
59
59
 
60
+ const MaxKeyLength = 128;
61
+
60
62
  export function s2u8(coder: Coder, s: string): Uint8Array
61
63
  {
62
64
  return coder.encoder.encode(s);
@@ -343,6 +345,23 @@ export class BinTrie
343
345
  }
344
346
  return undefined;
345
347
  }
348
+
349
+ forEach(cb: (k: string, v: string) => void)
350
+ {
351
+ let keybuf = new Uint8Array(MaxKeyLength);
352
+ let keylen = 0;
353
+
354
+ let processNode = (len: number, byteOffset: number) => {
355
+ let iOffset = byteOffset >> 2;
356
+ let n = this.i32[iOffset];
357
+ byteOffset += 4;
358
+ for (let j = 0; j < n; j++)
359
+ {
360
+ keybuf[keylen++] = this.u8[byteOffset+j];
361
+ }
362
+ };
363
+ processNode(0, 4);
364
+ }
346
365
  }
347
366
 
348
367
  export interface BinTrieOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",