I finally got around to writing a Snippet to reformat US phone numbers.
Unfortunately, when I posted it to the Forum, the Snippet wasn’t recognized when selected.
For some reason, the software used for the Forum, Discourse, is apparently converting the characters #popclip
into a link to https://forum.popclip.app/c/popclip/17
as you can see in this screenshot:
How do I upload this Extension?
// PopClip
// name: US Phone Number
// icon: square +1
// language: javascript
// after: paste-result
//
const countryCode = ‘1’;
const prefix = ‘+’ + countryCode + ’ ';
const separator = ’ ';
const standardPhoneNumberLength = 10;
const selectedText = popclip.input.text;
let digitsOnly = selectedText.replace(/\D/g, ‘’);
if (digitsOnly.startsWith(countryCode)) {
digitsOnly = digitsOnly.slice(countryCode.length);
}
if (digitsOnly.length == standardPhoneNumberLength) {
return prefix + digitsOnly.slice(0,3) + separator + digitsOnly.slice(3,6) + separator + digitsOnly.slice(6);
}
return selectedText;