1.0.0 • Published 4 years ago

@enterprize/string-formatter v1.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Enterprize String Formatter

Formats and validates strings against arbitrary patterns.

Mask Characters

CharacterDescription
0Any numbers
9Any numbers (Optional)
#Any numbers (recursive)
AAny alphanumeric character
aAny alphanumeric character (Optional) Not implemented yet
SAny letter
UAny letter (All lower case character will be mapped to uppercase)
LAny 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: