@cranberry-money/shared-utils 3.0.0 → 3.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.
|
@@ -8,4 +8,9 @@ import type { PortfolioServices } from '@cranberry-money/shared-services';
|
|
|
8
8
|
* Returns a map of instrument UUID to percentage
|
|
9
9
|
*/
|
|
10
10
|
export declare const calculateHoldingAllocations: (holdings: PortfolioServices.AssetHolding[]) => Record<string, number>;
|
|
11
|
+
/**
|
|
12
|
+
* Format quantity for display
|
|
13
|
+
* Handles fractional shares and whole numbers appropriately
|
|
14
|
+
*/
|
|
15
|
+
export declare const formatQuantity: (quantity?: number) => string;
|
|
11
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/portfolio/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,iBAAiB,CAAC,YAAY,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAwB7G,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/portfolio/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E;;;GAGG;AACH,eAAO,MAAM,2BAA2B,GAAI,UAAU,iBAAiB,CAAC,YAAY,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAwB7G,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAI,WAAW,MAAM,KAAG,MAWlD,CAAC"}
|
package/dist/portfolio/index.js
CHANGED
|
@@ -27,3 +27,18 @@ export const calculateHoldingAllocations = (holdings) => {
|
|
|
27
27
|
});
|
|
28
28
|
return allocations;
|
|
29
29
|
};
|
|
30
|
+
/**
|
|
31
|
+
* Format quantity for display
|
|
32
|
+
* Handles fractional shares and whole numbers appropriately
|
|
33
|
+
*/
|
|
34
|
+
export const formatQuantity = (quantity) => {
|
|
35
|
+
if (quantity === undefined || quantity === null)
|
|
36
|
+
return '0';
|
|
37
|
+
// For whole numbers, show without decimals
|
|
38
|
+
if (Number.isInteger(quantity)) {
|
|
39
|
+
return quantity.toString();
|
|
40
|
+
}
|
|
41
|
+
// For fractional shares, show up to 6 decimal places
|
|
42
|
+
// Remove trailing zeros
|
|
43
|
+
return quantity.toFixed(6).replace(/\.?0+$/, '');
|
|
44
|
+
};
|