cafe-utility 21.3.1 → 21.5.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 +12 -0
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -210,6 +210,7 @@ declare function breakLine(string: string): {
|
|
|
210
210
|
line: string;
|
|
211
211
|
rest: string;
|
|
212
212
|
};
|
|
213
|
+
declare function measureTextWidth(string: string, characterWidths?: Record<string, number>): number;
|
|
213
214
|
declare function toLines(string: string, maxWidth: number, characterWidths?: Record<string, number>): string[];
|
|
214
215
|
declare function levenshteinDistance(a: string, b: string): number;
|
|
215
216
|
declare function containsWord(string: string, word: string): boolean;
|
|
@@ -341,6 +342,7 @@ declare function diffKeys(objectA: CafeObject, objectB: CafeObject): {
|
|
|
341
342
|
declare function pickRandomKey(object: CafeObject): string;
|
|
342
343
|
declare function mapRandomKey<T>(object: CafeObject<T>, mapFunction: (value: T) => T): string;
|
|
343
344
|
declare function fromObjectString<T>(string: string): T;
|
|
345
|
+
declare function fromDecimals(number: string, decimals: number, unit?: string): string;
|
|
344
346
|
interface NumberFormatOptions {
|
|
345
347
|
precision?: number;
|
|
346
348
|
longForm?: boolean;
|
|
@@ -594,6 +596,7 @@ export declare const Numbers: {
|
|
|
594
596
|
increment: typeof increment;
|
|
595
597
|
decrement: typeof decrement;
|
|
596
598
|
format: typeof formatNumber;
|
|
599
|
+
fromDecimals: typeof fromDecimals;
|
|
597
600
|
asMegabytes: typeof asMegabytes;
|
|
598
601
|
convertBytes: typeof convertBytes;
|
|
599
602
|
hexToRgb: typeof hexToRgb;
|
|
@@ -814,6 +817,7 @@ export declare const Strings: {
|
|
|
814
817
|
replacePascalCaseWords: typeof replacePascalCaseWords;
|
|
815
818
|
stripHtml: typeof stripHtml;
|
|
816
819
|
breakLine: typeof breakLine;
|
|
820
|
+
measureTextWidth: typeof measureTextWidth;
|
|
817
821
|
toLines: typeof toLines;
|
|
818
822
|
levenshteinDistance: typeof levenshteinDistance;
|
|
819
823
|
};
|
package/index.js
CHANGED
|
@@ -1090,6 +1090,9 @@ function breakLine(n) {
|
|
|
1090
1090
|
r = n.slice(t + 1)
|
|
1091
1091
|
return { line: e, rest: r }
|
|
1092
1092
|
}
|
|
1093
|
+
function measureTextWidth(n, t = {}) {
|
|
1094
|
+
return [...n].reduce((e, r) => e + (t[r] || 1), 0)
|
|
1095
|
+
}
|
|
1093
1096
|
function toLines(n, t, e = {}) {
|
|
1094
1097
|
const r = []
|
|
1095
1098
|
let o = '',
|
|
@@ -1591,6 +1594,13 @@ const thresholds = [1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24, 1e27, 1e30, 1e9
|
|
|
1591
1594
|
'decillion'
|
|
1592
1595
|
],
|
|
1593
1596
|
shortNumberUnits = ['K', 'M', 'B', 'T', 'Qa', 'Qi', 'Sx', 'Sp', 'O', 'N', 'gwei', 'bzz', 'eth', 'btc', 'dai', 'D']
|
|
1597
|
+
function fromDecimals(n, t, e) {
|
|
1598
|
+
let r = n.length - t
|
|
1599
|
+
if (r <= 0) return '0.' + '0'.repeat(-r) + n + (e ? ' ' + e : '')
|
|
1600
|
+
let o = n.substring(0, r),
|
|
1601
|
+
i = n.substring(r)
|
|
1602
|
+
return o === '' && (o = '0'), o + '.' + i + (e ? ' ' + e : '')
|
|
1603
|
+
}
|
|
1594
1604
|
function formatNumber(n, t) {
|
|
1595
1605
|
var e, r
|
|
1596
1606
|
const o = (e = t?.longForm) !== null && e !== void 0 ? e : !1,
|
|
@@ -2379,6 +2389,7 @@ function raycastCircle(n, t, e) {
|
|
|
2379
2389
|
increment,
|
|
2380
2390
|
decrement,
|
|
2381
2391
|
format: formatNumber,
|
|
2392
|
+
fromDecimals,
|
|
2382
2393
|
asMegabytes,
|
|
2383
2394
|
convertBytes,
|
|
2384
2395
|
hexToRgb,
|
|
@@ -2594,6 +2605,7 @@ function raycastCircle(n, t, e) {
|
|
|
2594
2605
|
replacePascalCaseWords,
|
|
2595
2606
|
stripHtml,
|
|
2596
2607
|
breakLine,
|
|
2608
|
+
measureTextWidth,
|
|
2597
2609
|
toLines,
|
|
2598
2610
|
levenshteinDistance
|
|
2599
2611
|
}),
|