Skip to content

Commit

Permalink
normalize phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
kHorozhanov committed Feb 28, 2024
1 parent 3a10a3c commit 52f3414
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 11 additions & 11 deletions template.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const makeString = require('makeString');
const makeNumber = require('makeNumber');
const toBase64 = require('toBase64');
const fromBase64 = require('fromBase64');
const createRegex = require('createRegex');
const testRegex = require('testRegex');

const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = isLoggingEnabled ? getRequestHeader('trace-id') : undefined;
Expand Down Expand Up @@ -257,17 +259,7 @@ function hashData(key, value) {
value = makeString(value).trim().toLowerCase();

if (key === 'ph') {
value = value
.split(' ')
.join('')
.split('-')
.join('')
.split('(')
.join('')
.split(')')
.join('')
.split('+')
.join('');
value = normalizePhoneNumber(value);
} else if (key === 'ct') {
value = value.split(' ').join('');
}
Expand Down Expand Up @@ -601,6 +593,14 @@ function enhanceEventData(userData) {
return userData;
}

function normalizePhoneNumber(phoneNumber) {
if (!phoneNumber) return phoneNumber;
const itemRegex = createRegex('^[0-9]$');
return phoneNumber.split('')
.filter((item) => testRegex(itemRegex, item))
.join('');
}

function determinateIsLoggingEnabled() {
const containerVersion = getContainerVersion();
const isDebug = !!(
Expand Down
22 changes: 11 additions & 11 deletions template.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,8 @@ const makeString = require('makeString');
const makeNumber = require('makeNumber');
const toBase64 = require('toBase64');
const fromBase64 = require('fromBase64');
const createRegex = require('createRegex');
const testRegex = require('testRegex');

const isLoggingEnabled = determinateIsLoggingEnabled();
const traceId = isLoggingEnabled ? getRequestHeader('trace-id') : undefined;
Expand Down Expand Up @@ -916,17 +918,7 @@ function hashData(key, value) {
value = makeString(value).trim().toLowerCase();

if (key === 'ph') {
value = value
.split(' ')
.join('')
.split('-')
.join('')
.split('(')
.join('')
.split(')')
.join('')
.split('+')
.join('');
value = normalizePhoneNumber(value);
} else if (key === 'ct') {
value = value.split(' ').join('');
}
Expand Down Expand Up @@ -1260,6 +1252,14 @@ function enhanceEventData(userData) {
return userData;
}

function normalizePhoneNumber(phoneNumber) {
if (!phoneNumber) return phoneNumber;
const itemRegex = createRegex('^[0-9]$');
return phoneNumber.split('')
.filter((item) => testRegex(itemRegex, item))
.join('');
}

function determinateIsLoggingEnabled() {
const containerVersion = getContainerVersion();
const isDebug = !!(
Expand Down

0 comments on commit 52f3414

Please sign in to comment.