Format

Utility function to format text, mobile number, amount, masking and etc.

Capitalize


Code Editor
Copy
import { formatCapitalizeWords } from '@erudilabs/alma'

formatCapitalizeWords(value: string)

Code Editor
Copy
formatCapitalizeWords("erudifi bukas danacita")

The result should be in below

Erudifi Bukas Danacita


Percentage


Code Editor
Copy
import { formatPercentage } from '@erudilabs/alma'

formatPercentage(value: string | number, { toFixed: number })

Code Editor
Copy
formatPercentage("0.75")

The result should be in below

75%

Code Editor
Copy
formatPercentage("0.75", { toFixed: 2 })

The result should be in below

75.00%


Asterisk


Code Editor
Copy
import { maskingAsterisk } from '@erudilabs/alma'

maskingAsterisk(value: string)

Code Editor
Copy
maskingAsterisk("+6282312341234")

The result should be in below

+62********234


Mobile Number


Code Editor
Copy
import { formatMobileNumber } from '@erudilabs/alma'

formatMobileNumber(value: string, { options: countryCode: PH | ID })

Code Editor
Copy
formatMobileNumber("+6200000000000", { countryCode: 'ID' })

The result should be in below

+62 00 000 000 000

Code Editor
Copy
formatMobileNumber("+630000000000", { countryCode: 'PH' })

The result should be in below

+63 000 000 0000


Format Options


Code Editor
Copy
import { formatOptions } from '@erudilabs/alma'

const resultApi = [{ id: 1, name: 'Danacita', country: 'indonesia' }, { id: 2, name: 'Bukas', country: 'philipines' }]

Code Editor
Copy
formatOptions(resultApi, { label:'name', value:'country' })

The result should be in below

[{ label: 'Danacita', value: 'indonesia' }, { label: 'Bukas', value: 'philipines' }]


You can sort by alphabetical

Code Editor
Copy
formatOptions(resultApi, { label:'name', value:'country', sort: true })

The result should be in below

[{ label: 'Bukas', value: 'philipines' }, { label: 'Danacita', value: 'indonesia' }]