@dra2020/baseclient 1.0.53 → 1.0.54
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/dist/baseclient.js +35 -1
- package/dist/baseclient.js.map +1 -1
- package/dist/util/bitset.d.ts +10 -1
- package/lib/util/bitset.ts +54 -1
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -9725,9 +9725,20 @@ exports.BinTrieBuilder = BinTrieBuilder;
|
|
|
9725
9725
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
9726
9726
|
exports.ListToBitset = void 0;
|
|
9727
9727
|
const BitLookup = [1, 2, 4, 8, 16, 32, 64, 128];
|
|
9728
|
+
// In NodeJS:
|
|
9729
|
+
// {
|
|
9730
|
+
// btoa: (s: string) => { return Buffer.from(s, 'binary').toString('base64') },
|
|
9731
|
+
// atob: (s: string) => { return Buffer.from(s, 'base64').toString('binary') },
|
|
9732
|
+
// }
|
|
9733
|
+
// In Browser:
|
|
9734
|
+
// {
|
|
9735
|
+
// btoa: window.btoa,
|
|
9736
|
+
// atob: window.atob,
|
|
9737
|
+
// }
|
|
9728
9738
|
class ListToBitset {
|
|
9729
|
-
constructor(list) {
|
|
9739
|
+
constructor(list, converter) {
|
|
9730
9740
|
this.list = list;
|
|
9741
|
+
this.converter = converter;
|
|
9731
9742
|
}
|
|
9732
9743
|
toBits(l) {
|
|
9733
9744
|
if (!this.index) {
|
|
@@ -9770,6 +9781,29 @@ class ListToBitset {
|
|
|
9770
9781
|
}
|
|
9771
9782
|
return list;
|
|
9772
9783
|
}
|
|
9784
|
+
base64tou8(base64) {
|
|
9785
|
+
let raw = this.converter.atob(base64);
|
|
9786
|
+
let rawLength = raw.length;
|
|
9787
|
+
let u8 = new Uint8Array(new ArrayBuffer(rawLength));
|
|
9788
|
+
for (let i = 0; i < rawLength; i++)
|
|
9789
|
+
u8[i] = raw.charCodeAt(i);
|
|
9790
|
+
return u8;
|
|
9791
|
+
}
|
|
9792
|
+
u8ToBase64(u8) {
|
|
9793
|
+
let binary = [];
|
|
9794
|
+
let len = u8.byteLength;
|
|
9795
|
+
for (let i = 0; i < len; i++) {
|
|
9796
|
+
binary.push(String.fromCharCode(u8[i]));
|
|
9797
|
+
}
|
|
9798
|
+
return this.converter.btoa(binary.join(''));
|
|
9799
|
+
}
|
|
9800
|
+
fromBitString(base64) {
|
|
9801
|
+
return this.toList(this.base64tou8(base64));
|
|
9802
|
+
}
|
|
9803
|
+
toBitString(l) {
|
|
9804
|
+
// Note: On server, Buffer.from(this.toBits(l)).toString('base64') probably faster
|
|
9805
|
+
return this.u8ToBase64(this.toBits(l));
|
|
9806
|
+
}
|
|
9773
9807
|
}
|
|
9774
9808
|
exports.ListToBitset = ListToBitset;
|
|
9775
9809
|
|