@dra2020/baseclient 1.0.52 → 1.0.55

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.
@@ -21,6 +21,7 @@ export declare const FilterTrash: number;
21
21
  export declare const FilterPublic: number;
22
22
  export declare const FilterOfficial: number;
23
23
  export declare const FilterCOI: number;
24
+ export declare const FilterMyGroups: number;
24
25
  export declare const FilterCount: number;
25
26
  export declare type Filter = number;
26
27
  export declare const PermNone: number;
@@ -91,6 +92,7 @@ export interface SessionProps {
91
92
  xprops?: {
92
93
  [prop: string]: string;
93
94
  };
95
+ groups: any;
94
96
  }
95
97
  export declare type LabelUpdate = {
96
98
  [name: string]: boolean | null;
@@ -1,10 +1,19 @@
1
+ export interface Converter {
2
+ atob?: (s: string) => string;
3
+ btoa?: (s: string) => string;
4
+ }
1
5
  export declare class ListToBitset {
2
6
  list: string[];
3
7
  index: {
4
8
  [s: string]: number;
5
9
  };
6
10
  size: number;
7
- constructor(list: string[]);
11
+ converter: Converter;
12
+ constructor(list: string[], converter?: Converter);
8
13
  toBits(l: string[]): Uint8Array;
9
14
  toList(u8: Uint8Array): string[];
15
+ base64tou8(base64: string): Uint8Array;
16
+ u8ToBase64(u8: Uint8Array): string;
17
+ fromBitString(base64: string): string[];
18
+ toBitString(l: string[]): string;
10
19
  }
@@ -24,7 +24,8 @@ export const FilterTrash: number = 4;
24
24
  export const FilterPublic: number = 5;
25
25
  export const FilterOfficial: number = 6;
26
26
  export const FilterCOI: number = 7;
27
- export const FilterCount: number = 8;
27
+ export const FilterMyGroups: number = 8;
28
+ export const FilterCount: number = 9;
28
29
  export type Filter = number;
29
30
 
30
31
  // Permissions
@@ -117,6 +118,7 @@ export interface SessionProps
117
118
  expunged?: boolean;
118
119
  expungeDate?: string;
119
120
  xprops?: { [prop: string]: string };
121
+ groups: any; // DT.GroupsMapIndex
120
122
  }
121
123
 
122
124
  // True to add, False to remove
@@ -1,21 +1,46 @@
1
1
  const BitLookup = [ 1, 2, 4, 8, 16, 32, 64, 128 ];
2
2
 
3
+ export interface Converter
4
+ {
5
+ atob?: (s: string) => string;
6
+ btoa?: (s: string) => string;
7
+ }
8
+
9
+ // In NodeJS:
10
+
11
+ // {
12
+ // btoa: (s: string) => { return Buffer.from(s, 'binary').toString('base64') },
13
+ // atob: (s: string) => { return Buffer.from(s, 'base64').toString('binary') },
14
+ // }
15
+
16
+ // In Browser:
17
+
18
+ // {
19
+ // btoa: window.btoa,
20
+ // atob: window.atob,
21
+ // }
22
+
3
23
  export class ListToBitset
4
24
  {
5
25
  list: string[];
6
26
  index: { [s: string]: number };
7
27
  size: number;
28
+ converter: Converter;
8
29
 
9
- constructor(list: string[])
30
+ constructor(list: string[], converter?: Converter)
10
31
  {
11
32
  this.list = list;
12
- this.index = {};
13
- this.size = Math.floor((this.list.length+7)/8);
14
- this.list.forEach((s: string, i: number) => { this.index[s] = i });
33
+ this.converter = converter;
15
34
  }
16
35
 
17
36
  toBits(l: string[]): Uint8Array
18
37
  {
38
+ if (! this.index)
39
+ {
40
+ this.size = Math.floor((this.list.length+7)/8);
41
+ this.index = {};
42
+ this.list.forEach((s: string, i: number) => { this.index[s] = i });
43
+ }
19
44
  let ab = new ArrayBuffer(this.size);
20
45
  let u8 = new Uint8Array(ab);
21
46
  if (l) l.forEach(s => {
@@ -46,4 +71,35 @@ export class ListToBitset
46
71
  }
47
72
  return list;
48
73
  }
74
+
75
+ base64tou8(base64: string): Uint8Array
76
+ {
77
+ let raw = this.converter.atob(base64);
78
+ let rawLength = raw.length;
79
+ let u8 = new Uint8Array(new ArrayBuffer(rawLength));
80
+ for (let i = 0; i < rawLength; i++)
81
+ u8[i] = raw.charCodeAt(i);
82
+ return u8;
83
+ }
84
+
85
+ u8ToBase64(u8: Uint8Array): string
86
+ {
87
+ let binary: string[] = [];
88
+ let len = u8.byteLength;
89
+ for (let i = 0; i < len; i++) {
90
+ binary.push(String.fromCharCode(u8[i]));
91
+ }
92
+ return this.converter.btoa(binary.join(''));
93
+ }
94
+
95
+ fromBitString(base64: string): string[]
96
+ {
97
+ return this.toList(this.base64tou8(base64));
98
+ }
99
+
100
+ toBitString(l: string[]): string
101
+ {
102
+ // Note: On server, Buffer.from(this.toBits(l)).toString('base64') probably faster
103
+ return this.u8ToBase64(this.toBits(l));
104
+ }
49
105
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.52",
3
+ "version": "1.0.55",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",