cafe-utility 33.2.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 +2 -0
- package/index.js +19 -4
- 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
|
|
@@ -903,6 +904,7 @@ export declare const Numbers: {
|
|
|
903
904
|
triangularNumber: typeof triangularNumber
|
|
904
905
|
searchFloat: typeof searchFloat
|
|
905
906
|
binomialSample: typeof binomialSample
|
|
907
|
+
toSignificantDigits: typeof toSignificantDigits
|
|
906
908
|
}
|
|
907
909
|
export declare const Promises: {
|
|
908
910
|
raceFulfilled: typeof raceFulfilled
|
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
|
}
|
|
@@ -2100,8 +2115,8 @@ function keccakPermutate(n) {
|
|
|
2100
2115
|
R = (n[6] << 28) | (n[7] >>> 4),
|
|
2101
2116
|
I = (n[7] << 28) | (n[6] >>> 4),
|
|
2102
2117
|
C = (n[8] << 27) | (n[9] >>> 5),
|
|
2103
|
-
|
|
2104
|
-
|
|
2118
|
+
P = (n[9] << 27) | (n[8] >>> 5),
|
|
2119
|
+
D = (n[11] << 4) | (n[10] >>> 28),
|
|
2105
2120
|
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2106
2121
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
2107
2122
|
U = (n[12] << 12) | (n[13] >>> 20),
|
|
@@ -2141,7 +2156,7 @@ function keccakPermutate(n) {
|
|
|
2141
2156
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2142
2157
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2143
2158
|
yn = (n[49] << 14) | (n[48] >>> 18)
|
|
2144
|
-
;(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])
|
|
2145
2160
|
}
|
|
2146
2161
|
}
|
|
2147
2162
|
function bytesToNumbers(n) {
|
|
@@ -2753,7 +2768,7 @@ class RollingValueProvider {
|
|
|
2753
2768
|
(exports.Random = { intBetween, floatBetween, chance, signed: signedRandom, makeSeededRng, point: randomPoint, procs }),
|
|
2754
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 }),
|
|
2755
2770
|
(exports.System = { sleepMillis, forever, scheduleMany, waitFor, expandError, runAndSetInterval, whereAmI, withRetries }),
|
|
2756
|
-
(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 }),
|
|
2757
2772
|
(exports.Promises = { raceFulfilled, invert: invertPromise, runInParallelBatches }),
|
|
2758
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 }),
|
|
2759
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 }),
|