cafe-utility 33.10.0 → 33.11.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 +19 -1
- package/index.js +29 -11
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -466,7 +466,24 @@ declare function days(value: number): number
|
|
|
466
466
|
declare function makeDate(numberWithUnit: string): number
|
|
467
467
|
declare function makeStorage(numberWithUnit: string, conversionMultiplier?: number): number
|
|
468
468
|
declare function getPreLine(string: string): string
|
|
469
|
-
declare function getCached<T>(
|
|
469
|
+
declare function getCached<T>(
|
|
470
|
+
key: string,
|
|
471
|
+
ttlMillis: number,
|
|
472
|
+
handler: () => Promise<T>,
|
|
473
|
+
callbacks?: {
|
|
474
|
+
onMiss?: () => void
|
|
475
|
+
onFailure?: (err: unknown) => void
|
|
476
|
+
}
|
|
477
|
+
): Promise<T>
|
|
478
|
+
declare function getCachedDeferred<T>(
|
|
479
|
+
key: string,
|
|
480
|
+
ttlMillis: number,
|
|
481
|
+
handler: () => Promise<T>,
|
|
482
|
+
callbacks?: {
|
|
483
|
+
onMiss?: () => void
|
|
484
|
+
onFailure?: (err: unknown) => void
|
|
485
|
+
}
|
|
486
|
+
): Promise<T>
|
|
470
487
|
declare function deleteFromCache(key: string): void
|
|
471
488
|
declare function clearCache(): void
|
|
472
489
|
declare function deleteExpiredFromCache(): void
|
|
@@ -1204,6 +1221,7 @@ export declare const Assertions: {
|
|
|
1204
1221
|
}
|
|
1205
1222
|
export declare const Cache: {
|
|
1206
1223
|
get: typeof getCached
|
|
1224
|
+
getDeferred: typeof getCachedDeferred
|
|
1207
1225
|
delete: typeof deleteFromCache
|
|
1208
1226
|
deleteExpired: typeof deleteExpiredFromCache
|
|
1209
1227
|
size: typeof cacheSize
|
package/index.js
CHANGED
|
@@ -1478,13 +1478,31 @@ function getPreLine(n) {
|
|
|
1478
1478
|
return n.replace(/ +/g, ' ').replace(/^ /gm, '')
|
|
1479
1479
|
}
|
|
1480
1480
|
const tinyCache = new Map()
|
|
1481
|
-
async function getCached(n, e, t) {
|
|
1482
|
-
const
|
|
1483
|
-
|
|
1484
|
-
if (
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1481
|
+
async function getCached(n, e, t, r) {
|
|
1482
|
+
const i = Date.now(),
|
|
1483
|
+
o = tinyCache.get(n)
|
|
1484
|
+
if (o && o.validUntil > i) return o.value
|
|
1485
|
+
r?.onMiss?.()
|
|
1486
|
+
try {
|
|
1487
|
+
const u = await t()
|
|
1488
|
+
return tinyCache.set(n, { value: u, validUntil: i + e }), u
|
|
1489
|
+
} catch (u) {
|
|
1490
|
+
throw (r?.onFailure?.(u), u)
|
|
1491
|
+
}
|
|
1492
|
+
}
|
|
1493
|
+
function getCachedDeferred(n, e, t, r) {
|
|
1494
|
+
const i = Date.now(),
|
|
1495
|
+
o = tinyCache.get(n)
|
|
1496
|
+
if (o && o.validUntil > i) return o.value
|
|
1497
|
+
r?.onMiss?.()
|
|
1498
|
+
const u = t()
|
|
1499
|
+
return (
|
|
1500
|
+
tinyCache.set(n, { value: u, validUntil: i + e }),
|
|
1501
|
+
u.catch(s => {
|
|
1502
|
+
tinyCache.delete(n), r?.onFailure?.(s)
|
|
1503
|
+
}),
|
|
1504
|
+
u
|
|
1505
|
+
)
|
|
1488
1506
|
}
|
|
1489
1507
|
function deleteFromCache(n) {
|
|
1490
1508
|
tinyCache.delete(n)
|
|
@@ -2143,8 +2161,8 @@ function keccakPermutate(n) {
|
|
|
2143
2161
|
B = (n[11] << 4) | (n[10] >>> 28),
|
|
2144
2162
|
P = (n[10] << 4) | (n[11] >>> 28),
|
|
2145
2163
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
2146
|
-
|
|
2147
|
-
|
|
2164
|
+
U = (n[12] << 12) | (n[13] >>> 20),
|
|
2165
|
+
L = (n[14] << 6) | (n[15] >>> 26),
|
|
2148
2166
|
N = (n[15] << 6) | (n[14] >>> 26),
|
|
2149
2167
|
j = (n[17] << 23) | (n[16] >>> 9),
|
|
2150
2168
|
F = (n[16] << 23) | (n[17] >>> 9),
|
|
@@ -2180,7 +2198,7 @@ function keccakPermutate(n) {
|
|
|
2180
2198
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2181
2199
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2182
2200
|
yn = (n[49] << 14) | (n[48] >>> 18)
|
|
2183
|
-
;(n[0] = A ^ (~v & K)), (n[1] = M ^ (~
|
|
2201
|
+
;(n[0] = A ^ (~v & K)), (n[1] = M ^ (~U & Z)), (n[2] = v ^ (~K & un)), (n[3] = U ^ (~Z & cn)), (n[4] = K ^ (~un & xn)), (n[5] = Z ^ (~cn & yn)), (n[6] = un ^ (~xn & A)), (n[7] = cn ^ (~yn & M)), (n[8] = xn ^ (~A & v)), (n[9] = yn ^ (~M & U)), (n[10] = C ^ (~z & W)), (n[11] = R ^ (~q & H)), (n[12] = z ^ (~W & en)), (n[13] = q ^ (~H & tn)), (n[14] = W ^ (~en & pn)), (n[15] = H ^ (~tn & mn)), (n[16] = en ^ (~pn & C)), (n[17] = tn ^ (~mn & R)), (n[18] = pn ^ (~C & z)), (n[19] = mn ^ (~R & q)), (n[20] = k ^ (~L & Q)), (n[21] = S ^ (~N & G)), (n[22] = L ^ (~Q & sn)), (n[23] = N ^ (~G & fn)), (n[24] = Q ^ (~sn & ln)), (n[25] = G ^ (~fn & an)), (n[26] = sn ^ (~ln & k)), (n[27] = fn ^ (~an & S)), (n[28] = ln ^ (~k & L)), (n[29] = an ^ (~S & N)), (n[30] = I ^ (~B & V)), (n[31] = D ^ (~P & J)), (n[32] = B ^ (~V & rn)), (n[33] = P ^ (~J & on)), (n[34] = V ^ (~rn & gn)), (n[35] = J ^ (~on & wn)), (n[36] = rn ^ (~gn & I)), (n[37] = on ^ (~wn & D)), (n[38] = gn ^ (~I & B)), (n[39] = wn ^ (~D & P)), (n[40] = O ^ (~j & Y)), (n[41] = T ^ (~F & X)), (n[42] = j ^ (~Y & _)), (n[43] = F ^ (~X & nn)), (n[44] = Y ^ (~_ & hn)), (n[45] = X ^ (~nn & dn)), (n[46] = _ ^ (~hn & O)), (n[47] = nn ^ (~dn & T)), (n[48] = hn ^ (~O & j)), (n[49] = dn ^ (~T & F)), (n[0] ^= IOTA_CONSTANTS[e * 2]), (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
2184
2202
|
}
|
|
2185
2203
|
}
|
|
2186
2204
|
function bytesToNumbers(n) {
|
|
@@ -2874,5 +2892,5 @@ class Lock {
|
|
|
2874
2892
|
(exports.Types = { isFunction, isObject, isStrictlyObject, isEmptyArray, isEmptyObject, isUndefined, isString, isNumber, isBoolean, isDate, isBlank, isId, isIntegerString, isHexString, isUrl, isBigint, isNullable, asString, asHexString, asSafeString, asIntegerString, asNumber, asFunction, asInteger, asBoolean, asDate, asNullableString, asEmptiableString, asId, asTime, asArray, asObject, asNullableObject, asStringMap, asNumericDictionary, asUrl, asBigint, asEmptiable, asNullable, asOptional, enforceObjectShape, enforceArrayShape, isPng, isJpg, isWebp, isImage }),
|
|
2875
2893
|
(exports.Strings = { tokenizeByCount, tokenizeByLength, searchHex, searchSubstring, randomHex: randomHexString, randomLetter: randomLetterString, randomAlphanumeric: randomAlphanumericString, randomRichAscii: randomRichAsciiString, randomUnicode: randomUnicodeString, includesAny, slugify, normalForm, enumify, escapeHtml, decodeHtmlEntities, after, afterLast, before, beforeLast, betweenWide, betweenNarrow, getPreLine, containsWord, containsWords, joinUrl, getFuzzyMatchScore, sortByFuzzyScore, splitOnce, splitAll, randomize, expand, shrinkTrim, capitalize, decapitalize, csvEscape, parseCsv, surroundInOut, getExtension, getBasename, normalizeEmail, normalizeFilename, parseFilename, camelToTitle, slugToTitle, slugToCamel, joinHumanly, findWeightedPair, extractBlock, extractAllBlocks, replaceBlocks, indexOfEarliest, lastIndexOfBefore, parseHtmlAttributes, readNextWord, readWordsAfterAll, resolveVariables, resolveVariableWithDefaultSyntax, resolveRemainingVariablesWithDefaults, isLetter, isDigit, isLetterOrDigit, isValidObjectPathCharacter, insert: insertString, indexOfRegex, allIndexOf, lineMatches, linesMatchInOrder, represent, resolveMarkdownLinks, buildUrl, isChinese, replaceBetweenStrings, describeMarkdown, isBalanced, textToFormat, splitFormatting, splitHashtags, splitUrls, route, explodeReplace, generateVariants, replaceWord, replacePascalCaseWords, stripHtml, breakLine, measureTextWidth, toLines, levenshteinDistance, findCommonPrefix, findCommonDirectory }),
|
|
2876
2894
|
(exports.Assertions = { asEqual, asTrue, asTruthy, asFalse, asFalsy, asEither }),
|
|
2877
|
-
(exports.Cache = { get: getCached, delete: deleteFromCache, deleteExpired: deleteExpiredFromCache, size: cacheSize, clear: clearCache }),
|
|
2895
|
+
(exports.Cache = { get: getCached, getDeferred: getCachedDeferred, delete: deleteFromCache, deleteExpired: deleteExpiredFromCache, size: cacheSize, clear: clearCache }),
|
|
2878
2896
|
(exports.Vector = { addPoint, subtractPoint, multiplyPoint, normalizePoint, pushPoint, filterCoordinates, findCorners, findLines, raycast, raycastCircle, getLineIntersectionPoint })
|