cafe-utility 33.2.0 → 33.3.1
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 +20 -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,22 @@ 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
|
+
if (parseFloat(n) === 0) return '0'
|
|
292
|
+
const [t, r] = n.split('.'),
|
|
293
|
+
o = t.replace('-', ''),
|
|
294
|
+
i = o.length
|
|
295
|
+
if (i >= e) return t
|
|
296
|
+
if (!(o === '0')) {
|
|
297
|
+
const f = e - i,
|
|
298
|
+
l = r.slice(0, f)
|
|
299
|
+
return /[1-9]/.test(l) ? `${t}.${l.replace(/0+$/, '')}` : t
|
|
300
|
+
}
|
|
301
|
+
const s = r.match(/^0*/)?.[0].length ?? 0,
|
|
302
|
+
c = e + s
|
|
303
|
+
return `${t}.${r.slice(0, c)}`
|
|
304
|
+
}
|
|
289
305
|
function isObject(n, e = !0) {
|
|
290
306
|
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
307
|
}
|
|
@@ -2100,8 +2116,8 @@ function keccakPermutate(n) {
|
|
|
2100
2116
|
R = (n[6] << 28) | (n[7] >>> 4),
|
|
2101
2117
|
I = (n[7] << 28) | (n[6] >>> 4),
|
|
2102
2118
|
C = (n[8] << 27) | (n[9] >>> 5),
|
|
2103
|
-
|
|
2104
|
-
|
|
2119
|
+
P = (n[9] << 27) | (n[8] >>> 5),
|
|
2120
|
+
D = (n[11] << 4) | (n[10] >>> 28),
|
|
2105
2121
|
B = (n[10] << 4) | (n[11] >>> 28),
|
|
2106
2122
|
v = (n[13] << 12) | (n[12] >>> 20),
|
|
2107
2123
|
U = (n[12] << 12) | (n[13] >>> 20),
|
|
@@ -2141,7 +2157,7 @@ function keccakPermutate(n) {
|
|
|
2141
2157
|
wn = (n[46] << 24) | (n[47] >>> 8),
|
|
2142
2158
|
xn = (n[48] << 14) | (n[49] >>> 18),
|
|
2143
2159
|
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 ^ (~
|
|
2160
|
+
;(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
2161
|
}
|
|
2146
2162
|
}
|
|
2147
2163
|
function bytesToNumbers(n) {
|
|
@@ -2753,7 +2769,7 @@ class RollingValueProvider {
|
|
|
2753
2769
|
(exports.Random = { intBetween, floatBetween, chance, signed: signedRandom, makeSeededRng, point: randomPoint, procs }),
|
|
2754
2770
|
(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
2771
|
(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 }),
|
|
2772
|
+
(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
2773
|
(exports.Promises = { raceFulfilled, invert: invertPromise, runInParallelBatches }),
|
|
2758
2774
|
(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
2775
|
(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 }),
|