@enterprize/string-formatter
v1.0.0
Published
Formats and validates strings against arbitrary patterns
Downloads
7
Maintainers
Readme
Enterprize String Formatter
Formats and validates strings against arbitrary patterns.
Mask Characters
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.
Usage
Examples
Currency Masking
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");
Percentage
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%");
Number
const numberFormatter: StringFormatter = new StringFormatter("#.##0", {reverse: true});
const number: string = "1854";
const formattedNumber: string = numberFormatter.apply(number);
expect(formattedNumber).to.equal("1.854");
Sponsor
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: