cafe-utility 33.1.0 → 33.3.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 +25 -5
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -68,6 +68,7 @@ declare function formatDistance(meters: number): string
|
|
|
68
68
|
declare function triangularNumber(n: number): number
|
|
69
69
|
declare function searchFloat(string: string): number
|
|
70
70
|
declare function binomialSample(n: number, p: number, generator?: () => number): number
|
|
71
|
+
declare function toSignificantDigits(decimalString: string, significantDigits: number): string
|
|
71
72
|
declare function isObject(value: any, checkForPlainObject?: boolean): value is object
|
|
72
73
|
declare function isStrictlyObject(value: any): value is object
|
|
73
74
|
declare function isEmptyArray(value: any): boolean
|
|
@@ -359,6 +360,7 @@ declare function selectMax<T>(object: Record<string, T>, mapper: (item: T) => nu
|
|
|
359
360
|
declare function reposition(array: Record<string, unknown>[], key: string, current: number, delta: number): void
|
|
360
361
|
declare function unwrapSingleKey(object: Record<string, unknown>): unknown
|
|
361
362
|
declare function parseKeyValues(lines: string[], separator?: string): Record<string, string>
|
|
363
|
+
declare function errorMatches(error: unknown, expected: string): boolean
|
|
362
364
|
declare function buildUrl(baseUrl?: string | null, path?: string | null, query?: Record<string, any> | null): string
|
|
363
365
|
declare function parseCsv(string: string, delimiter?: string, quote?: string): string[]
|
|
364
366
|
declare function humanizeProgress(state: Progress): string
|
|
@@ -902,6 +904,7 @@ export declare const Numbers: {
|
|
|
902
904
|
triangularNumber: typeof triangularNumber
|
|
903
905
|
searchFloat: typeof searchFloat
|
|
904
906
|
binomialSample: typeof binomialSample
|
|
907
|
+
toSignificantDigits: typeof toSignificantDigits
|
|
905
908
|
}
|
|
906
909
|
export declare const Promises: {
|
|
907
910
|
raceFulfilled: typeof raceFulfilled
|
|
@@ -995,6 +998,7 @@ export declare const Objects: {
|
|
|
995
998
|
reposition: typeof reposition
|
|
996
999
|
unwrapSingleKey: typeof unwrapSingleKey
|
|
997
1000
|
parseKeyValues: typeof parseKeyValues
|
|
1001
|
+
errorMatches: typeof errorMatches
|
|
998
1002
|
}
|
|
999
1003
|
export declare const Types: {
|
|
1000
1004
|
isFunction: typeof isFunction
|
package/index.js
CHANGED
|
@@ -286,6 +286,21 @@ function binomialSample(n, e, t = Math.random) {
|
|
|
286
286
|
s = Math.round(r + o * u)
|
|
287
287
|
return Math.max(0, Math.min(n, s))
|
|
288
288
|
}
|
|
289
|
+
function toSignificantDigits(n, e) {
|
|
290
|
+
if (!n.includes('.')) return n
|
|
291
|
+
const [t, r] = n.split('.'),
|
|
292
|
+
o = t.replace('-', ''),
|
|
293
|
+
i = o.length
|
|
294
|
+
if (i >= e) return t
|
|
295
|
+
if (!(o === '0')) {
|
|
296
|
+
const f = e - i,
|
|
297
|
+
l = r.slice(0, f)
|
|
298
|
+
return /[1-9]/.test(l) ? `${t}.${l.replace(/0+$/, '')}` : t
|
|
299
|
+
}
|
|
300
|
+
const s = r.match(/^0*/)?.[0].length ?? 0,
|
|
301
|
+
c = e + s
|
|
302
|
+
return `${t}.${r.slice(0, c)}`
|
|
303
|
+
}
|
|
289
304
|
function isObject(n, e = !0) {
|
|
290
305
|
return !n || (e && !isUndefined(n._readableState)) || (e && n.constructor && (n.constructor.isBuffer || n.constructor.name == 'Uint8Array' || n.constructor.name === 'ArrayBuffer' || n.constructor.name === 'ReadableStream')) ? !1 : typeof n == 'object'
|
|
291
306
|
}
|
|
@@ -1281,6 +1296,11 @@ function parseKeyValues(n, e = ':') {
|
|
|
1281
1296
|
.filter(t => t)
|
|
1282
1297
|
)
|
|
1283
1298
|
}
|
|
1299
|
+
function errorMatches(n, e) {
|
|
1300
|
+
if (!n) return !1
|
|
1301
|
+
const t = n.message
|
|
1302
|
+
return typeof t == 'string' && t.includes(e)
|
|
1303
|
+
}
|
|
1284
1304
|
function buildUrl(n, e, t) {
|
|
1285
1305
|
return joinUrl([n, e]) + toQueryString(t || {})
|
|
1286
1306
|
}
|
|
@@ -2095,8 +2115,8 @@ function keccakPermutate(n) {
|
|
|
2095
2115
|
R = (n[6] << 28) | (n[7] >>> 4),
|
|
2096
2116
|
I = (n[7] << 28) | (n[6] >>> 4),
|
|
2097
2117
|
C = (n[8] << 27) | (n[9] >>> 5),
|
|
2098
|
-
|
|
2099
|
-
|
|
2118
|
+
P = (n[9] << 27) | (n[8] >>> 5),
|
|
2119
|
+
D = (n[11] << 4) | (n[10] >>> 28),
|
|
2100
2120
|
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2101
2121
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
2102
2122
|
U = (n[12] << 12) | (n[13] >>> 20),
|
|
@@ -2136,7 +2156,7 @@ function keccakPermutate(n) {
|
|
|
2136
2156
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2137
2157
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2138
2158
|
yn = (n[49] << 14) | (n[48] >>> 18)
|
|
2139
|
-
;(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 ^ (~F & q)), (n[11] = I ^ (~W & H)), (n[12] = F ^ (~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 & F)), (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 ^ (~
|
|
2159
|
+
;(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 ^ (~F & q)), (n[11] = I ^ (~W & H)), (n[12] = F ^ (~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 & F)), (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 ^ (~D & V)), (n[31] = P ^ (~B & J)), (n[32] = D ^ (~V & rn)), (n[33] = B ^ (~J & on)), (n[34] = V ^ (~rn & gn)), (n[35] = J ^ (~on & wn)), (n[36] = rn ^ (~gn & C)), (n[37] = on ^ (~wn & P)), (n[38] = gn ^ (~C & D)), (n[39] = wn ^ (~P & B)), (n[40] = T ^ (~j & Y)), (n[41] = S ^ (~z & _)), (n[42] = j ^ (~Y & X)), (n[43] = z ^ (~_ & 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 & z)), (n[0] ^= IOTA_CONSTANTS[e * 2]), (n[1] ^= IOTA_CONSTANTS[e * 2 + 1])
|
|
2140
2160
|
}
|
|
2141
2161
|
}
|
|
2142
2162
|
function bytesToNumbers(n) {
|
|
@@ -2748,10 +2768,10 @@ class RollingValueProvider {
|
|
|
2748
2768
|
(exports.Random = { intBetween, floatBetween, chance, signed: signedRandom, makeSeededRng, point: randomPoint, procs }),
|
|
2749
2769
|
(exports.Arrays = { countUnique, makeUnique, splitBySize, splitByCount, index: indexArray, indexCollection: indexArrayToCollection, onlyOrThrow, onlyOrNull, firstOrThrow, firstOrNull, shuffle, initialize: initializeArray, initialize2D: initialize2DArray, rotate2D: rotate2DArray, containsShape, glue, pluck, pick, pickMany, pickManyUnique, pickWeighted, pickRandomIndices, pickGuaranteed, last, pipe, makePipe, sortWeighted, pushAll, unshiftAll, filterAndRemove, merge: mergeArrays, empty, pushToBucket, unshiftAndLimit, atRolling, group, createOscillator, organiseWithLimits, tickPlaybook, getArgument, getBooleanArgument, getNumberArgument, requireStringArgument, requireNumberArgument, bringToFront, bringToFrontInPlace, findInstance, filterInstances, interleave, toggle, createHierarchy, multicall, maxBy }),
|
|
2750
2770
|
(exports.System = { sleepMillis, forever, scheduleMany, waitFor, expandError, runAndSetInterval, whereAmI, withRetries }),
|
|
2751
|
-
(exports.Numbers = { make: makeNumber, sum, average, median, getDistanceFromMidpoint, clamp, range, interpolate, createSequence, increment, decrement, format: formatNumber, fromDecimals, makeStorage, asMegabytes, convertBytes, hexToRgb, rgbToHex, haversineDistanceToMeters, roundToNearest, formatDistance, triangularNumber, searchFloat, binomialSample }),
|
|
2771
|
+
(exports.Numbers = { make: makeNumber, sum, average, median, getDistanceFromMidpoint, clamp, range, interpolate, createSequence, increment, decrement, format: formatNumber, fromDecimals, makeStorage, asMegabytes, convertBytes, hexToRgb, rgbToHex, haversineDistanceToMeters, roundToNearest, formatDistance, triangularNumber, searchFloat, binomialSample, toSignificantDigits }),
|
|
2752
2772
|
(exports.Promises = { raceFulfilled, invert: invertPromise, runInParallelBatches }),
|
|
2753
2773
|
(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 }),
|
|
2754
|
-
(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 }),
|
|
2774
|
+
(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, errorMatches }),
|
|
2755
2775
|
(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 }),
|
|
2756
2776
|
(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 }),
|
|
2757
2777
|
(exports.Assertions = { asEqual, asTrue, asTruthy, asFalse, asFalsy, asEither }),
|