@cranberry-money/shared-utils 8.17.36 → 8.17.38
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/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/instruments.d.ts +1 -49
- package/dist/instruments.d.ts.map +1 -1
- package/dist/instruments.js +1 -100
- package/dist/numbers.d.ts +1 -56
- package/dist/numbers.d.ts.map +1 -1
- package/dist/numbers.js +0 -74
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -14,10 +14,10 @@ export { calculateLiquidationProgress, getTotalEstimatedValue, } from './withdra
|
|
|
14
14
|
export { isNumericOnly, validatePassword, isValidTokenFormat, formatVerificationToken, validateEmailConfirmation, isValidEmail, hasUppercase, hasLowercase, hasSpecialCharacter, hasDigit, validatePasswordExtended, isValidPhoneNumber, isValidPhoneFormat, isValidUrl, isValidDate, isEmptyOrWhitespace, meetsMinLength, meetsMaxLength, isInRange, isPositiveNumber, isNonNegativeNumber, isValidFullName, isValidDateOfBirth, formatPhoneNumber, isValidInvestmentAmount, isValidSourceOfFunds, hasMinimumSelection, isSelected, validatePercentageSum, validateAllocationSum, isInNumberRange, isValidPercentage, } from './validation';
|
|
15
15
|
export { hasActiveFilters, countActiveFilters, clearAllFilters, updateFilters, isFilterEmpty, removeEmptyFilters, mergeFilters, areFiltersEqual, createFilterPredicate, hasActiveInstrumentFilters, countActiveInstrumentFilters, hasActiveTradeFilters, countActiveTradeFilters, hasActiveTransactionFilters, countActiveTransactionFilters, hasActiveTargetTradeFilters, countActiveTargetTradeFilters, } from './filters';
|
|
16
16
|
export { isTokenExpired, isTokenExpiringSoon, getTimeUntilExpiry, formatTimeUntilExpiry, parseDeviceInfo, isRefreshSuccess, getRefreshErrorMessage, createAutoRefreshHandler, } from './auth';
|
|
17
|
-
export { formatInstrumentPrice, getCurrencySymbol,
|
|
17
|
+
export { formatInstrumentPrice, getCurrencySymbol, } from './instruments';
|
|
18
18
|
export { sortByStringField, filterByTextSearch, filterByBooleanField, findByField, findByStringField, extractAndSortField, groupByFirstLetter, groupByField, hasItemWithFieldValue, countByFieldValue, } from './collections';
|
|
19
19
|
export { downloadBlob, downloadTextFile, downloadJsonFile, generateTimestampedFilename, downloadDataUrl, downloadCsvFile, } from './downloads';
|
|
20
|
-
export { formatQuantityWithSuffix,
|
|
20
|
+
export { formatQuantityWithSuffix, } from './numbers';
|
|
21
21
|
export { validateAllocations } from './allocations';
|
|
22
22
|
export { calculatePortfolioValue, calculateHoldingAllocations, groupHoldingsByInstrument, filterHoldingsByMinQuantity, sortHoldings, } from './holdings';
|
|
23
23
|
export { processAllocationData, calculateTotals, formatPercentage, formatDashboardCurrency, type AllocationDisplayItem, } from './dashboard';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,GACb,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGnE,OAAO,EACL,mBAAmB,EACnB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,GAC1B,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhH,OAAO,EACL,4BAA4B,EAC5B,sBAAsB,GACvB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,aAAa,EACb,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,EACvB,yBAAyB,EACzB,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,EAClB,UAAU,EACV,WAAW,EACX,mBAAmB,EACnB,cAAc,EACd,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,uBAAuB,EACvB,oBAAoB,EACpB,mBAAmB,EACnB,UAAU,EAEV,qBAAqB,EACrB,qBAAqB,EACrB,eAAe,EACf,iBAAiB,GAClB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,eAAe,EACf,aAAa,EACb,aAAa,EACb,kBAAkB,EAClB,YAAY,EACZ,eAAe,EACf,qBAAqB,EAErB,0BAA0B,EAC1B,4BAA4B,EAC5B,qBAAqB,EACrB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC7B,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,wBAAwB,GACzB,MAAM,QAAQ,CAAC;AAGhB,OAAO,EACL,qBAAqB,EACrB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EACL,8BAA8B,EAC9B,qCAAqC,EACrC,cAAc,EACd,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,E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ACtB,KAAK,aAAa,GACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,iBAAiB,EACjB,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,0BAA0B,EAC1B,YAAY,EACZ,wBAAwB,EACxB,KAAK,UAAU,GAChB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,wBAAwB,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGhG,OAAO,EACL,oBAAoB,EACpB,sBAAsB,EACtB,wBAAwB,EACxB,kBAAkB,EAClB,gBAAgB,EAChB,uBAAuB,EACvB,6BAA6B,EAC7B,0BAA0B,EAC1B,uBAAuB,EACvB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,YAAY,GAClB,MAAM,YAAY,CAAC;AAGpB,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,wBAAwB,EACxB,iBAAiB,EACjB,iBAAiB,EACjB,eAAe,EACf,4BAA4B,EAC5B,yBAAyB,EACzB,kBAAkB,EAClB,KAAK,WAAW,IAAI,eAAe,GACpC,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,wBAAwB,EACxB,6BAA6B,EAC7B,sBAAsB,EACtB,KAAK,cAAc,GACpB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,wBAAwB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAG3F,OAAO,EACL,aAAa,EACb,uBAAuB,EACvB,uBAAuB,EACvB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -29,13 +29,13 @@ hasActiveInstrumentFilters, countActiveInstrumentFilters, hasActiveTradeFilters,
|
|
|
29
29
|
// Authentication utilities
|
|
30
30
|
export { isTokenExpired, isTokenExpiringSoon, getTimeUntilExpiry, formatTimeUntilExpiry, parseDeviceInfo, isRefreshSuccess, getRefreshErrorMessage, createAutoRefreshHandler, } from './auth';
|
|
31
31
|
// Instrument utilities
|
|
32
|
-
export { formatInstrumentPrice, getCurrencySymbol,
|
|
32
|
+
export { formatInstrumentPrice, getCurrencySymbol, } from './instruments';
|
|
33
33
|
// Collection utilities
|
|
34
34
|
export { sortByStringField, filterByTextSearch, filterByBooleanField, findByField, findByStringField, extractAndSortField, groupByFirstLetter, groupByField, hasItemWithFieldValue, countByFieldValue, } from './collections';
|
|
35
35
|
// Download utilities
|
|
36
36
|
export { downloadBlob, downloadTextFile, downloadJsonFile, generateTimestampedFilename, downloadDataUrl, downloadCsvFile, } from './downloads';
|
|
37
37
|
// Number formatting utilities
|
|
38
|
-
export { formatQuantityWithSuffix,
|
|
38
|
+
export { formatQuantityWithSuffix, } from './numbers';
|
|
39
39
|
// Allocation utilities
|
|
40
40
|
export { validateAllocations } from './allocations';
|
|
41
41
|
// Holdings utilities
|
package/dist/instruments.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Instrument and market data formatting utilities
|
|
3
3
|
*/
|
|
4
|
-
import type { InstrumentTypeInfo, InstrumentBasicInfo, PriceChangeResult, PriceSnapshot, FormattedPriceChange, TradeableInstrument, MarketDataInfo } from '@cranberry-money/shared-types';
|
|
5
4
|
/**
|
|
6
5
|
* Format instrument price with currency symbol
|
|
7
6
|
* @param price - The price as string
|
|
@@ -15,51 +14,4 @@ export declare function formatInstrumentPrice(price: string, currency?: string |
|
|
|
15
14
|
* @returns Currency symbol
|
|
16
15
|
*/
|
|
17
16
|
export declare function getCurrencySymbol(currency?: string | null): string;
|
|
18
|
-
|
|
19
|
-
* Determine instrument type based on flags
|
|
20
|
-
* @param instrument - The instrument with type flags
|
|
21
|
-
* @returns Instrument type string
|
|
22
|
-
*/
|
|
23
|
-
export declare function getInstrumentType(instrument: InstrumentTypeInfo): string;
|
|
24
|
-
/**
|
|
25
|
-
* Format instrument display name with symbol
|
|
26
|
-
* @param instrument - The instrument with symbol and name
|
|
27
|
-
* @returns Formatted display name
|
|
28
|
-
*/
|
|
29
|
-
export declare function formatInstrumentName(instrument: InstrumentBasicInfo): string;
|
|
30
|
-
/**
|
|
31
|
-
* Calculate price change from snapshot
|
|
32
|
-
* @param snapshot - The price snapshot
|
|
33
|
-
* @returns Price change calculation result
|
|
34
|
-
*/
|
|
35
|
-
export declare function calculatePriceChange(snapshot: PriceSnapshot): PriceChangeResult;
|
|
36
|
-
/**
|
|
37
|
-
* Format price change with appropriate color class
|
|
38
|
-
* @param snapshot - The price snapshot
|
|
39
|
-
* @returns Formatted price change with color class
|
|
40
|
-
*/
|
|
41
|
-
export declare function formatPriceChange(snapshot: PriceSnapshot): FormattedPriceChange;
|
|
42
|
-
/**
|
|
43
|
-
* Check if instrument is actively tradeable
|
|
44
|
-
* @param instrument - The instrument with trading flags
|
|
45
|
-
* @returns true if tradeable, false otherwise
|
|
46
|
-
*/
|
|
47
|
-
export declare function isInstrumentTradeable(instrument: TradeableInstrument): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Format market cap value
|
|
50
|
-
* @param marketCap - The market cap value as string or null
|
|
51
|
-
* @returns Formatted market cap string
|
|
52
|
-
*/
|
|
53
|
-
export declare function formatMarketCap(marketCap: string | null | undefined): string;
|
|
54
|
-
/**
|
|
55
|
-
* Format trading volume
|
|
56
|
-
* @param volume - The volume number
|
|
57
|
-
* @returns Formatted volume string
|
|
58
|
-
*/
|
|
59
|
-
export declare function formatVolume(volume: number): string;
|
|
60
|
-
/**
|
|
61
|
-
* Check if market data is available
|
|
62
|
-
* @param marketData - The market data to check
|
|
63
|
-
* @returns true if market data is available, false otherwise
|
|
64
|
-
*/
|
|
65
|
-
export declare function hasMarketData(marketData: MarketDataInfo): boolean;
|
|
17
|
+
//# sourceMappingURL=instruments.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instruments.d.ts","sourceRoot":"","sources":["../src/instruments.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"instruments.d.ts","sourceRoot":"","sources":["../src/instruments.ts"],"names":[],"mappings":"AAAA;;GAEG;AAOH;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAMrF;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,MAAM,CAalE"}
|
package/dist/instruments.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Instrument and market data formatting utilities
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { CURRENCY_USD, CURRENCY_AUD, } from '@cranberry-money/shared-constants';
|
|
5
5
|
/**
|
|
6
6
|
* Format instrument price with currency symbol
|
|
7
7
|
* @param price - The price as string
|
|
@@ -34,102 +34,3 @@ export function getCurrencySymbol(currency) {
|
|
|
34
34
|
return '$'; // Default to USD symbol
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
/**
|
|
38
|
-
* Determine instrument type based on flags
|
|
39
|
-
* @param instrument - The instrument with type flags
|
|
40
|
-
* @returns Instrument type string
|
|
41
|
-
*/
|
|
42
|
-
export function getInstrumentType(instrument) {
|
|
43
|
-
if (instrument.isEtf)
|
|
44
|
-
return INSTRUMENT_TYPE_ETF;
|
|
45
|
-
if (instrument.isFund)
|
|
46
|
-
return INSTRUMENT_TYPE_FUND;
|
|
47
|
-
return INSTRUMENT_TYPE_STOCK;
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* Format instrument display name with symbol
|
|
51
|
-
* @param instrument - The instrument with symbol and name
|
|
52
|
-
* @returns Formatted display name
|
|
53
|
-
*/
|
|
54
|
-
export function formatInstrumentName(instrument) {
|
|
55
|
-
return `${instrument.symbol} - ${instrument.name}`;
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Calculate price change from snapshot
|
|
59
|
-
* @param snapshot - The price snapshot
|
|
60
|
-
* @returns Price change calculation result
|
|
61
|
-
*/
|
|
62
|
-
export function calculatePriceChange(snapshot) {
|
|
63
|
-
const change = parseFloat(snapshot.change);
|
|
64
|
-
const changePercent = parseFloat(snapshot.changePercent);
|
|
65
|
-
return {
|
|
66
|
-
change,
|
|
67
|
-
changePercent,
|
|
68
|
-
isPositive: change >= 0,
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Format price change with appropriate color class
|
|
73
|
-
* @param snapshot - The price snapshot
|
|
74
|
-
* @returns Formatted price change with color class
|
|
75
|
-
*/
|
|
76
|
-
export function formatPriceChange(snapshot) {
|
|
77
|
-
const { change, changePercent, isPositive } = calculatePriceChange(snapshot);
|
|
78
|
-
const changeText = `${isPositive ? '+' : ''}${change.toFixed(2)}`;
|
|
79
|
-
const changePercentText = `${isPositive ? '+' : ''}${changePercent.toFixed(2)}%`;
|
|
80
|
-
const colorClass = isPositive ? 'text-positive' : 'text-negative';
|
|
81
|
-
return {
|
|
82
|
-
changeText,
|
|
83
|
-
changePercentText,
|
|
84
|
-
colorClass,
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* Check if instrument is actively tradeable
|
|
89
|
-
* @param instrument - The instrument with trading flags
|
|
90
|
-
* @returns true if tradeable, false otherwise
|
|
91
|
-
*/
|
|
92
|
-
export function isInstrumentTradeable(instrument) {
|
|
93
|
-
return instrument.isActive && instrument.isActivelyTrading;
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Format market cap value
|
|
97
|
-
* @param marketCap - The market cap value as string or null
|
|
98
|
-
* @returns Formatted market cap string
|
|
99
|
-
*/
|
|
100
|
-
export function formatMarketCap(marketCap) {
|
|
101
|
-
if (!marketCap)
|
|
102
|
-
return 'N/A';
|
|
103
|
-
const marketCapValue = parseFloat(marketCap);
|
|
104
|
-
if (isNaN(marketCapValue))
|
|
105
|
-
return 'N/A';
|
|
106
|
-
if (marketCapValue >= 1e12)
|
|
107
|
-
return `$${(marketCapValue / 1e12).toFixed(1)}T`;
|
|
108
|
-
if (marketCapValue >= 1e9)
|
|
109
|
-
return `$${(marketCapValue / 1e9).toFixed(1)}B`;
|
|
110
|
-
if (marketCapValue >= 1e6)
|
|
111
|
-
return `$${(marketCapValue / 1e6).toFixed(1)}M`;
|
|
112
|
-
return `$${marketCapValue.toFixed(0)}`;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Format trading volume
|
|
116
|
-
* @param volume - The volume number
|
|
117
|
-
* @returns Formatted volume string
|
|
118
|
-
*/
|
|
119
|
-
export function formatVolume(volume) {
|
|
120
|
-
if (volume >= 1e9)
|
|
121
|
-
return `${(volume / 1e9).toFixed(1)}B`;
|
|
122
|
-
if (volume >= 1e6)
|
|
123
|
-
return `${(volume / 1e6).toFixed(1)}M`;
|
|
124
|
-
if (volume >= 1e3)
|
|
125
|
-
return `${(volume / 1e3).toFixed(1)}K`;
|
|
126
|
-
return volume.toString();
|
|
127
|
-
}
|
|
128
|
-
/**
|
|
129
|
-
* Check if market data is available
|
|
130
|
-
* @param marketData - The market data to check
|
|
131
|
-
* @returns true if market data is available, false otherwise
|
|
132
|
-
*/
|
|
133
|
-
export function hasMarketData(marketData) {
|
|
134
|
-
return Boolean(marketData.openPrice || marketData.dayHigh || marketData.dayLow || marketData.volume);
|
|
135
|
-
}
|
package/dist/numbers.d.ts
CHANGED
|
@@ -13,59 +13,4 @@
|
|
|
13
13
|
* formatQuantityWithSuffix(999) // '999'
|
|
14
14
|
*/
|
|
15
15
|
export declare function formatQuantityWithSuffix(quantity: number, decimals?: number): string;
|
|
16
|
-
|
|
17
|
-
* Format a large number with customizable suffixes
|
|
18
|
-
* @param num - The number to format
|
|
19
|
-
* @param suffixes - Array of suffix configurations (default: standard K, M, B, T)
|
|
20
|
-
* @param decimals - Number of decimal places (default: 1)
|
|
21
|
-
* @returns Formatted number string with suffix
|
|
22
|
-
* @example
|
|
23
|
-
* formatLargeNumber(1500000) // '1.5M'
|
|
24
|
-
* formatLargeNumber(1500000000) // '1.5B'
|
|
25
|
-
*/
|
|
26
|
-
export declare function formatLargeNumber(num: number, suffixes?: Array<{
|
|
27
|
-
threshold: number;
|
|
28
|
-
suffix: string;
|
|
29
|
-
}>, decimals?: number): string;
|
|
30
|
-
/**
|
|
31
|
-
* Format a number as a percentage
|
|
32
|
-
* @param value - The decimal value to format as percentage
|
|
33
|
-
* @param decimals - Number of decimal places (default: 1)
|
|
34
|
-
* @returns Formatted percentage string
|
|
35
|
-
* @example
|
|
36
|
-
* formatAsPercentage(0.1234) // '12.3%'
|
|
37
|
-
* formatAsPercentage(0.5, 0) // '50%'
|
|
38
|
-
*/
|
|
39
|
-
export declare function formatAsPercentage(value: number, decimals?: number): string;
|
|
40
|
-
/**
|
|
41
|
-
* Format a number with thousand separators
|
|
42
|
-
* @param num - The number to format
|
|
43
|
-
* @param separator - The separator character (default: ',')
|
|
44
|
-
* @returns Formatted number string with separators
|
|
45
|
-
* @example
|
|
46
|
-
* formatWithSeparators(1234567) // '1,234,567'
|
|
47
|
-
* formatWithSeparators(1234567, ' ') // '1 234 567'
|
|
48
|
-
*/
|
|
49
|
-
export declare function formatWithSeparators(num: number, separator?: string): string;
|
|
50
|
-
/**
|
|
51
|
-
* Round a number to specified decimal places
|
|
52
|
-
* @param num - The number to round
|
|
53
|
-
* @param decimals - Number of decimal places (default: 2)
|
|
54
|
-
* @returns Rounded number
|
|
55
|
-
* @example
|
|
56
|
-
* roundToDecimals(3.14159, 2) // 3.14
|
|
57
|
-
* roundToDecimals(123.456, 0) // 123
|
|
58
|
-
*/
|
|
59
|
-
export declare function roundToDecimals(num: number, decimals?: number): number;
|
|
60
|
-
/**
|
|
61
|
-
* Clamp a number between min and max values
|
|
62
|
-
* @param num - The number to clamp
|
|
63
|
-
* @param min - Minimum value
|
|
64
|
-
* @param max - Maximum value
|
|
65
|
-
* @returns Clamped number
|
|
66
|
-
* @example
|
|
67
|
-
* clampNumber(150, 0, 100) // 100
|
|
68
|
-
* clampNumber(-10, 0, 100) // 0
|
|
69
|
-
* clampNumber(50, 0, 100) // 50
|
|
70
|
-
*/
|
|
71
|
-
export declare function clampNumber(num: number, min: number, max: number): number;
|
|
16
|
+
//# sourceMappingURL=numbers.d.ts.map
|
package/dist/numbers.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../src/numbers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAWvF
|
|
1
|
+
{"version":3,"file":"numbers.d.ts","sourceRoot":"","sources":["../src/numbers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAWvF"}
|
package/dist/numbers.js
CHANGED
|
@@ -25,77 +25,3 @@ export function formatQuantityWithSuffix(quantity, decimals = 1) {
|
|
|
25
25
|
return quantity.toString();
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
|
-
/**
|
|
29
|
-
* Format a large number with customizable suffixes
|
|
30
|
-
* @param num - The number to format
|
|
31
|
-
* @param suffixes - Array of suffix configurations (default: standard K, M, B, T)
|
|
32
|
-
* @param decimals - Number of decimal places (default: 1)
|
|
33
|
-
* @returns Formatted number string with suffix
|
|
34
|
-
* @example
|
|
35
|
-
* formatLargeNumber(1500000) // '1.5M'
|
|
36
|
-
* formatLargeNumber(1500000000) // '1.5B'
|
|
37
|
-
*/
|
|
38
|
-
export function formatLargeNumber(num, suffixes = [
|
|
39
|
-
{ threshold: 1000000000000, suffix: 'T' },
|
|
40
|
-
{ threshold: 1000000000, suffix: 'B' },
|
|
41
|
-
{ threshold: 1000000, suffix: 'M' },
|
|
42
|
-
{ threshold: 1000, suffix: 'K' },
|
|
43
|
-
], decimals = 1) {
|
|
44
|
-
for (const { threshold, suffix } of suffixes) {
|
|
45
|
-
if (num >= threshold) {
|
|
46
|
-
return `${(num / threshold).toFixed(decimals)}${suffix}`;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
return num.toString();
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Format a number as a percentage
|
|
53
|
-
* @param value - The decimal value to format as percentage
|
|
54
|
-
* @param decimals - Number of decimal places (default: 1)
|
|
55
|
-
* @returns Formatted percentage string
|
|
56
|
-
* @example
|
|
57
|
-
* formatAsPercentage(0.1234) // '12.3%'
|
|
58
|
-
* formatAsPercentage(0.5, 0) // '50%'
|
|
59
|
-
*/
|
|
60
|
-
export function formatAsPercentage(value, decimals = 1) {
|
|
61
|
-
return `${(value * 100).toFixed(decimals)}%`;
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Format a number with thousand separators
|
|
65
|
-
* @param num - The number to format
|
|
66
|
-
* @param separator - The separator character (default: ',')
|
|
67
|
-
* @returns Formatted number string with separators
|
|
68
|
-
* @example
|
|
69
|
-
* formatWithSeparators(1234567) // '1,234,567'
|
|
70
|
-
* formatWithSeparators(1234567, ' ') // '1 234 567'
|
|
71
|
-
*/
|
|
72
|
-
export function formatWithSeparators(num, separator = ',') {
|
|
73
|
-
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, separator);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Round a number to specified decimal places
|
|
77
|
-
* @param num - The number to round
|
|
78
|
-
* @param decimals - Number of decimal places (default: 2)
|
|
79
|
-
* @returns Rounded number
|
|
80
|
-
* @example
|
|
81
|
-
* roundToDecimals(3.14159, 2) // 3.14
|
|
82
|
-
* roundToDecimals(123.456, 0) // 123
|
|
83
|
-
*/
|
|
84
|
-
export function roundToDecimals(num, decimals = 2) {
|
|
85
|
-
const factor = Math.pow(10, decimals);
|
|
86
|
-
return Math.round(num * factor) / factor;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Clamp a number between min and max values
|
|
90
|
-
* @param num - The number to clamp
|
|
91
|
-
* @param min - Minimum value
|
|
92
|
-
* @param max - Maximum value
|
|
93
|
-
* @returns Clamped number
|
|
94
|
-
* @example
|
|
95
|
-
* clampNumber(150, 0, 100) // 100
|
|
96
|
-
* clampNumber(-10, 0, 100) // 0
|
|
97
|
-
* clampNumber(50, 0, 100) // 50
|
|
98
|
-
*/
|
|
99
|
-
export function clampNumber(num, min, max) {
|
|
100
|
-
return Math.min(Math.max(num, min), max);
|
|
101
|
-
}
|