( input: string | null, symbol: string = '', digits: number = 3, splitter: string = ',', symbolAlign = SymbolAlign.default, )
| 295 | * @param symbolAlign currency symbol position |
| 296 | */ |
| 297 | export function str2Currency( |
| 298 | input: string | null, |
| 299 | symbol: string = '', |
| 300 | digits: number = 3, |
| 301 | splitter: string = ',', |
| 302 | symbolAlign = SymbolAlign.default, |
| 303 | ): string | null { |
| 304 | let tempStr = ('' + input).trim(); |
| 305 | let sign = ''; |
| 306 | |
| 307 | if (input == null || tempStr === '') { |
| 308 | return null; |
| 309 | } |
| 310 | if (tempStr.startsWith('-')) { |
| 311 | sign = '-'; |
| 312 | tempStr = tempStr.substring(1); |
| 313 | } |
| 314 | if (tempStr.includes('e')) { |
| 315 | if (symbolAlign === SymbolAlign.right) { |
| 316 | return `${sign}${tempStr}${symbol}`; |
| 317 | } |
| 318 | return `${sign}${symbol}${tempStr}`; |
| 319 | } |
| 320 | if (!tempStr.includes('.')) { |
| 321 | tempStr += '.'; |
| 322 | } |
| 323 | |
| 324 | const regExp = new RegExp(`(\\d)(?=(\\d{${digits}})+\\.)`, 'g'); |
| 325 | |
| 326 | tempStr = tempStr.replace(regExp, function(_$0: string, $1: any) { |
| 327 | return $1 + splitter; |
| 328 | }).replace(/\.$/, ''); |
| 329 | if (!tempStr) { |
| 330 | return null; |
| 331 | } |
| 332 | |
| 333 | if (symbolAlign === SymbolAlign.right) { |
| 334 | return `${sign}${tempStr}${symbol}`; |
| 335 | } |
| 336 | return `${sign}${symbol}${tempStr}`; |
| 337 | } |
| 338 | |
| 339 | export function truncateText(text: string, maxLength: number = 20, postfix: string = '...') { |
| 340 | if (text.length <= maxLength) return text; |
no test coverage detected