expensify-common 2.0.2 → 2.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,7 +35,7 @@ declare type Rule = {
35
35
  };
36
36
 
37
37
  declare type ExtrasObject = {
38
- reportIdToName?: Record<string, string>;
38
+ reportIDToName?: Record<string, string>;
39
39
  accountIDToName?: Record<string, string>;
40
40
  };
41
41
  export default class ExpensiMark {
@@ -197,7 +197,10 @@ class ExpensiMark {
197
197
  name: 'userMentions',
198
198
  regex: new RegExp(`(@here|[a-zA-Z0-9.!$%&+=?^\`{|}-]?)(@${Constants.CONST.REG_EXP.EMAIL_PART}|@${Constants.CONST.REG_EXP.PHONE_PART})(?!((?:(?!<a).)+)?<\\/a>|[^<]*(<\\/pre>|<\\/code>))`, 'gim'),
199
199
  replacement: (match, g1, g2) => {
200
- if (!str_1.default.isValidMention(match)) {
200
+ const phoneNumberRegex = new RegExp(`^${Constants.CONST.REG_EXP.PHONE_PART}$`);
201
+ const mention = g2.slice(1);
202
+ const mentionWithoutSMSDomain = str_1.default.removeSMSDomain(mention);
203
+ if (!str_1.default.isValidMention(match) || (phoneNumberRegex.test(mentionWithoutSMSDomain) && !str_1.default.isValidPhoneNumber(mentionWithoutSMSDomain))) {
201
204
  return match;
202
205
  }
203
206
  const phoneRegex = new RegExp(`^@${Constants.CONST.REG_EXP.PHONE_PART}$`);
@@ -453,7 +456,7 @@ class ExpensiMark {
453
456
  name: 'reportMentions',
454
457
  regex: /<mention-report reportID="(\d+)" *\/>/gi,
455
458
  replacement: (match, g1, offset, string, extras) => {
456
- const reportToNameMap = extras.reportIdToName;
459
+ const reportToNameMap = extras.reportIDToName;
457
460
  if (!reportToNameMap || !reportToNameMap[g1]) {
458
461
  Log_1.default.alert('[ExpensiMark] Missing report name', { reportID: g1 });
459
462
  return '#Hidden';
@@ -466,12 +469,12 @@ class ExpensiMark {
466
469
  regex: /(?:<mention-user accountID="(\d+)" *\/>)|(?:<mention-user>(.*?)<\/mention-user>)/gi,
467
470
  replacement: (match, g1, g2, offset, string, extras) => {
468
471
  if (g1) {
469
- const accountToNameMap = extras.accountIdToName;
472
+ const accountToNameMap = extras.accountIDToName;
470
473
  if (!accountToNameMap || !accountToNameMap[g1]) {
471
474
  Log_1.default.alert('[ExpensiMark] Missing account name', { accountID: g1 });
472
475
  return '@Hidden';
473
476
  }
474
- return `@${extras.accountIdToName[g1]}`;
477
+ return `@${extras.accountIDToName[g1]}`;
475
478
  }
476
479
  return str_1.default.removeSMSDomain(g2);
477
480
  },
@@ -522,7 +525,7 @@ class ExpensiMark {
522
525
  name: 'reportMentions',
523
526
  regex: /<mention-report reportID="(\d+)" *\/>/gi,
524
527
  replacement: (match, g1, offset, string, extras) => {
525
- const reportToNameMap = extras.reportIdToName;
528
+ const reportToNameMap = extras.reportIDToName;
526
529
  if (!reportToNameMap || !reportToNameMap[g1]) {
527
530
  Log_1.default.alert('[ExpensiMark] Missing report name', { reportID: g1 });
528
531
  return '#Hidden';
@@ -534,12 +537,12 @@ class ExpensiMark {
534
537
  name: 'userMention',
535
538
  regex: /<mention-user accountID="(\d+)" *\/>/gi,
536
539
  replacement: (match, g1, offset, string, extras) => {
537
- const accountToNameMap = extras.accountIdToName;
540
+ const accountToNameMap = extras.accountIDToName;
538
541
  if (!accountToNameMap || !accountToNameMap[g1]) {
539
542
  Log_1.default.alert('[ExpensiMark] Missing account name', { accountID: g1 });
540
543
  return '@Hidden';
541
544
  }
542
- return `@${extras.accountIdToName[g1]}`;
545
+ return `@${extras.accountIDToName[g1]}`;
543
546
  },
544
547
  },
545
548
  {
package/dist/str.d.ts CHANGED
@@ -478,9 +478,14 @@ declare const Str: {
478
478
  /**
479
479
  * Check for whether a phone number is valid.
480
480
  * @param phone
481
- * @deprecated use isValidE164Phone to validate E.164 phone numbers or isValidPhoneFormat to validate phone numbers in general
481
+ * @deprecated use isValidE164Phone to validate E.164 phone numbers, isValidPhoneFormat to validate phone number format, or isValidPhoneNumber to validate phone numbers in general
482
482
  */
483
483
  isValidPhone(phone: string): boolean;
484
+ /**
485
+ * Check for whether a phone number is valid.
486
+ * @param phone
487
+ */
488
+ isValidPhoneNumber(phone: string): boolean;
484
489
  /**
485
490
  * Check for whether a phone number is valid according to E.164 standard.
486
491
  * @param phone
package/dist/str.js CHANGED
@@ -28,6 +28,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  /* eslint-disable no-control-regex */
30
30
  const underscore_1 = __importDefault(require("underscore"));
31
+ const awesome_phonenumber_1 = require("awesome-phonenumber");
31
32
  const HtmlEntities = __importStar(require("html-entities"));
32
33
  const Constants = __importStar(require("./CONST"));
33
34
  const UrlPatterns = __importStar(require("./Url"));
@@ -868,6 +869,15 @@ const Str = {
868
869
  isValidPhone(phone) {
869
870
  return Constants.CONST.SMS.E164_REGEX.test(phone);
870
871
  },
872
+ /**
873
+ * Check for whether a phone number is valid.
874
+ * @param {String} phone
875
+ *
876
+ * @return {bool}
877
+ */
878
+ isValidPhoneNumber(phone) {
879
+ return (0, awesome_phonenumber_1.parsePhoneNumber)(phone).possible;
880
+ },
871
881
  /**
872
882
  * Check for whether a phone number is valid according to E.164 standard.
873
883
  * @param {String} phone
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.2",
3
+ "version": "2.0.4",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",
@@ -28,6 +28,7 @@
28
28
  "url": "git+ssh://git@github.com/Expensify/JS-Libs.git"
29
29
  },
30
30
  "dependencies": {
31
+ "awesome-phonenumber": "^5.4.0",
31
32
  "classnames": "2.5.0",
32
33
  "clipboard": "2.0.11",
33
34
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.14.0",