expensify-common 2.0.149 → 2.0.151

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.
@@ -2,9 +2,9 @@ export default class ExpenseRule {
2
2
  /**
3
3
  * Creates a new instance of this class.
4
4
  *
5
- * @param {Array} ruleArray
5
+ * @param {Object|Array} ruleArray
6
6
  */
7
- constructor(ruleArray: any[]);
7
+ constructor(ruleArray: Object | any[]);
8
8
  /**
9
9
  * Returns the applyWhen array associated with the passed field
10
10
  * i.e. field == category returns [field: 'category', condition: 'matches', value: 'car']
@@ -4,12 +4,20 @@ class ExpenseRule {
4
4
  /**
5
5
  * Creates a new instance of this class.
6
6
  *
7
- * @param {Array} ruleArray
7
+ * @param {Object|Array} ruleArray
8
8
  */
9
9
  constructor(ruleArray) {
10
- ruleArray.forEach((value, key) => {
11
- this[key] = value;
12
- });
10
+ // It's not 100% certain that `ruleArray` is an array or an object, so support both of them so the app doesn't crash
11
+ if (Array.isArray(ruleArray)) {
12
+ ruleArray.forEach((value, key) => {
13
+ this[key] = value;
14
+ });
15
+ }
16
+ else if (ruleArray && typeof ruleArray === 'object') {
17
+ Object.keys(ruleArray).forEach((key) => {
18
+ this[key] = ruleArray[key];
19
+ });
20
+ }
13
21
  }
14
22
  /**
15
23
  * Returns the applyWhen array associated with the passed field
@@ -127,8 +127,7 @@ export default class ExpensiMark {
127
127
  * replace block element with '\n' if :
128
128
  * 1. We have text within the element.
129
129
  * 2. The text does not end with a new line.
130
- * 3. The text does not have quote mark '>' .
131
- * 4. It's not the last element in the string.
130
+ * 3. It's not the last element in the string.
132
131
  */
133
132
  replaceBlockElementWithNewLine(htmlString: string): string;
134
133
  /**
@@ -532,7 +532,8 @@ class ExpensiMark {
532
532
  let resultString = g2
533
533
  .replace(/\n?(<h1># )/g, '$1')
534
534
  .replace(/(<h1>|<\/h1>)+/g, '\n')
535
- .trim()
535
+ // Replace trim() with manually removing line breaks at the beginning and end of the string to avoid adding extra lines
536
+ .replace(/^(\n)+|(\n)+$/g, '')
536
537
  .split('\n');
537
538
  // Wrap each string in the array with <blockquote> and </blockquote>
538
539
  resultString = resultString.map((line) => {
@@ -544,7 +545,9 @@ class ExpensiMark {
544
545
  let depth;
545
546
  do {
546
547
  depth = (modifiedText.match(/<blockquote>/gi) || []).length;
547
- modifiedText = modifiedText.replace(/<blockquote>/gi, '');
548
+ // Need (\s)? because the server usually sends a space character after <blockquote> so we need to consume it,
549
+ // avoid being redundant because it is added in the return part
550
+ modifiedText = modifiedText.replace(/<blockquote>(\s)?/gi, '');
548
551
  modifiedText = modifiedText.replace(/<\/blockquote>/gi, '');
549
552
  } while (/<blockquote>/i.test(modifiedText));
550
553
  return `${'>'.repeat(depth)} ${modifiedText}`;
@@ -963,12 +966,14 @@ class ExpensiMark {
963
966
  * replace block element with '\n' if :
964
967
  * 1. We have text within the element.
965
968
  * 2. The text does not end with a new line.
966
- * 3. The text does not have quote mark '>' .
967
- * 4. It's not the last element in the string.
969
+ * 3. It's not the last element in the string.
968
970
  */
969
971
  replaceBlockElementWithNewLine(htmlString) {
970
972
  // eslint-disable-next-line max-len
971
- let splitText = htmlString.split(/<div.*?>|<\/div>|<comment.*?>|\n<\/comment>|<\/comment>|<h1>|<\/h1>|<h2>|<\/h2>|<h3>|<\/h3>|<h4>|<\/h4>|<h5>|<\/h5>|<h6>|<\/h6>|<p>|<\/p>|<li>|<\/li>|<blockquote>|<\/blockquote>/);
973
+ let splitText = htmlString
974
+ // Lines starting with quote mark '>' will have '\n' added to them so to avoid adding extra '\n', remove the block element right next to it
975
+ .replaceAll(/<blockquote>> (<div.*?>|<\/div>|<comment.*?>|\n<\/comment>|<\/comment>|<h1>|<\/h1>|<h2>|<\/h2>|<h3>|<\/h3>|<h4>|<\/h4>|<h5>|<\/h5>|<h6>|<\/h6>|<p>|<\/p>|<li>|<\/li>)/gi, '<blockquote>> ')
976
+ .split(/<div.*?>|<\/div>|<comment.*?>|\n<\/comment>|<\/comment>|<h1>|<\/h1>|<h2>|<\/h2>|<h3>|<\/h3>|<h4>|<\/h4>|<h5>|<\/h5>|<h6>|<\/h6>|<p>|<\/p>|<li>|<\/li>|<blockquote>|<\/blockquote>/);
972
977
  const stripHTML = (text) => str_1.default.stripHTML(text);
973
978
  splitText = splitText.map(stripHTML);
974
979
  let joinedText = '';
@@ -983,9 +988,8 @@ class ExpensiMark {
983
988
  if (text.trim().length === 0 && !text.match(/\n/)) {
984
989
  return;
985
990
  }
986
- const nextItem = splitText === null || splitText === void 0 ? void 0 : splitText[index + 1];
987
- // Insert '\n' unless it ends with '\n' or '>' or it's the last element, or if it's a header ('# ') with a space.
988
- if ((nextItem && text.match(/>[\s]?$/) && !nextItem.startsWith('> ')) || text.match(/\n[\s]?$/) || index === splitText.length - 1 || text === '# ') {
991
+ // Insert '\n' unless it ends with '\n' or it's the last element, or if it's a header ('# ') with a space.
992
+ if (text.match(/\n[\s]?$/) || index === splitText.length - 1 || text === '# ') {
989
993
  joinedText += text;
990
994
  }
991
995
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "expensify-common",
3
- "version": "2.0.149",
3
+ "version": "2.0.151",
4
4
  "author": "Expensify, Inc.",
5
5
  "description": "Expensify libraries and components shared across different repos",
6
6
  "homepage": "https://expensify.com",