@enterprize/string-formatter
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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. 😉

PayPal - The safer, easier way to pay online!

Package Sidebar

Install

npm i @enterprize/string-formatter

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

14.2 kB

Total Files

11

Last publish

Collaborators

  • prophet