Skip to content

Commit a976332

Browse files
Jiaming Youmeta-codesync[bot]
authored andcommitted
Added getNormalizedZipCode
Summary: Added getNormalizedZipCode Differential Revision: D83914502 fbshipit-source-id: 67c7da860981d2f360043d642a4998ab465c7030
1 parent 7f91d6d commit a976332

3 files changed

Lines changed: 909 additions & 0 deletions

File tree

nodejs/capi-param-builder/src/piiUtil/PIIUtil.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const { getNormalizedEmail } = require('./emailUtil');
1111
const { getNormalizedPhone } = require('./phoneUtil');
1212
const { getNormalizedDOB } = require('./dobUtil');
1313
const { getNormalizedGender } = require('./genderUtil');
14+
const { getNormalizedZipCode } = require('./zipCodeUtil');
1415
const {
1516
getNormalizedName,
1617
getNormalizedCity,
@@ -51,6 +52,8 @@ function getNormalizedPII(piiValue, dataType) {
5152
normalizedPII = getNormalizedCountry(piiValue);
5253
} else if (dataType === Constants.PII_DATA_TYPE.EXTERNAL_ID) {
5354
normalizedPII = getNormalizedExternalID(piiValue);
55+
} else if (dataType === Constants.PII_DATA_TYPE.ZIP_CODE) {
56+
normalizedPII = getNormalizedZipCode(piiValue);
5457
}
5558

5659
return normalizedPII;
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
const { looksLikeHashed, trim } = require('./commonUtil');
10+
11+
function getNormalizedZipCode(zipCode) {
12+
let normalizedZipCode = null;
13+
14+
if (zipCode != null && typeof zipCode === 'string') {
15+
if (looksLikeHashed(zipCode)) {
16+
normalizedZipCode = zipCode;
17+
} else {
18+
const maybeZIP = trim(String(zipCode).toLowerCase().split('-', 1)[0]);
19+
20+
if (maybeZIP.length >= 2) {
21+
normalizedZipCode = maybeZIP;
22+
}
23+
}
24+
}
25+
26+
return normalizedZipCode;
27+
}
28+
29+
module.exports = { getNormalizedZipCode };

0 commit comments

Comments
 (0)