Formats and validates strings against arbitrary patterns.
Character | Description |
---|---|
0 |
Any numbers |
9 |
Any numbers (Optional) |
# |
Any numbers (recursive) |
A |
Any alphanumeric character |
a |
Any alphanumeric character (Optional) Not implemented yet |
S |
Any letter |
U |
Any letter (All lower case character will be mapped to uppercase) |
L |
Any letter (All upper case character will be mapped to lowercase) |
$ |
Escape character, used to escape any of the special formatting characters. |
const currencyFormatter: StringFormatter = new StringFormatter("R$ #.##0,00", {reverse: true});
const currency: string = "2538792";
const formattedCurrency: string = currencyFormatter.apply(currency);
expect(formattedCurrency).to.equal("R$ 25.387,92");
const percentFormatter: StringFormatter = new StringFormatter("#.##0,00%", {reverse: true});
const percentage: string = "3821";
const formattedPercentage: string = percentFormatter.apply(percentage);
expect(formattedPercentage).to.equal("38,21%");
const numberFormatter: StringFormatter = new StringFormatter("#.##0", {reverse: true});
const number: string = "1854";
const formattedNumber: string = numberFormatter.apply(number);
expect(formattedNumber).to.equal("1.854");
Use my packages in your projects? You think they are awesome? So, help me give more time to develop them by becoming a sponsor. 😉