@cranberry-money/shared-utils 8.23.16 → 8.23.20
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/README.md +0 -157
package/package.json
CHANGED
package/README.md
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# @myportfolio/shared-utils
|
|
2
|
-
|
|
3
|
-
Shared utility functions for the Blueberry platform, supporting both web (Blueberry) and mobile (Blackberry) applications.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```bash
|
|
8
|
-
npm install @myportfolio/shared-utils
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```typescript
|
|
14
|
-
import { formatCurrency, formatDate, hasActiveFilters, truncateText } from '@myportfolio/shared-utils';
|
|
15
|
-
|
|
16
|
-
// Currency formatting
|
|
17
|
-
const amount = formatCurrency(1234.56); // "1,234.56"
|
|
18
|
-
|
|
19
|
-
// Date formatting
|
|
20
|
-
const date = formatDate('2024-01-15T10:30:00Z'); // "1/15/2024"
|
|
21
|
-
|
|
22
|
-
// Filter utilities
|
|
23
|
-
const hasFilters = hasActiveFilters({ name: 'Apple', category: '', page: 1 }); // true
|
|
24
|
-
|
|
25
|
-
// Text utilities
|
|
26
|
-
const short = truncateText('This is a very long text', 10); // "This is a..."
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## Available Utilities
|
|
30
|
-
|
|
31
|
-
### Formatters
|
|
32
|
-
|
|
33
|
-
#### Currency (`formatters/currency.ts`)
|
|
34
|
-
|
|
35
|
-
- `formatCurrency(value)` - Format number with commas and 2 decimals
|
|
36
|
-
- `parseCurrencyInput(value)` - Parse currency string to number
|
|
37
|
-
- `formatCurrencyWithCode(value, code, locale, minDigits, maxDigits)` - Format with currency code
|
|
38
|
-
- `formatDefaultCurrency(value, minDigits, maxDigits)` - Format with default currency (AUD)
|
|
39
|
-
|
|
40
|
-
#### Dates (`formatters/dates.ts`)
|
|
41
|
-
|
|
42
|
-
- `formatDate(dateString, fallback)` - Format ISO date to localized date
|
|
43
|
-
- `formatShortDate(dateString, locale)` - Format to short date (e.g., "Jan 15")
|
|
44
|
-
- `formatTime(dateString, locale)` - Format to 24-hour time
|
|
45
|
-
- `formatDateTime(dateString, locale)` - Format to "Jan 15 14:30"
|
|
46
|
-
|
|
47
|
-
#### Numbers (`formatters/numbers.ts`)
|
|
48
|
-
|
|
49
|
-
- `formatShares(shares, locale)` - Format share quantities (no decimals)
|
|
50
|
-
|
|
51
|
-
### Helpers
|
|
52
|
-
|
|
53
|
-
#### Filters (`helpers/filters.ts`)
|
|
54
|
-
|
|
55
|
-
- `hasActiveFilters<T>(filters, excludeFields)` - Check if any filters are active
|
|
56
|
-
- `countActiveFilters<T>(filters, excludeFields)` - Count active filters
|
|
57
|
-
- `clearAllFilters<T>(filters, preserveFields)` - Clear all filter values
|
|
58
|
-
- `updateFilters<T>(currentFilters, updates)` - Type-safe filter updates
|
|
59
|
-
|
|
60
|
-
#### Text (`helpers/text.ts`)
|
|
61
|
-
|
|
62
|
-
- `truncateText(text, maxLength)` - Truncate text with ellipsis
|
|
63
|
-
|
|
64
|
-
## Platform Compatibility
|
|
65
|
-
|
|
66
|
-
This package is designed to work across:
|
|
67
|
-
|
|
68
|
-
- Web applications (React) - Direct use of utility functions
|
|
69
|
-
- Mobile applications (React Native) - Platform-agnostic implementations
|
|
70
|
-
- Node.js environments - For server-side utility needs
|
|
71
|
-
|
|
72
|
-
### Platform-Specific Considerations
|
|
73
|
-
|
|
74
|
-
#### Date Formatting
|
|
75
|
-
|
|
76
|
-
The date formatters use `Intl.DateTimeFormat` and `toLocaleDateString` which work consistently across web and React Native platforms.
|
|
77
|
-
|
|
78
|
-
#### Currency Formatting
|
|
79
|
-
|
|
80
|
-
Currency formatters use `Intl.NumberFormat` which provides consistent formatting across platforms with proper locale support.
|
|
81
|
-
|
|
82
|
-
#### Filter Utilities
|
|
83
|
-
|
|
84
|
-
Filter utilities are completely platform-agnostic and work with any TypeScript object structure.
|
|
85
|
-
|
|
86
|
-
## Examples
|
|
87
|
-
|
|
88
|
-
### Currency Formatting
|
|
89
|
-
|
|
90
|
-
```typescript
|
|
91
|
-
import { formatCurrency, formatCurrencyWithCode } from '@myportfolio/shared-utils';
|
|
92
|
-
|
|
93
|
-
// Basic formatting
|
|
94
|
-
formatCurrency(1234.56); // "1,234.56"
|
|
95
|
-
formatCurrency('1234.56'); // "1,234.56"
|
|
96
|
-
|
|
97
|
-
// With currency code
|
|
98
|
-
formatCurrencyWithCode(1234.56, 'USD', 'en-US', 2, 2); // "$1,234.56"
|
|
99
|
-
formatCurrencyWithCode(1234.56, 'AUD', 'en-AU', 0, 0); // "A$1,235"
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
### Filter Management
|
|
103
|
-
|
|
104
|
-
```typescript
|
|
105
|
-
import { hasActiveFilters, countActiveFilters, clearAllFilters } from '@myportfolio/shared-utils';
|
|
106
|
-
|
|
107
|
-
const filters = {
|
|
108
|
-
searchQuery: 'apple',
|
|
109
|
-
category: 'technology',
|
|
110
|
-
minPrice: 100,
|
|
111
|
-
maxPrice: null,
|
|
112
|
-
tags: [],
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
// Check for active filters (excluding searchQuery by default)
|
|
116
|
-
hasActiveFilters(filters); // true (category and minPrice are active)
|
|
117
|
-
|
|
118
|
-
// Count active filters
|
|
119
|
-
countActiveFilters(filters); // 2 (category and minPrice)
|
|
120
|
-
|
|
121
|
-
// Clear all filters while preserving searchQuery
|
|
122
|
-
const cleared = clearAllFilters(filters, ['searchQuery']);
|
|
123
|
-
// Result: { searchQuery: 'apple' }
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Date Formatting
|
|
127
|
-
|
|
128
|
-
```typescript
|
|
129
|
-
import { formatDate, formatDateTime, formatShortDate } from '@myportfolio/shared-utils';
|
|
130
|
-
|
|
131
|
-
const isoDate = '2024-01-15T14:30:00Z';
|
|
132
|
-
|
|
133
|
-
formatDate(isoDate); // "1/15/2024"
|
|
134
|
-
formatShortDate(isoDate); // "Jan 15"
|
|
135
|
-
formatDateTime(isoDate); // "Jan 15 14:30"
|
|
136
|
-
```
|
|
137
|
-
|
|
138
|
-
## Development
|
|
139
|
-
|
|
140
|
-
```bash
|
|
141
|
-
# Build the package
|
|
142
|
-
npm run build
|
|
143
|
-
|
|
144
|
-
# Watch for changes
|
|
145
|
-
npm run dev
|
|
146
|
-
|
|
147
|
-
# Type check
|
|
148
|
-
npm run typecheck
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
## Dependencies
|
|
152
|
-
|
|
153
|
-
- `@myportfolio/shared-constants` - For currency and formatting constants
|
|
154
|
-
|
|
155
|
-
## License
|
|
156
|
-
|
|
157
|
-
MIT
|