@temboplus/frontend-core 0.3.0 → 0.4.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.
@@ -46,16 +46,16 @@ export type AmountJSON = z.infer<typeof AmountJSONSchema>;
46
46
  * @example
47
47
  * ```typescript
48
48
  * // Currency-amount combinations
49
- * Amount.from('TZS10000'); // TSh 10,000.00
50
- * Amount.from('TZS 10,000'); // TSh 10,000.00 (spaces removed)
51
- * Amount.from('10000TZS'); // TSh 10,000.00
52
- * Amount.from('TZS1,234.56'); // TSh 1,234.56
53
- * Amount.from('-TZS1000'); // -TSh 1,000.00
54
- * Amount.from('TZS-1000'); // -TSh 1,000.00
49
+ * Amount.from('TZS10000'); // TZS 10,000.00
50
+ * Amount.from('TZS 10,000'); // TZS 10,000.00 (spaces removed)
51
+ * Amount.from('10000TZS'); // TZS 10,000.00
52
+ * Amount.from('TZS1,234.56'); // TZS 1,234.56
53
+ * Amount.from('-TZS1000'); // -TZS 1,000.00
54
+ * Amount.from('TZS-1000'); // -TZS 1,000.00
55
55
  *
56
56
  * // Traditional usage still works
57
- * Amount.from(1000, 'TZS'); // TSh 1,000.00
58
- * Amount.from('1000', 'USD'); // $1,000.00
57
+ * Amount.from(1000, 'TZS'); // TZS 1,000.00
58
+ * Amount.from('1000', 'USD'); // USD 1,000.00
59
59
  * ```
60
60
  */
61
61
  /**
@@ -75,13 +75,13 @@ export interface AmountJson {
75
75
  * Formatting options for the enhanced format method
76
76
  */
77
77
  interface AmountFormatOptions {
78
- /** Include currency symbol (e.g., $, TSh) */
79
- includeSymbol?: boolean;
80
- /** Include currency code (e.g., USD, TZS) */
81
- includeCurrency?: boolean;
82
- /** Position of currency symbol */
83
- symbolPosition?: "before" | "after";
84
- /** Use thousands separators (commas) */
78
+ /** Show currency indicator (code by default, or symbol if useSymbol is true). Default: true */
79
+ showCurrency?: boolean;
80
+ /** Use currency symbol (e.g., $, TSh) instead of code (e.g., USD, TZS). Default: false */
81
+ useSymbol?: boolean;
82
+ /** Position of currency indicator. Default: "before" */
83
+ currencyPosition?: "before" | "after";
84
+ /** Use thousands separators (commas). Default: true */
85
85
  useGrouping?: boolean;
86
86
  /** Minimum number of decimal places */
87
87
  minimumFractionDigits?: number;
@@ -95,10 +95,8 @@ interface AmountFormatOptions {
95
95
  thousandsSeparator?: string;
96
96
  /** Custom decimal separator */
97
97
  decimalSeparator?: string;
98
- /** Use native formatting with Intl.NumberFormat (defaults to false for backward compatibility) */
98
+ /** Use native formatting with Intl.NumberFormat (defaults to false) */
99
99
  useNativeFormatting?: boolean;
100
- /** Use native currency symbol instead of international symbol */
101
- useNativeSymbol?: boolean;
102
100
  /** Prefer native locale for the currency (overrides provided locale) */
103
101
  useNativeLocale?: boolean;
104
102
  }
@@ -116,9 +114,9 @@ interface AmountFormatOptions {
116
114
  * @example
117
115
  * ```typescript
118
116
  * // Creating amounts
119
- * const positive = Amount.from(1000, 'USD'); // $1,000.00
120
- * const negative = Amount.from(-500, 'USD'); // -$500.00
121
- * const fromString = Amount.from('-1,234.56', 'EUR'); // -€1,234.56
117
+ * const positive = Amount.from(1000, 'USD'); // USD 1,000.00
118
+ * const negative = Amount.from(-500, 'USD'); // -USD 500.00
119
+ * const fromString = Amount.from('-1,234.56', 'EUR'); // -EUR 1,234.56
122
120
  *
123
121
  * // Mathematical operations
124
122
  * const sum = positive.add(negative); // $500.00
@@ -480,51 +478,41 @@ declare class Amount {
480
478
  * const amount = Amount.from(-1234.56, 'USD');
481
479
  * const tzAmount = Amount.from(1234.56, 'TZS');
482
480
  *
483
- * // Basic formatting (existing behavior)
484
- * amount.format(); // "-$1,234.56"
481
+ * // Default formatting (currency codes)
482
+ * amount.format(); // "-USD 1,234.56"
483
+ * tzAmount.format(); // "TZS 1,234.56"
485
484
  *
486
- * // Native formatting with proper spacing and locale
487
- * tzAmount.format({ useNativeFormatting: true }); // "TSh 1,234.56"
485
+ * // Symbol formatting (opt-in)
486
+ * amount.format({ useSymbol: true }); // "-$1,234.56"
487
+ * tzAmount.format({ useSymbol: true }); // "TSh 1,234.56"
488
+ *
489
+ * // Native formatting with Intl (uses symbols via browser locale)
488
490
  * tzAmount.format({ useNativeFormatting: true, useNativeLocale: true }); // Uses Swahili locale
489
491
  *
490
- * // Manual formatting with native symbols
491
- * amount.format({ useNativeSymbol: true }); // "-$1,234.56"
492
- * tzAmount.format({ useNativeSymbol: true }); // "-TSh 1,234.56" (with proper spacing)
493
- *
494
- * // Advanced native formatting
495
- * amount.format({
496
- * useNativeFormatting: true,
497
- * useNativeLocale: true,
498
- * showSign: 'always'
499
- * }); // "+$1,234.56" (US formatting)
500
- *
501
- * // European formatting
502
- * Amount.from(1234.56, 'EUR').format({
503
- * useNativeFormatting: true,
504
- * useNativeLocale: true
505
- * }); // "1.234,56 €" (German formatting)
506
- *
507
- * // Custom formatting (existing behavior preserved)
508
- * amount.format({ symbolPosition: 'after', useGrouping: false }); // "-1234.56$"
492
+ * // Currency position
493
+ * amount.format({ currencyPosition: 'after' }); // "-1,234.56 USD"
494
+ *
495
+ * // No currency
496
+ * amount.format({ showCurrency: false }); // "-1,234.56"
509
497
  * ```
510
498
  */
511
499
  format(options?: AmountFormatOptions): string;
512
500
  /**
513
- * Convenience method for native formatting
501
+ * Convenience method for native formatting using Intl.NumberFormat with symbols
514
502
  * @param options Additional formatting options
515
- * @returns Formatted string using native currency conventions
503
+ * @returns Formatted string using native currency conventions with symbols
516
504
  */
517
505
  formatNative(options?: Omit<AmountFormatOptions, "useNativeFormatting">): string;
518
506
  /**
519
- * Enhanced label using native formatting for better UX
507
+ * Primary display label using currency codes (e.g., "TZS 1,000.00", "USD 500.00")
520
508
  */
521
509
  get label(): string;
522
510
  /**
523
- * International label using consistent formatting
511
+ * International label using currency codes with en-US locale
524
512
  */
525
513
  get internationalLabel(): string;
526
514
  /**
527
- * Returns the amount as a plain number string without currency symbols
515
+ * Returns the amount as a plain number string without currency indicator
528
516
  *
529
517
  * @param options - Formatting options for the numeric value
530
518
  * @returns Plain numeric string
@@ -538,35 +526,34 @@ declare class Amount {
538
526
  * }); // "1,234.5000"
539
527
  * ```
540
528
  */
541
- toPlainNumber(options?: Omit<AmountFormatOptions, "includeSymbol" | "includeCurrency" | "symbolPosition">): string;
529
+ toPlainNumber(options?: Omit<AmountFormatOptions, "showCurrency" | "useSymbol" | "currencyPosition">): string;
542
530
  /**
543
531
  * Formats amount in compact notation (K, M, B, T)
544
532
  *
545
533
  * @param precision - Number of decimal places for compact numbers (default: 1)
546
- * @param includeSymbol - Whether to include currency symbol (default: true)
547
534
  * @param options - Additional formatting options
548
535
  * @returns Compact formatted string
549
536
  *
550
537
  * @example
551
538
  * ```typescript
552
- * Amount.from(1500).toCompactFormat(); // "$1.5K"
553
- * Amount.from(-2500000).toCompactFormat(); // "-$2.5M"
554
- * Amount.from(1234567890).toCompactFormat(); // "$1.2B"
555
- * Amount.from(999).toCompactFormat(); // "$999"
556
- * Amount.from(1000000, 'EUR').toCompactFormat(2); // "1.00M"
557
- * Amount.from(1000000).toCompactFormat(2, true, { alwaysShowDecimals: true }); // "$1.00M"
558
- * Amount.from(1500000).toCompactFormat(0); // "$2M" (rounded)
539
+ * Amount.from(1500).toCompactFormat(); // "TZS 1.5K"
540
+ * Amount.from(-2500000, 'USD').toCompactFormat(); // "-USD 2.5M"
541
+ * Amount.from(1234567890, 'USD').toCompactFormat(); // "USD 1.2B"
542
+ * Amount.from(999, 'USD').toCompactFormat(); // "USD 999"
543
+ * Amount.from(1000000, 'EUR').toCompactFormat(2, { alwaysShowDecimals: true }); // "EUR 1.00M"
544
+ * Amount.from(1500000, 'USD').toCompactFormat(0); // "USD 2M" (rounded)
559
545
  * ```
560
546
  */
561
547
  toCompactFormat(precision?: number, options?: {
562
- includeSymbol?: boolean;
548
+ showCurrency?: boolean;
549
+ useSymbol?: boolean;
563
550
  alwaysShowDecimals?: boolean;
564
551
  roundingMode?: "round" | "floor" | "ceil";
565
552
  }): string;
566
553
  /**
567
554
  * Returns the amount rounded to the nearest whole number
568
555
  *
569
- * @param includeSymbol - Whether to include currency symbol (default: false)
556
+ * @param showCurrency - Whether to include currency code (default: false)
570
557
  * @param useGrouping - Whether to use thousands separators (default: true)
571
558
  * @returns Whole number formatted string
572
559
  *
@@ -574,11 +561,11 @@ declare class Amount {
574
561
  * ```typescript
575
562
  * Amount.from(1234.56).toWholeNumber(); // "1,235"
576
563
  * Amount.from(-1234.44).toWholeNumber(); // "-1,234"
577
- * Amount.from(1000.5).toWholeNumber(true); // "$1,001"
564
+ * Amount.from(1000.5, 'USD').toWholeNumber(true); // "USD 1,001"
578
565
  * Amount.from(999.4).toWholeNumber(false, false); // "999"
579
566
  * ```
580
567
  */
581
- toWholeNumber(includeSymbol?: boolean, useGrouping?: boolean): string;
568
+ toWholeNumber(showCurrency?: boolean, useGrouping?: boolean): string;
582
569
  /**
583
570
  * Helper method to get the actual rounded value as a number (for toWholeNumber)
584
571
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/frontend-core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.",
5
5
  "author": "Okello Gerald",
6
6
  "license": "MIT",