cafe-utility 30.0.1 → 31.1.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 +8 -1
- package/index.js +18 -9
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -210,6 +210,7 @@ declare function asUrl(
|
|
|
210
210
|
): string
|
|
211
211
|
declare function isNullable(typeFn: (value: any) => boolean, value: any): boolean
|
|
212
212
|
declare function asNullable<T>(typeFn: (value: any) => T, value: any): T | null
|
|
213
|
+
declare function asEmptiable<T>(typeFn: (value: any) => T, value: any): T | ''
|
|
213
214
|
declare function asOptional<T>(typeFn: (value: any) => T, value: any): T | undefined
|
|
214
215
|
declare function enforceObjectShape(value: Record<string, any>, shape: Record<string, (value: any) => boolean>): boolean
|
|
215
216
|
declare function enforceArrayShape(value: any[], shape: Record<string, (value: any) => boolean>): boolean
|
|
@@ -357,7 +358,12 @@ declare function parseKeyValues(lines: string[], separator?: string): Record<str
|
|
|
357
358
|
declare function buildUrl(baseUrl?: string | null, path?: string | null, query?: Record<string, any> | null): string
|
|
358
359
|
declare function parseCsv(string: string, delimiter?: string, quote?: string): string[]
|
|
359
360
|
declare function humanizeProgress(state: Progress): string
|
|
360
|
-
|
|
361
|
+
interface WaitOptions {
|
|
362
|
+
waitMillis: number
|
|
363
|
+
attempts: number
|
|
364
|
+
requiredConsecutivePasses?: number
|
|
365
|
+
}
|
|
366
|
+
declare function waitFor(predicate: () => Promise<boolean>, options: WaitOptions): Promise<void>
|
|
361
367
|
declare function filterAndRemove<T>(array: T[], predicate: (item: T) => boolean): T[]
|
|
362
368
|
declare function cloneWithJson<T>(a: T): T
|
|
363
369
|
declare function unixTimestamp(optionalTimestamp?: number): number
|
|
@@ -1011,6 +1017,7 @@ export declare const Types: {
|
|
|
1011
1017
|
asStringMap: typeof asStringMap
|
|
1012
1018
|
asNumericDictionary: typeof asNumericDictionary
|
|
1013
1019
|
asUrl: typeof asUrl
|
|
1020
|
+
asEmptiable: typeof asEmptiable
|
|
1014
1021
|
asNullable: typeof asNullable
|
|
1015
1022
|
asOptional: typeof asOptional
|
|
1016
1023
|
enforceObjectShape: typeof enforceObjectShape
|
package/index.js
CHANGED
|
@@ -464,6 +464,9 @@ function isNullable(n, e) {
|
|
|
464
464
|
function asNullable(n, e) {
|
|
465
465
|
return e == null ? null : n(e)
|
|
466
466
|
}
|
|
467
|
+
function asEmptiable(n, e) {
|
|
468
|
+
return e === '' ? '' : n(e)
|
|
469
|
+
}
|
|
467
470
|
function asOptional(n, e) {
|
|
468
471
|
return e == null ? void 0 : n(e)
|
|
469
472
|
}
|
|
@@ -1272,12 +1275,18 @@ function parseCsv(n, e = ',', t = '"') {
|
|
|
1272
1275
|
function humanizeProgress(n) {
|
|
1273
1276
|
return `[${Math.floor(n.progress * 100)}%] ${humanizeTime(n.deltaMs)} out of ${humanizeTime(n.totalTimeMs)} (${humanizeTime(n.remainingTimeMs)} left) [${Math.round(n.baseTimeMs)} ms each]`
|
|
1274
1277
|
}
|
|
1275
|
-
async function waitFor(n, e
|
|
1276
|
-
|
|
1278
|
+
async function waitFor(n, e) {
|
|
1279
|
+
let t = e.requiredConsecutivePasses || 1,
|
|
1280
|
+
r = 0
|
|
1281
|
+
for (let o = 0; o < e.attempts; o++) {
|
|
1277
1282
|
try {
|
|
1278
|
-
if (await n())
|
|
1279
|
-
|
|
1280
|
-
|
|
1283
|
+
if (await n()) {
|
|
1284
|
+
if ((r++, r >= t)) return
|
|
1285
|
+
} else r = 0
|
|
1286
|
+
} catch {
|
|
1287
|
+
r = 0
|
|
1288
|
+
}
|
|
1289
|
+
o < e.attempts - 1 && (await sleepMillis(e.waitMillis))
|
|
1281
1290
|
}
|
|
1282
1291
|
throw Error('Timed out waiting for predicate')
|
|
1283
1292
|
}
|
|
@@ -2058,8 +2067,8 @@ function keccakPermutate(n) {
|
|
|
2058
2067
|
S = (n[4] << 30) | (n[5] >>> 2),
|
|
2059
2068
|
R = (n[6] << 28) | (n[7] >>> 4),
|
|
2060
2069
|
I = (n[7] << 28) | (n[6] >>> 4),
|
|
2061
|
-
|
|
2062
|
-
|
|
2070
|
+
C = (n[8] << 27) | (n[9] >>> 5),
|
|
2071
|
+
D = (n[9] << 27) | (n[8] >>> 5),
|
|
2063
2072
|
B = (n[11] << 4) | (n[10] >>> 28),
|
|
2064
2073
|
P = (n[10] << 4) | (n[11] >>> 28),
|
|
2065
2074
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
@@ -2100,7 +2109,7 @@ function keccakPermutate(n) {
|
|
|
2100
2109
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2101
2110
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2102
2111
|
yn = (n[49] << 14) | (n[48] >>> 18)
|
|
2103
|
-
;(n[0] = E ^ (~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 & E)), (n[7] = cn ^ (~yn & M)), (n[8] = xn ^ (~E & v)), (n[9] = yn ^ (~M & U)), (n[10] = R ^ (~z & q)), (n[11] = I ^ (~W & H)), (n[12] = z ^ (~q & en)), (n[13] = W ^ (~H & tn)), (n[14] = q ^ (~en & pn)), (n[15] = H ^ (~tn & mn)), (n[16] = en ^ (~pn & R)), (n[17] = tn ^ (~mn & I)), (n[18] = pn ^ (~R & z)), (n[19] = mn ^ (~I & W)), (n[20] = O ^ (~L & Q)), (n[21] = k ^ (~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 & O)), (n[27] = fn ^ (~an & k)), (n[28] = ln ^ (~O & L)), (n[29] = an ^ (~k & N)), (n[30] =
|
|
2112
|
+
;(n[0] = E ^ (~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 & E)), (n[7] = cn ^ (~yn & M)), (n[8] = xn ^ (~E & v)), (n[9] = yn ^ (~M & U)), (n[10] = R ^ (~z & q)), (n[11] = I ^ (~W & H)), (n[12] = z ^ (~q & en)), (n[13] = W ^ (~H & tn)), (n[14] = q ^ (~en & pn)), (n[15] = H ^ (~tn & mn)), (n[16] = en ^ (~pn & R)), (n[17] = tn ^ (~mn & I)), (n[18] = pn ^ (~R & z)), (n[19] = mn ^ (~I & W)), (n[20] = O ^ (~L & Q)), (n[21] = k ^ (~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 & O)), (n[27] = fn ^ (~an & k)), (n[28] = ln ^ (~O & L)), (n[29] = an ^ (~k & N)), (n[30] = C ^ (~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 & C)), (n[37] = on ^ (~wn & D)), (n[38] = gn ^ (~C & B)), (n[39] = wn ^ (~D & P)), (n[40] = T ^ (~j & Y)), (n[41] = S ^ (~F & _)), (n[42] = j ^ (~Y & X)), (n[43] = F ^ (~_ & nn)), (n[44] = Y ^ (~X & hn)), (n[45] = _ ^ (~nn & dn)), (n[46] = X ^ (~hn & T)), (n[47] = nn ^ (~dn & S)), (n[48] = hn ^ (~T & j)), (n[49] = dn ^ (~S & F)), (n[0] ^= IOTA_CONSTANTS[e * 2]), (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
2104
2113
|
}
|
|
2105
2114
|
}
|
|
2106
2115
|
function bytesToNumbers(n) {
|
|
@@ -2704,7 +2713,7 @@ class TrieRouter {
|
|
|
2704
2713
|
(exports.Promises = { raceFulfilled, invert: invertPromise, runInParallelBatches }),
|
|
2705
2714
|
(exports.Dates = { getTimestamp, getTimeDelta, secondsToHumanTime, countCycles, isoDate, throttle, timeSince, dateTimeSlug, unixTimestamp, fromUtcString, fromMillis, getProgress, humanizeTime, humanizeProgress, createTimeDigits, mapDayNumber, getDayInfoFromDate, getDayInfoFromDateTimeString, seconds, minutes, hours, days, make: makeDate, normalizeTime, absoluteDays }),
|
|
2706
2715
|
(exports.Objects = { safeParse, deleteDeep, getDeep, setDeep, incrementDeep, ensureDeep, replaceDeep, getFirstDeep, deepMergeInPlace, deepMerge2, deepMerge3, mapAllAsync, cloneWithJson, sortObject, sortArray, sortAny, deepEquals, deepEqualsEvery, runOn, ifPresent, zip, zipSum, removeEmptyArrays, removeEmptyValues, flatten, unflatten, match, sort: sortObjectValues, map: mapObject, mapIterable, filterKeys: filterObjectKeys, filterValues: filterObjectValues, rethrow, setSomeOnObject, setSomeDeep, flip, getAllPermutations, countTruthyValues, transformToArray, setMulti, incrementMulti, createBidirectionalMap, createTemporalBidirectionalMap, pushToBidirectionalMap, unshiftToBidirectionalMap, addToTemporalBidirectionalMap, getFromTemporalBidirectionalMap, createStatefulToggle, diffKeys, pickRandomKey, mapRandomKey, fromObjectString, toQueryString, parseQueryString, hasKey, selectMax, reposition, unwrapSingleKey, parseKeyValues }),
|
|
2707
|
-
(exports.Types = { isFunction, isObject, isStrictlyObject, isEmptyArray, isEmptyObject, isUndefined, isString, isNumber, isBoolean, isDate, isBlank, isId, isIntegerString, isHexString, isUrl, isNullable, asString, asHexString, asSafeString, asIntegerString, asNumber, asFunction, asInteger, asBoolean, asDate, asNullableString, asEmptiableString, asId, asTime, asArray, asObject, asNullableObject, asStringMap, asNumericDictionary, asUrl, asNullable, asOptional, enforceObjectShape, enforceArrayShape, isPng, isJpg, isWebp, isImage }),
|
|
2716
|
+
(exports.Types = { isFunction, isObject, isStrictlyObject, isEmptyArray, isEmptyObject, isUndefined, isString, isNumber, isBoolean, isDate, isBlank, isId, isIntegerString, isHexString, isUrl, isNullable, asString, asHexString, asSafeString, asIntegerString, asNumber, asFunction, asInteger, asBoolean, asDate, asNullableString, asEmptiableString, asId, asTime, asArray, asObject, asNullableObject, asStringMap, asNumericDictionary, asUrl, asEmptiable, asNullable, asOptional, enforceObjectShape, enforceArrayShape, isPng, isJpg, isWebp, isImage }),
|
|
2708
2717
|
(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 }),
|
|
2709
2718
|
(exports.Assertions = { asEqual, asTrue, asTruthy, asFalse, asFalsy, asEither }),
|
|
2710
2719
|
(exports.Cache = { get: getCached, invalidate: invalidateCache }),
|