@dialstack/sdk-dev / js/src / formatWhileTyping
Function: formatWhileTyping()
TypeScript
function formatWhileTyping(raw, previous): string;
Defined in: sdk/js/src/utils/phone-input-format.ts:20
Format a single number field as it is typed.
Formatting applies to insertions only. A deletion is always literal — one
keypress removes exactly the one character under the caret and nothing else.
Rewriting during a deletion is what makes an input feel possessed: removing
the x from 678-555-0199 x123 would also swallow the space, so the next
press lands on a digit instead of where the reader was aiming.
Shared by both surfaces because these rules are subtle, the failure mode is a digit silently disappearing, and the two must behave identically.
Parameters
raw
string
previous
string
Returns
string