cafe-utility 26.3.0 → 26.5.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 +10 -0
- package/index.js +68 -37
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -357,6 +357,7 @@ declare function getDayInfoFromDateTimeString(dateTimeString: string): DayInfo;
|
|
|
357
357
|
declare function seconds(value: number): number;
|
|
358
358
|
declare function minutes(value: number): number;
|
|
359
359
|
declare function hours(value: number): number;
|
|
360
|
+
declare function days(value: number): number;
|
|
360
361
|
declare function makeDate(numberWithUnit: string): number;
|
|
361
362
|
declare function makeStorage(numberWithUnit: string): number;
|
|
362
363
|
declare function getPreLine(string: string): string;
|
|
@@ -506,6 +507,10 @@ declare function sliceBytes(bytes: Uint8Array, lengths: number[]): Uint8Array[];
|
|
|
506
507
|
declare function partition(bytes: Uint8Array, size: number): Uint8Array[];
|
|
507
508
|
declare function keccak256(bytes: Uint8Array): Uint8Array;
|
|
508
509
|
declare function sha3_256(bytes: Uint8Array): Uint8Array;
|
|
510
|
+
declare function proximity(one: Uint8Array, other: Uint8Array, max: number): number;
|
|
511
|
+
declare function commonPrefix(one: Uint8Array, other: Uint8Array): Uint8Array;
|
|
512
|
+
declare function setBit(bytes: Uint8Array, index: number, value: 0 | 1): void;
|
|
513
|
+
declare function getBit(bytes: Uint8Array, index: number): 0 | 1;
|
|
509
514
|
interface Uint8ArrayIO {
|
|
510
515
|
max: () => number;
|
|
511
516
|
}
|
|
@@ -614,6 +619,10 @@ export declare const Binary: {
|
|
|
614
619
|
sliceBytes: typeof sliceBytes;
|
|
615
620
|
keccak256: typeof keccak256;
|
|
616
621
|
sha3_256: typeof sha3_256;
|
|
622
|
+
proximity: typeof proximity;
|
|
623
|
+
commonPrefix: typeof commonPrefix;
|
|
624
|
+
setBit: typeof setBit;
|
|
625
|
+
getBit: typeof getBit;
|
|
617
626
|
};
|
|
618
627
|
export declare const Random: {
|
|
619
628
|
intBetween: typeof intBetween;
|
|
@@ -739,6 +748,7 @@ export declare const Dates: {
|
|
|
739
748
|
seconds: typeof seconds;
|
|
740
749
|
minutes: typeof minutes;
|
|
741
750
|
hours: typeof hours;
|
|
751
|
+
days: typeof days;
|
|
742
752
|
make: typeof makeDate;
|
|
743
753
|
normalizeTime: typeof normalizeTime;
|
|
744
754
|
absoluteDays: typeof absoluteDays;
|
package/index.js
CHANGED
|
@@ -1477,6 +1477,9 @@ function minutes(n) {
|
|
|
1477
1477
|
function hours(n) {
|
|
1478
1478
|
return n * 36e5
|
|
1479
1479
|
}
|
|
1480
|
+
function days(n) {
|
|
1481
|
+
return n * 864e5
|
|
1482
|
+
}
|
|
1480
1483
|
const dateUnits = {
|
|
1481
1484
|
ms: 1,
|
|
1482
1485
|
milli: 1,
|
|
@@ -2175,10 +2178,10 @@ function keccakPermutate(n) {
|
|
|
2175
2178
|
h = (o << 1) | (i >>> 31),
|
|
2176
2179
|
bn = (i << 1) | (o >>> 31),
|
|
2177
2180
|
p = l ^ h,
|
|
2178
|
-
|
|
2181
|
+
m = a ^ bn,
|
|
2179
2182
|
$n = (u << 1) | (s >>> 31),
|
|
2180
2183
|
An = (s << 1) | (u >>> 31),
|
|
2181
|
-
|
|
2184
|
+
d = t ^ $n,
|
|
2182
2185
|
g = r ^ An,
|
|
2183
2186
|
Mn = (c << 1) | (f >>> 31),
|
|
2184
2187
|
On = (f << 1) | (c >>> 31),
|
|
@@ -2193,8 +2196,8 @@ function keccakPermutate(n) {
|
|
|
2193
2196
|
$ = c ^ kn,
|
|
2194
2197
|
A = f ^ Dn
|
|
2195
2198
|
;(n[0] ^= p),
|
|
2196
|
-
(n[1] ^=
|
|
2197
|
-
(n[2] ^=
|
|
2199
|
+
(n[1] ^= m),
|
|
2200
|
+
(n[2] ^= d),
|
|
2198
2201
|
(n[3] ^= g),
|
|
2199
2202
|
(n[4] ^= y),
|
|
2200
2203
|
(n[5] ^= w),
|
|
@@ -2203,8 +2206,8 @@ function keccakPermutate(n) {
|
|
|
2203
2206
|
(n[8] ^= $),
|
|
2204
2207
|
(n[9] ^= A),
|
|
2205
2208
|
(n[10] ^= p),
|
|
2206
|
-
(n[11] ^=
|
|
2207
|
-
(n[12] ^=
|
|
2209
|
+
(n[11] ^= m),
|
|
2210
|
+
(n[12] ^= d),
|
|
2208
2211
|
(n[13] ^= g),
|
|
2209
2212
|
(n[14] ^= y),
|
|
2210
2213
|
(n[15] ^= w),
|
|
@@ -2213,8 +2216,8 @@ function keccakPermutate(n) {
|
|
|
2213
2216
|
(n[18] ^= $),
|
|
2214
2217
|
(n[19] ^= A),
|
|
2215
2218
|
(n[20] ^= p),
|
|
2216
|
-
(n[21] ^=
|
|
2217
|
-
(n[22] ^=
|
|
2219
|
+
(n[21] ^= m),
|
|
2220
|
+
(n[22] ^= d),
|
|
2218
2221
|
(n[23] ^= g),
|
|
2219
2222
|
(n[24] ^= y),
|
|
2220
2223
|
(n[25] ^= w),
|
|
@@ -2223,8 +2226,8 @@ function keccakPermutate(n) {
|
|
|
2223
2226
|
(n[28] ^= $),
|
|
2224
2227
|
(n[29] ^= A),
|
|
2225
2228
|
(n[30] ^= p),
|
|
2226
|
-
(n[31] ^=
|
|
2227
|
-
(n[32] ^=
|
|
2229
|
+
(n[31] ^= m),
|
|
2230
|
+
(n[32] ^= d),
|
|
2228
2231
|
(n[33] ^= g),
|
|
2229
2232
|
(n[34] ^= y),
|
|
2230
2233
|
(n[35] ^= w),
|
|
@@ -2233,8 +2236,8 @@ function keccakPermutate(n) {
|
|
|
2233
2236
|
(n[38] ^= $),
|
|
2234
2237
|
(n[39] ^= A),
|
|
2235
2238
|
(n[40] ^= p),
|
|
2236
|
-
(n[41] ^=
|
|
2237
|
-
(n[42] ^=
|
|
2239
|
+
(n[41] ^= m),
|
|
2240
|
+
(n[42] ^= d),
|
|
2238
2241
|
(n[43] ^= g),
|
|
2239
2242
|
(n[44] ^= y),
|
|
2240
2243
|
(n[45] ^= w),
|
|
@@ -2254,10 +2257,10 @@ function keccakPermutate(n) {
|
|
|
2254
2257
|
I = (n[9] << 27) | (n[8] >>> 5),
|
|
2255
2258
|
L = (n[11] << 4) | (n[10] >>> 28),
|
|
2256
2259
|
P = (n[10] << 4) | (n[11] >>> 28),
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2260
|
+
B = (n[13] << 12) | (n[12] >>> 20),
|
|
2261
|
+
N = (n[12] << 12) | (n[13] >>> 20),
|
|
2262
|
+
j = (n[14] << 6) | (n[15] >>> 26),
|
|
2263
|
+
U = (n[15] << 6) | (n[14] >>> 26),
|
|
2261
2264
|
F = (n[17] << 23) | (n[16] >>> 9),
|
|
2262
2265
|
z = (n[16] << 23) | (n[17] >>> 9),
|
|
2263
2266
|
q = (n[18] << 20) | (n[19] >>> 12),
|
|
@@ -2286,42 +2289,42 @@ function keccakPermutate(n) {
|
|
|
2286
2289
|
an = (n[41] << 18) | (n[40] >>> 14),
|
|
2287
2290
|
hn = (n[42] << 2) | (n[43] >>> 30),
|
|
2288
2291
|
pn = (n[43] << 2) | (n[42] >>> 30),
|
|
2289
|
-
|
|
2290
|
-
|
|
2292
|
+
mn = (n[45] << 29) | (n[44] >>> 3),
|
|
2293
|
+
dn = (n[44] << 29) | (n[45] >>> 3),
|
|
2291
2294
|
gn = (n[47] << 24) | (n[46] >>> 8),
|
|
2292
2295
|
yn = (n[46] << 24) | (n[47] >>> 8),
|
|
2293
2296
|
wn = (n[48] << 14) | (n[49] >>> 18),
|
|
2294
2297
|
xn = (n[49] << 14) | (n[48] >>> 18)
|
|
2295
|
-
;(n[0] = M ^ (~
|
|
2296
|
-
(n[1] = O ^ (~
|
|
2297
|
-
(n[2] =
|
|
2298
|
-
(n[3] =
|
|
2298
|
+
;(n[0] = M ^ (~B & K)),
|
|
2299
|
+
(n[1] = O ^ (~N & Z)),
|
|
2300
|
+
(n[2] = B ^ (~K & un)),
|
|
2301
|
+
(n[3] = N ^ (~Z & cn)),
|
|
2299
2302
|
(n[4] = K ^ (~un & wn)),
|
|
2300
2303
|
(n[5] = Z ^ (~cn & xn)),
|
|
2301
2304
|
(n[6] = un ^ (~wn & M)),
|
|
2302
2305
|
(n[7] = cn ^ (~xn & O)),
|
|
2303
|
-
(n[8] = wn ^ (~M &
|
|
2304
|
-
(n[9] = xn ^ (~O &
|
|
2306
|
+
(n[8] = wn ^ (~M & B)),
|
|
2307
|
+
(n[9] = xn ^ (~O & N)),
|
|
2305
2308
|
(n[10] = R ^ (~q & H)),
|
|
2306
2309
|
(n[11] = S ^ (~W & V)),
|
|
2307
2310
|
(n[12] = q ^ (~H & en)),
|
|
2308
2311
|
(n[13] = W ^ (~V & tn)),
|
|
2309
|
-
(n[14] = H ^ (~en &
|
|
2310
|
-
(n[15] = V ^ (~tn &
|
|
2311
|
-
(n[16] = en ^ (~
|
|
2312
|
-
(n[17] = tn ^ (~
|
|
2313
|
-
(n[18] =
|
|
2314
|
-
(n[19] =
|
|
2315
|
-
(n[20] = E ^ (~
|
|
2316
|
-
(n[21] = T ^ (~
|
|
2317
|
-
(n[22] =
|
|
2318
|
-
(n[23] =
|
|
2312
|
+
(n[14] = H ^ (~en & mn)),
|
|
2313
|
+
(n[15] = V ^ (~tn & dn)),
|
|
2314
|
+
(n[16] = en ^ (~mn & R)),
|
|
2315
|
+
(n[17] = tn ^ (~dn & S)),
|
|
2316
|
+
(n[18] = mn ^ (~R & q)),
|
|
2317
|
+
(n[19] = dn ^ (~S & W)),
|
|
2318
|
+
(n[20] = E ^ (~j & _)),
|
|
2319
|
+
(n[21] = T ^ (~U & Q)),
|
|
2320
|
+
(n[22] = j ^ (~_ & sn)),
|
|
2321
|
+
(n[23] = U ^ (~Q & fn)),
|
|
2319
2322
|
(n[24] = _ ^ (~sn & ln)),
|
|
2320
2323
|
(n[25] = Q ^ (~fn & an)),
|
|
2321
2324
|
(n[26] = sn ^ (~ln & E)),
|
|
2322
2325
|
(n[27] = fn ^ (~an & T)),
|
|
2323
|
-
(n[28] = ln ^ (~E &
|
|
2324
|
-
(n[29] = an ^ (~T &
|
|
2326
|
+
(n[28] = ln ^ (~E & j)),
|
|
2327
|
+
(n[29] = an ^ (~T & U)),
|
|
2325
2328
|
(n[30] = C ^ (~L & v)),
|
|
2326
2329
|
(n[31] = I ^ (~P & J)),
|
|
2327
2330
|
(n[32] = L ^ (~v & rn)),
|
|
@@ -2417,6 +2420,29 @@ function keccak256(n) {
|
|
|
2417
2420
|
function sha3_256(n) {
|
|
2418
2421
|
return squeeze(absorb(new Array(50).fill(0), divideToBlocks(n, 6)))
|
|
2419
2422
|
}
|
|
2423
|
+
function proximity(n, e, t) {
|
|
2424
|
+
const r = Math.min(n.length, e.length, t / 8 + 1)
|
|
2425
|
+
for (let o = 0; o < r; o++) {
|
|
2426
|
+
const i = n[o] ^ e[o]
|
|
2427
|
+
for (let u = 0; u < 8; u++) if ((i >> (7 - u)) & 1) return o * 8 + u
|
|
2428
|
+
}
|
|
2429
|
+
return t
|
|
2430
|
+
}
|
|
2431
|
+
function commonPrefix(n, e) {
|
|
2432
|
+
const t = Math.min(n.length, e.length)
|
|
2433
|
+
for (let r = 0; r < t; r++) if (n[r] !== e[r]) return n.subarray(0, r)
|
|
2434
|
+
return n.subarray(0, t)
|
|
2435
|
+
}
|
|
2436
|
+
function setBit(n, e, t) {
|
|
2437
|
+
const r = Math.floor(e / 8),
|
|
2438
|
+
o = e % 8
|
|
2439
|
+
t === 1 ? (n[r] |= 1 << (7 - o)) : (n[r] &= ~(1 << (7 - o)))
|
|
2440
|
+
}
|
|
2441
|
+
function getBit(n, e) {
|
|
2442
|
+
const t = Math.floor(e / 8),
|
|
2443
|
+
r = e % 8
|
|
2444
|
+
return (n[t] >> (7 - r)) & 1
|
|
2445
|
+
}
|
|
2420
2446
|
class Uint8ArrayReader {
|
|
2421
2447
|
constructor(e) {
|
|
2422
2448
|
;(this.cursor = 0), (this.buffer = e)
|
|
@@ -2771,7 +2797,11 @@ class AsyncQueue {
|
|
|
2771
2797
|
uint256ToNumber,
|
|
2772
2798
|
sliceBytes,
|
|
2773
2799
|
keccak256,
|
|
2774
|
-
sha3_256
|
|
2800
|
+
sha3_256,
|
|
2801
|
+
proximity,
|
|
2802
|
+
commonPrefix,
|
|
2803
|
+
setBit,
|
|
2804
|
+
getBit
|
|
2775
2805
|
}),
|
|
2776
2806
|
(exports.Random = {
|
|
2777
2807
|
intBetween,
|
|
@@ -2886,6 +2916,7 @@ class AsyncQueue {
|
|
|
2886
2916
|
seconds,
|
|
2887
2917
|
minutes,
|
|
2888
2918
|
hours,
|
|
2919
|
+
days,
|
|
2889
2920
|
make: makeDate,
|
|
2890
2921
|
normalizeTime,
|
|
2891
2922
|
absoluteDays
|