Parse phone numbers into e164 as part of schema upgrade
This commit is contained in:
parent
8cb1f1f532
commit
aa13a2c6f7
8 changed files with 87 additions and 8 deletions
|
@ -137,6 +137,7 @@ const Attachments = {
|
|||
parent.Signal = Signal.setup({
|
||||
Attachments,
|
||||
userDataPath: '/',
|
||||
getRegionCode: () => parent.storage.get('regionCode'),
|
||||
});
|
||||
parent.SignalService = SignalService;
|
||||
|
||||
|
|
17
ts/util/parsePhoneNumber.ts
Normal file
17
ts/util/parsePhoneNumber.ts
Normal file
|
@ -0,0 +1,17 @@
|
|||
import { instance, PhoneNumberFormat } from './libphonenumberInstance';
|
||||
|
||||
export function parsePhoneNumber(
|
||||
phoneNumber: string,
|
||||
options: {
|
||||
regionCode: string;
|
||||
}
|
||||
): string {
|
||||
const { regionCode } = options;
|
||||
const parsedNumber = instance.parse(phoneNumber, regionCode);
|
||||
|
||||
if (instance.isValidNumber(parsedNumber)) {
|
||||
return instance.format(parsedNumber, PhoneNumberFormat.E164);
|
||||
}
|
||||
|
||||
return phoneNumber;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue