@cranberry-money/shared-utils 4.15.0 → 5.0.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/package.json +1 -1
- package/dist/auth.d.ts +0 -55
- package/dist/auth.d.ts.map +0 -1
- package/dist/auth.js +0 -135
- package/dist/badge-status.d.ts +0 -87
- package/dist/badge-status.d.ts.map +0 -1
- package/dist/badge-status.js +0 -170
- package/dist/badge.d.ts +0 -68
- package/dist/badge.d.ts.map +0 -1
- package/dist/badge.js +0 -71
- package/dist/collections.d.ts +0 -81
- package/dist/collections.d.ts.map +0 -1
- package/dist/collections.js +0 -127
- package/dist/currency.d.ts +0 -99
- package/dist/currency.d.ts.map +0 -1
- package/dist/currency.js +0 -128
- package/dist/date.d.ts +0 -64
- package/dist/date.d.ts.map +0 -1
- package/dist/date.js +0 -91
- package/dist/downloads.d.ts +0 -46
- package/dist/downloads.d.ts.map +0 -1
- package/dist/downloads.js +0 -91
- package/dist/filters.d.ts +0 -121
- package/dist/filters.d.ts.map +0 -1
- package/dist/filters.js +0 -206
- package/dist/formatting.d.ts +0 -59
- package/dist/formatting.d.ts.map +0 -1
- package/dist/formatting.js +0 -81
- package/dist/index.d.ts +0 -28
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -34
- package/dist/instruments.d.ts +0 -118
- package/dist/instruments.d.ts.map +0 -1
- package/dist/instruments.js +0 -135
- package/dist/numbers.d.ts +0 -72
- package/dist/numbers.d.ts.map +0 -1
- package/dist/numbers.js +0 -101
- package/dist/portfolio.d.ts +0 -68
- package/dist/portfolio.d.ts.map +0 -1
- package/dist/portfolio.js +0 -87
- package/dist/text.d.ts +0 -22
- package/dist/text.d.ts.map +0 -1
- package/dist/text.js +0 -25
- package/dist/validation.d.ts +0 -249
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -337
- package/dist/withdrawal.d.ts +0 -97
- package/dist/withdrawal.d.ts.map +0 -1
- package/dist/withdrawal.js +0 -119
package/dist/instruments.d.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Instrument and market data formatting utilities
|
|
3
|
-
*/
|
|
4
|
-
/**
|
|
5
|
-
* Format instrument price with currency symbol
|
|
6
|
-
* @param price - The price as string
|
|
7
|
-
* @param currency - The currency code
|
|
8
|
-
* @returns Formatted price with currency symbol
|
|
9
|
-
*/
|
|
10
|
-
export declare function formatInstrumentPrice(price: string, currency?: string | null): string;
|
|
11
|
-
/**
|
|
12
|
-
* Get currency symbol for display
|
|
13
|
-
* @param currency - The currency code
|
|
14
|
-
* @returns Currency symbol
|
|
15
|
-
*/
|
|
16
|
-
export declare function getCurrencySymbol(currency?: string | null): string;
|
|
17
|
-
/**
|
|
18
|
-
* Instrument interface for type determination
|
|
19
|
-
*/
|
|
20
|
-
export interface InstrumentTypeInfo {
|
|
21
|
-
isEtf?: boolean;
|
|
22
|
-
isFund?: boolean;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Determine instrument type based on flags
|
|
26
|
-
* @param instrument - The instrument with type flags
|
|
27
|
-
* @returns Instrument type string
|
|
28
|
-
*/
|
|
29
|
-
export declare function getInstrumentType(instrument: InstrumentTypeInfo): string;
|
|
30
|
-
/**
|
|
31
|
-
* Basic instrument info for formatting
|
|
32
|
-
*/
|
|
33
|
-
export interface InstrumentBasicInfo {
|
|
34
|
-
symbol: string;
|
|
35
|
-
name: string;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Format instrument display name with symbol
|
|
39
|
-
* @param instrument - The instrument with symbol and name
|
|
40
|
-
* @returns Formatted display name
|
|
41
|
-
*/
|
|
42
|
-
export declare function formatInstrumentName(instrument: InstrumentBasicInfo): string;
|
|
43
|
-
/**
|
|
44
|
-
* Price change calculation result
|
|
45
|
-
*/
|
|
46
|
-
export interface PriceChangeResult {
|
|
47
|
-
change: number;
|
|
48
|
-
changePercent: number;
|
|
49
|
-
isPositive: boolean;
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* Snapshot data for price change calculation
|
|
53
|
-
*/
|
|
54
|
-
export interface PriceSnapshot {
|
|
55
|
-
change: string;
|
|
56
|
-
changePercent: string;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Calculate price change from snapshot
|
|
60
|
-
* @param snapshot - The price snapshot
|
|
61
|
-
* @returns Price change calculation result
|
|
62
|
-
*/
|
|
63
|
-
export declare function calculatePriceChange(snapshot: PriceSnapshot): PriceChangeResult;
|
|
64
|
-
/**
|
|
65
|
-
* Formatted price change result
|
|
66
|
-
*/
|
|
67
|
-
export interface FormattedPriceChange {
|
|
68
|
-
changeText: string;
|
|
69
|
-
changePercentText: string;
|
|
70
|
-
colorClass: string;
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Format price change with appropriate color class
|
|
74
|
-
* @param snapshot - The price snapshot
|
|
75
|
-
* @returns Formatted price change with color class
|
|
76
|
-
*/
|
|
77
|
-
export declare function formatPriceChange(snapshot: PriceSnapshot): FormattedPriceChange;
|
|
78
|
-
/**
|
|
79
|
-
* Tradeable instrument info
|
|
80
|
-
*/
|
|
81
|
-
export interface TradeableInstrument {
|
|
82
|
-
isActive: boolean;
|
|
83
|
-
isActivelyTrading: boolean;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Check if instrument is actively tradeable
|
|
87
|
-
* @param instrument - The instrument with trading flags
|
|
88
|
-
* @returns true if tradeable, false otherwise
|
|
89
|
-
*/
|
|
90
|
-
export declare function isInstrumentTradeable(instrument: TradeableInstrument): boolean;
|
|
91
|
-
/**
|
|
92
|
-
* Format market cap value
|
|
93
|
-
* @param marketCap - The market cap value as string or null
|
|
94
|
-
* @returns Formatted market cap string
|
|
95
|
-
*/
|
|
96
|
-
export declare function formatMarketCap(marketCap: string | null | undefined): string;
|
|
97
|
-
/**
|
|
98
|
-
* Format trading volume
|
|
99
|
-
* @param volume - The volume number
|
|
100
|
-
* @returns Formatted volume string
|
|
101
|
-
*/
|
|
102
|
-
export declare function formatVolume(volume: number): string;
|
|
103
|
-
/**
|
|
104
|
-
* Market data availability info
|
|
105
|
-
*/
|
|
106
|
-
export interface MarketDataInfo {
|
|
107
|
-
openPrice?: string | null;
|
|
108
|
-
dayHigh?: string | null;
|
|
109
|
-
dayLow?: string | null;
|
|
110
|
-
volume?: number | null;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Check if market data is available
|
|
114
|
-
* @param marketData - The market data to check
|
|
115
|
-
* @returns true if market data is available, false otherwise
|
|
116
|
-
*/
|
|
117
|
-
export declare function hasMarketData(marketData: MarketDataInfo): boolean;
|
|
118
|
-
//# sourceMappingURL=instruments.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"instruments.d.ts","sourceRoot":"","sources":["../src/instruments.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH;;;;;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;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,kBAAkB,GAAG,MAAM,CAIxE;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,mBAAmB,GAAG,MAAM,CAE5E;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,aAAa,GAAG,iBAAiB,CAS/E;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,aAAa,GAAG,oBAAoB,CAY/E;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,OAAO,CAAC;IAClB,iBAAiB,EAAE,OAAO,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,mBAAmB,GAAG,OAAO,CAE9E;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAU5E;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAKnD;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,cAAc,GAAG,OAAO,CAEjE"}
|
package/dist/instruments.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Instrument and market data formatting utilities
|
|
3
|
-
*/
|
|
4
|
-
import { INSTRUMENT_TYPE_ETF, INSTRUMENT_TYPE_FUND, INSTRUMENT_TYPE_STOCK, CURRENCY_USD, CURRENCY_AUD, } from '@cranberry-money/shared-constants';
|
|
5
|
-
/**
|
|
6
|
-
* Format instrument price with currency symbol
|
|
7
|
-
* @param price - The price as string
|
|
8
|
-
* @param currency - The currency code
|
|
9
|
-
* @returns Formatted price with currency symbol
|
|
10
|
-
*/
|
|
11
|
-
export function formatInstrumentPrice(price, currency) {
|
|
12
|
-
const numericPrice = parseFloat(price);
|
|
13
|
-
if (isNaN(numericPrice))
|
|
14
|
-
return price;
|
|
15
|
-
const currencySymbol = getCurrencySymbol(currency);
|
|
16
|
-
return `${currencySymbol}${numericPrice.toFixed(2)}`;
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Get currency symbol for display
|
|
20
|
-
* @param currency - The currency code
|
|
21
|
-
* @returns Currency symbol
|
|
22
|
-
*/
|
|
23
|
-
export function getCurrencySymbol(currency) {
|
|
24
|
-
switch (currency) {
|
|
25
|
-
case CURRENCY_USD:
|
|
26
|
-
return '$';
|
|
27
|
-
case CURRENCY_AUD:
|
|
28
|
-
return 'A$';
|
|
29
|
-
case 'EUR':
|
|
30
|
-
return '€';
|
|
31
|
-
case 'GBP':
|
|
32
|
-
return '£';
|
|
33
|
-
default:
|
|
34
|
-
return '$'; // Default to USD symbol
|
|
35
|
-
}
|
|
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
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Number formatting utilities
|
|
3
|
-
* Generic number manipulation and formatting functions
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Format a large number with K/M suffixes for display
|
|
7
|
-
* @param quantity - The number to format
|
|
8
|
-
* @param decimals - Number of decimal places (default: 1)
|
|
9
|
-
* @returns Formatted number string with suffix
|
|
10
|
-
* @example
|
|
11
|
-
* formatQuantityWithSuffix(1000) // '1.0K'
|
|
12
|
-
* formatQuantityWithSuffix(1500000) // '1.5M'
|
|
13
|
-
* formatQuantityWithSuffix(999) // '999'
|
|
14
|
-
*/
|
|
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;
|
|
72
|
-
//# sourceMappingURL=numbers.d.ts.map
|
package/dist/numbers.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAC/B,GAAG,EAAE,MAAM,EACX,QAAQ,GAAE,KAAK,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAKpD,EACD,QAAQ,GAAE,MAAU,GACnB,MAAM,CAOR;AAED;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAE9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,MAAY,GAAG,MAAM,CAEjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAU,GAAG,MAAM,CAGzE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzE"}
|
package/dist/numbers.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Number formatting utilities
|
|
3
|
-
* Generic number manipulation and formatting functions
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Format a large number with K/M suffixes for display
|
|
7
|
-
* @param quantity - The number to format
|
|
8
|
-
* @param decimals - Number of decimal places (default: 1)
|
|
9
|
-
* @returns Formatted number string with suffix
|
|
10
|
-
* @example
|
|
11
|
-
* formatQuantityWithSuffix(1000) // '1.0K'
|
|
12
|
-
* formatQuantityWithSuffix(1500000) // '1.5M'
|
|
13
|
-
* formatQuantityWithSuffix(999) // '999'
|
|
14
|
-
*/
|
|
15
|
-
export function formatQuantityWithSuffix(quantity, decimals = 1) {
|
|
16
|
-
const million = 1000000;
|
|
17
|
-
const thousand = 1000;
|
|
18
|
-
if (quantity >= million) {
|
|
19
|
-
return `${(quantity / million).toFixed(decimals)}M`;
|
|
20
|
-
}
|
|
21
|
-
else if (quantity >= thousand) {
|
|
22
|
-
return `${(quantity / thousand).toFixed(decimals)}K`;
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
return quantity.toString();
|
|
26
|
-
}
|
|
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
|
-
}
|
package/dist/portfolio.d.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Portfolio calculation and formatting utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides pure functions for portfolio value calculations,
|
|
5
|
-
* allocations, and formatting. All functions handle string or number inputs
|
|
6
|
-
* for flexibility with API responses.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Formats a portfolio value as currency with AUD
|
|
10
|
-
*
|
|
11
|
-
* @param value - Portfolio value as string or number
|
|
12
|
-
* @returns Formatted currency string with AUD symbol
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* formatPortfolioValue(12345.67) // 'A$12,345.67'
|
|
17
|
-
* formatPortfolioValue('12345.67') // 'A$12,345.67'
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
export declare function formatPortfolioValue(value: string | number): string;
|
|
21
|
-
/**
|
|
22
|
-
* Calculates total portfolio value from market value and cash balance
|
|
23
|
-
*
|
|
24
|
-
* @param marketValue - Market value of holdings
|
|
25
|
-
* @param cashBalance - Cash balance in portfolio
|
|
26
|
-
* @returns Total portfolio value as number
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* calculateTotalValue(10000, 5000) // 15000
|
|
31
|
-
* calculateTotalValue('10000', '5000') // 15000
|
|
32
|
-
* calculateTotalValue('10000.50', 5000.25) // 15000.75
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare function calculateTotalValue(marketValue: string | number, cashBalance: string | number): number;
|
|
36
|
-
/**
|
|
37
|
-
* Calculates market allocation percentage in portfolio
|
|
38
|
-
*
|
|
39
|
-
* @param marketValue - Market value of holdings
|
|
40
|
-
* @param totalValue - Total portfolio value
|
|
41
|
-
* @returns Market allocation percentage (0-100)
|
|
42
|
-
*
|
|
43
|
-
* @example
|
|
44
|
-
* ```typescript
|
|
45
|
-
* getMarketAllocation(7500, 10000) // 75
|
|
46
|
-
* getMarketAllocation('7500', '10000') // 75
|
|
47
|
-
* getMarketAllocation(0, 10000) // 0
|
|
48
|
-
* getMarketAllocation(100, 0) // 0 (prevents division by zero)
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
export declare function getMarketAllocation(marketValue: string | number, totalValue: string | number): number;
|
|
52
|
-
/**
|
|
53
|
-
* Calculates cash allocation percentage in portfolio
|
|
54
|
-
*
|
|
55
|
-
* @param cashBalance - Cash balance in portfolio
|
|
56
|
-
* @param totalValue - Total portfolio value
|
|
57
|
-
* @returns Cash allocation percentage (0-100)
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* getCashAllocation(2500, 10000) // 25
|
|
62
|
-
* getCashAllocation('2500', '10000') // 25
|
|
63
|
-
* getCashAllocation(0, 10000) // 0
|
|
64
|
-
* getCashAllocation(100, 0) // 0 (prevents division by zero)
|
|
65
|
-
* ```
|
|
66
|
-
*/
|
|
67
|
-
export declare function getCashAllocation(cashBalance: string | number, totalValue: string | number): number;
|
|
68
|
-
//# sourceMappingURL=portfolio.d.ts.map
|
package/dist/portfolio.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"portfolio.d.ts","sourceRoot":"","sources":["../src/portfolio.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAUH;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMnE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAItG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAIrG;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAInG"}
|
package/dist/portfolio.js
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Portfolio calculation and formatting utilities
|
|
3
|
-
*
|
|
4
|
-
* This module provides pure functions for portfolio value calculations,
|
|
5
|
-
* allocations, and formatting. All functions handle string or number inputs
|
|
6
|
-
* for flexibility with API responses.
|
|
7
|
-
*/
|
|
8
|
-
import { LOCALE_AUSTRALIA, DEFAULT_NUMERIC_ZERO, DEFAULT_EMPTY_STRING, CURRENCY_AUD, } from '@cranberry-money/shared-constants';
|
|
9
|
-
import { NUMBER_FORMAT_OPTIONS_CURRENCY } from './currency';
|
|
10
|
-
/**
|
|
11
|
-
* Formats a portfolio value as currency with AUD
|
|
12
|
-
*
|
|
13
|
-
* @param value - Portfolio value as string or number
|
|
14
|
-
* @returns Formatted currency string with AUD symbol
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* formatPortfolioValue(12345.67) // 'A$12,345.67'
|
|
19
|
-
* formatPortfolioValue('12345.67') // 'A$12,345.67'
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export function formatPortfolioValue(value) {
|
|
23
|
-
const numValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
24
|
-
return new Intl.NumberFormat(LOCALE_AUSTRALIA, {
|
|
25
|
-
...NUMBER_FORMAT_OPTIONS_CURRENCY,
|
|
26
|
-
currency: CURRENCY_AUD,
|
|
27
|
-
}).format(numValue);
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Calculates total portfolio value from market value and cash balance
|
|
31
|
-
*
|
|
32
|
-
* @param marketValue - Market value of holdings
|
|
33
|
-
* @param cashBalance - Cash balance in portfolio
|
|
34
|
-
* @returns Total portfolio value as number
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* ```typescript
|
|
38
|
-
* calculateTotalValue(10000, 5000) // 15000
|
|
39
|
-
* calculateTotalValue('10000', '5000') // 15000
|
|
40
|
-
* calculateTotalValue('10000.50', 5000.25) // 15000.75
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export function calculateTotalValue(marketValue, cashBalance) {
|
|
44
|
-
const market = typeof marketValue === 'string' ? parseFloat(marketValue || DEFAULT_EMPTY_STRING) : marketValue;
|
|
45
|
-
const cash = typeof cashBalance === 'string' ? parseFloat(cashBalance || DEFAULT_EMPTY_STRING) : cashBalance;
|
|
46
|
-
return market + cash;
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Calculates market allocation percentage in portfolio
|
|
50
|
-
*
|
|
51
|
-
* @param marketValue - Market value of holdings
|
|
52
|
-
* @param totalValue - Total portfolio value
|
|
53
|
-
* @returns Market allocation percentage (0-100)
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* ```typescript
|
|
57
|
-
* getMarketAllocation(7500, 10000) // 75
|
|
58
|
-
* getMarketAllocation('7500', '10000') // 75
|
|
59
|
-
* getMarketAllocation(0, 10000) // 0
|
|
60
|
-
* getMarketAllocation(100, 0) // 0 (prevents division by zero)
|
|
61
|
-
* ```
|
|
62
|
-
*/
|
|
63
|
-
export function getMarketAllocation(marketValue, totalValue) {
|
|
64
|
-
const market = typeof marketValue === 'string' ? parseFloat(marketValue || DEFAULT_EMPTY_STRING) : marketValue;
|
|
65
|
-
const total = typeof totalValue === 'string' ? parseFloat(totalValue || DEFAULT_EMPTY_STRING) : totalValue;
|
|
66
|
-
return total > DEFAULT_NUMERIC_ZERO ? (market / total) * 100 : DEFAULT_NUMERIC_ZERO;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Calculates cash allocation percentage in portfolio
|
|
70
|
-
*
|
|
71
|
-
* @param cashBalance - Cash balance in portfolio
|
|
72
|
-
* @param totalValue - Total portfolio value
|
|
73
|
-
* @returns Cash allocation percentage (0-100)
|
|
74
|
-
*
|
|
75
|
-
* @example
|
|
76
|
-
* ```typescript
|
|
77
|
-
* getCashAllocation(2500, 10000) // 25
|
|
78
|
-
* getCashAllocation('2500', '10000') // 25
|
|
79
|
-
* getCashAllocation(0, 10000) // 0
|
|
80
|
-
* getCashAllocation(100, 0) // 0 (prevents division by zero)
|
|
81
|
-
* ```
|
|
82
|
-
*/
|
|
83
|
-
export function getCashAllocation(cashBalance, totalValue) {
|
|
84
|
-
const cash = typeof cashBalance === 'string' ? parseFloat(cashBalance || DEFAULT_EMPTY_STRING) : cashBalance;
|
|
85
|
-
const total = typeof totalValue === 'string' ? parseFloat(totalValue || DEFAULT_EMPTY_STRING) : totalValue;
|
|
86
|
-
return total > DEFAULT_NUMERIC_ZERO ? (cash / total) * 100 : DEFAULT_NUMERIC_ZERO;
|
|
87
|
-
}
|
package/dist/text.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text manipulation utility functions
|
|
3
|
-
*
|
|
4
|
-
* This module provides pure functions for common text operations
|
|
5
|
-
* such as truncation, formatting, and manipulation.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
9
|
-
*
|
|
10
|
-
* @param text - The text to truncate
|
|
11
|
-
* @param maxLength - The maximum length of the text (default: 30)
|
|
12
|
-
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* truncateText('This is a very long text', 10) // 'This is a...'
|
|
17
|
-
* truncateText('Short', 10) // 'Short'
|
|
18
|
-
* truncateText('', 10) // ''
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export declare function truncateText(text: string, maxLength?: number): string;
|
|
22
|
-
//# sourceMappingURL=text.d.ts.map
|
package/dist/text.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.d.ts","sourceRoot":"","sources":["../src/text.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,GAAE,MAAW,GAAG,MAAM,CAGzE"}
|
package/dist/text.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Text manipulation utility functions
|
|
3
|
-
*
|
|
4
|
-
* This module provides pure functions for common text operations
|
|
5
|
-
* such as truncation, formatting, and manipulation.
|
|
6
|
-
*/
|
|
7
|
-
/**
|
|
8
|
-
* Truncates text to a specified maximum length and adds ellipsis if needed
|
|
9
|
-
*
|
|
10
|
-
* @param text - The text to truncate
|
|
11
|
-
* @param maxLength - The maximum length of the text (default: 30)
|
|
12
|
-
* @returns The truncated text with ellipsis if it exceeds maxLength
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```typescript
|
|
16
|
-
* truncateText('This is a very long text', 10) // 'This is a...'
|
|
17
|
-
* truncateText('Short', 10) // 'Short'
|
|
18
|
-
* truncateText('', 10) // ''
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
export function truncateText(text, maxLength = 30) {
|
|
22
|
-
if (text.length <= maxLength)
|
|
23
|
-
return text;
|
|
24
|
-
return `${text.substring(0, maxLength)}...`;
|
|
25
|
-
}
|