|
1 |
| -# etz-string-formatter |
2 |
| -Formats and validates strings against arbitrary patterns |
| 1 | +# Enterprize String Formatter |
| 2 | +Formats and validates strings against arbitrary patterns. |
| 3 | + |
| 4 | +# Mask Characters |
| 5 | + |
| 6 | +Character | Description |
| 7 | +--- | --- |
| 8 | +`0` | Any numbers |
| 9 | +`9` | Any numbers (Optional) |
| 10 | +`#` | Any numbers (recursive) |
| 11 | +`A` | Any alphanumeric character |
| 12 | +`a` | Any alphanumeric character (Optional) __Not implemented yet__ |
| 13 | +`S` | Any letter |
| 14 | +`U` | Any letter (All lower case character will be mapped to uppercase) |
| 15 | +`L` | Any letter (All upper case character will be mapped to lowercase) |
| 16 | +`$` | Escape character, used to escape any of the special formatting characters. |
| 17 | + |
| 18 | +# Usage |
| 19 | + |
| 20 | +## Examples |
| 21 | + |
| 22 | +### Currency Masking |
| 23 | + |
| 24 | +```typescript |
| 25 | + |
| 26 | +const currencyFormatter: StringFormatter = new StringFormatter("R$ #.##0,00", {reverse: true}); |
| 27 | +const currency: string = "2538792"; |
| 28 | +const formattedCurrency: string = currencyFormatter.apply(currency); |
| 29 | + |
| 30 | +expect(formattedCurrency).to.equal("R$ 25.387,92"); |
| 31 | +``` |
| 32 | + |
| 33 | +### Percentage |
| 34 | + |
| 35 | +```typescript |
| 36 | + |
| 37 | +const percentFormatter: StringFormatter = new StringFormatter("#.##0,00%", {reverse: true}); |
| 38 | + const percentage: string = "3821"; |
| 39 | + const formattedPercentage: string = percentFormatter.apply(percentage); |
| 40 | + |
| 41 | + expect(formattedPercentage).to.equal("38,21%"); |
| 42 | +``` |
| 43 | + |
| 44 | +### Number |
| 45 | + |
| 46 | +```typescript |
| 47 | + |
| 48 | +const numberFormatter: StringFormatter = new StringFormatter("#.##0", {reverse: true}); |
| 49 | +const number: string = "1854"; |
| 50 | +const formattedNumber: string = numberFormatter.apply(number); |
| 51 | + |
| 52 | +expect(formattedNumber).to.equal("1.854"); |
| 53 | +``` |
| 54 | + |
| 55 | +# Sponsor |
| 56 | + |
| 57 | +Use my packages in your projects? You think they are awesome? So, help me give more time to develop them by becoming a sponsor. :wink: |
| 58 | + |
| 59 | +<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=8KT6SPVB84XLY&source=url"><img src="https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif" alt="PayPal - The safer, easier way to pay online!"></a> |
0 commit comments