Move phone number format/parse into ts/types/PhoneNumber
This commit is contained in:
parent
93d3abbf8d
commit
80b069e9b6
4 changed files with 20 additions and 21 deletions
|
@ -2,7 +2,7 @@ const { omit, compact, map } = require('lodash');
|
|||
|
||||
const { toLogFormat } = require('./errors');
|
||||
const { SignalService } = require('../../../ts/protobuf');
|
||||
const { parsePhoneNumber } = require('../../../ts/util/parsePhoneNumber');
|
||||
const { parse: parsePhoneNumber } = require('../../../ts/types/PhoneNumber');
|
||||
|
||||
const DEFAULT_PHONE_TYPE = SignalService.DataMessage.Contact.Phone.Type.HOME;
|
||||
const DEFAULT_EMAIL_TYPE = SignalService.DataMessage.Contact.Email.Type.HOME;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// @ts-ignore
|
||||
import Attachments from '../../app/attachments';
|
||||
import { formatPhoneNumber } from '../util/formatPhoneNumber';
|
||||
import { format as formatPhoneNumber } from '../types/PhoneNumber';
|
||||
|
||||
export interface Contact {
|
||||
name: Name;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { instance, PhoneNumberFormat } from './libphonenumberInstance';
|
||||
import { instance, PhoneNumberFormat } from '../util/libphonenumberInstance';
|
||||
|
||||
export function formatPhoneNumber(
|
||||
export function format(
|
||||
phoneNumber: string,
|
||||
options: {
|
||||
ourRegionCode: string;
|
||||
|
@ -20,3 +20,19 @@ export function formatPhoneNumber(
|
|||
return phoneNumber;
|
||||
}
|
||||
}
|
||||
|
||||
export function parse(
|
||||
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;
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
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…
Reference in a new issue