cafe-utility 28.1.0 → 28.2.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 +4 -0
- package/index.js +16 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -256,6 +256,8 @@ declare function base32ToUint8Array(base32String: string): Uint8Array;
|
|
|
256
256
|
declare function uint8ArrayToBase32(array: Uint8Array): string;
|
|
257
257
|
declare function hexToUint8Array(hex: string): Uint8Array;
|
|
258
258
|
declare function uint8ArrayToHex(array: Uint8Array): string;
|
|
259
|
+
declare function uint8ArrayToBinary(array: Uint8Array): string;
|
|
260
|
+
declare function binaryToUint8Array(binary: string): Uint8Array;
|
|
259
261
|
declare function route(pattern: string, actual: string): Record<string, unknown> | null;
|
|
260
262
|
type VariantGroup = {
|
|
261
263
|
variants: string[];
|
|
@@ -667,6 +669,8 @@ export declare class TrieRouter<Q, S> {
|
|
|
667
669
|
export declare const Binary: {
|
|
668
670
|
hexToUint8Array: typeof hexToUint8Array;
|
|
669
671
|
uint8ArrayToHex: typeof uint8ArrayToHex;
|
|
672
|
+
binaryToUint8Array: typeof binaryToUint8Array;
|
|
673
|
+
uint8ArrayToBinary: typeof uint8ArrayToBinary;
|
|
670
674
|
base64ToUint8Array: typeof base64ToUint8Array;
|
|
671
675
|
uint8ArrayToBase64: typeof uint8ArrayToBase64;
|
|
672
676
|
base32ToUint8Array: typeof base32ToUint8Array;
|
package/index.js
CHANGED
|
@@ -1144,6 +1144,20 @@ function uint8ArrayToHex(n) {
|
|
|
1144
1144
|
.map(e => e.toString(16).padStart(2, '0'))
|
|
1145
1145
|
.join('')
|
|
1146
1146
|
}
|
|
1147
|
+
function uint8ArrayToBinary(n) {
|
|
1148
|
+
return Array.from(n)
|
|
1149
|
+
.map(e => e.toString(2).padStart(8, '0'))
|
|
1150
|
+
.join('')
|
|
1151
|
+
}
|
|
1152
|
+
function binaryToUint8Array(n) {
|
|
1153
|
+
const e = Math.ceil(n.length / 8),
|
|
1154
|
+
t = new Uint8Array(e)
|
|
1155
|
+
for (let r = 0; r < e; r++) {
|
|
1156
|
+
const o = parseInt(n.slice(r * 8, r * 8 + 8), 2)
|
|
1157
|
+
t[r] = o
|
|
1158
|
+
}
|
|
1159
|
+
return t
|
|
1160
|
+
}
|
|
1147
1161
|
function route(n, e) {
|
|
1148
1162
|
const t = n.split('/').filter(i => i),
|
|
1149
1163
|
r = e.split('/').filter(i => i)
|
|
@@ -3133,6 +3147,8 @@ class TrieRouter {
|
|
|
3133
3147
|
(exports.Binary = {
|
|
3134
3148
|
hexToUint8Array,
|
|
3135
3149
|
uint8ArrayToHex,
|
|
3150
|
+
binaryToUint8Array,
|
|
3151
|
+
uint8ArrayToBinary,
|
|
3136
3152
|
base64ToUint8Array,
|
|
3137
3153
|
uint8ArrayToBase64,
|
|
3138
3154
|
base32ToUint8Array,
|