expensify-common 2.0.181 → 2.0.183

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.
package/dist/Func.js CHANGED
@@ -82,7 +82,9 @@ function invokeAsync(callback, args, scope) {
82
82
  * @param {Array} [args]
83
83
  */
84
84
  function bulkInvoke(callbacks, args) {
85
- callbacks.forEach((callback) => invoke(callback, args));
85
+ for (const callback of callbacks) {
86
+ invoke(callback, args);
87
+ }
86
88
  }
87
89
  /**
88
90
  * Throws an uncaught error in an attempt to stop JS execution
package/dist/Log.js CHANGED
@@ -48,7 +48,7 @@ const Utils = __importStar(require("./utils"));
48
48
  * @param {Object} params
49
49
  * @param {Object} params.parameters
50
50
  * @param {String} params.message
51
- * @return {Promise}
51
+ * @returns {Promise}
52
52
  */
53
53
  function serverLoggingCallback(logger, params) {
54
54
  return (0, API_1.default)((0, Network_1.default)('/api/')).logToServer(params);
package/dist/Logger.d.ts CHANGED
@@ -61,8 +61,8 @@ export default class Logger {
61
61
  /**
62
62
  * Logs a warn.
63
63
  *
64
- * @param {String} message The message to warn.
65
- * @param {Object|String} parameters The parameters to send along with the message
64
+ * @param message The message to warn.
65
+ * @param parameters The parameters to send along with the message
66
66
  */
67
67
  warn(message: string, parameters?: Parameters): void;
68
68
  /**
package/dist/Logger.js CHANGED
@@ -33,11 +33,13 @@ class Logger {
33
33
  return l;
34
34
  });
35
35
  this.logLines = [];
36
- const promise = this.serverLoggingCallback(this, { api_setCookie: false, logPacket: JSON.stringify(linesToLog) });
36
+ const promise = this.serverLoggingCallback(this, {
37
+ api_setCookie: false,
38
+ logPacket: JSON.stringify(linesToLog),
39
+ });
37
40
  if (!promise) {
38
41
  return;
39
42
  }
40
- // eslint-disable-next-line rulesdir/prefer-early-return
41
43
  promise.then((response) => {
42
44
  if (!response.requestID) {
43
45
  return;
@@ -107,8 +109,8 @@ class Logger {
107
109
  /**
108
110
  * Logs a warn.
109
111
  *
110
- * @param {String} message The message to warn.
111
- * @param {Object|String} parameters The parameters to send along with the message
112
+ * @param message The message to warn.
113
+ * @param parameters The parameters to send along with the message
112
114
  */
113
115
  warn(message, parameters = '') {
114
116
  const msg = `[warn] ${message}`;
package/dist/Network.js CHANGED
@@ -113,16 +113,16 @@ function Network(endpoint) {
113
113
  // Check to see if parameters contains a File or Blob object
114
114
  // If it does, we should use formData instead of parameters and update
115
115
  // the ajax settings accordingly
116
- Object.entries(parameters).forEach(([key, value]) => {
116
+ for (const [key, value] of Object.entries(parameters)) {
117
117
  if (value === undefined) {
118
- return;
118
+ continue;
119
119
  }
120
120
  // Populate formData in case we need it
121
121
  formData.append(key, value);
122
122
  if (value instanceof File || value instanceof Blob) {
123
123
  shouldUseFormData = true;
124
124
  }
125
- });
125
+ }
126
126
  if (shouldUseFormData) {
127
127
  settings.processData = false;
128
128
  settings.contentType = false;
@@ -153,26 +153,26 @@ function Network(endpoint) {
153
153
  url = addCommandToUrl(parameters.command, url);
154
154
  // Add our data as form data
155
155
  const formData = new FormData();
156
- Object.entries(parameters).forEach(([key, value]) => {
156
+ for (const [key, value] of Object.entries(parameters)) {
157
157
  if (value === undefined) {
158
- return;
158
+ continue;
159
159
  }
160
160
  if (Array.isArray(value)) {
161
- value.forEach((valueItem, i) => {
161
+ for (const [i, valueItem] of value.entries()) {
162
162
  if (Utils.isObject(valueItem)) {
163
- Object.entries(valueItem).forEach(([valueItemObjectKey, valueItemObjectValue]) => {
163
+ for (const [valueItemObjectKey, valueItemObjectValue] of Object.entries(valueItem)) {
164
164
  formData.append(`${key}[${i}][${valueItemObjectKey}]`, valueItemObjectValue);
165
- });
165
+ }
166
166
  }
167
167
  else {
168
168
  formData.append(`${key}[${i}]`, valueItem);
169
169
  }
170
- });
170
+ }
171
171
  }
172
172
  else {
173
173
  formData.append(key, value);
174
174
  }
175
- });
175
+ }
176
176
  settings.body = formData;
177
177
  // Make our request via the fetch API but return it in the form of a jQuery promise
178
178
  // so that our API can be consistent
package/dist/Num.d.ts CHANGED
@@ -59,7 +59,7 @@ declare namespace _default {
59
59
  * Returns how many decimals to display (used for currencies).
60
60
  *
61
61
  * @param {Number} rate
62
- * @return {Number}
62
+ * @returns {Number}
63
63
  */
64
64
  function getDisplayDecimals(rate: number): number;
65
65
  namespace tax {
package/dist/Num.js CHANGED
@@ -52,7 +52,8 @@ exports.default = {
52
52
  let h = null;
53
53
  let i = null;
54
54
  let j = null;
55
- a = Math.round(a * Math.pow(10, b)) / Math.pow(10, b);
55
+ const multiplier = Math.pow(10, b);
56
+ a = Math.round(a * multiplier) / multiplier;
56
57
  if (a < 0) {
57
58
  a *= -1;
58
59
  sign = '-';
@@ -76,7 +77,8 @@ exports.default = {
76
77
  h = f[0];
77
78
  f[0] = '';
78
79
  for (j = 3; j < h.length; j += 3) {
79
- i = h.slice(h.length - j, h.length - j + 3);
80
+ const sliceStart = h.length - j;
81
+ i = h.slice(sliceStart, sliceStart + 3);
80
82
  f[0] = `${d}${i}${f[0]}`;
81
83
  }
82
84
  j = h.substr(0, h.length % 3 === 0 ? 3 : h.length % 3);
@@ -141,7 +143,7 @@ exports.default = {
141
143
  * Returns how many decimals to display (used for currencies).
142
144
  *
143
145
  * @param {Number} rate
144
- * @return {Number}
146
+ * @returns {Number}
145
147
  */
146
148
  getDisplayDecimals(rate) {
147
149
  if (rate % 1 === 0) {
@@ -173,7 +175,8 @@ exports.default = {
173
175
  * @returns {number} The amount of tax
174
176
  */
175
177
  calculateTaxFromPercentage(total, percentage) {
176
- const divisor = percentage ? str_1.default.percentageStringToNumber(percentage) / 100 + 1 : 1;
178
+ const percentageAsDecimal = str_1.default.percentageStringToNumber(percentage) / 100;
179
+ const divisor = percentage ? percentageAsDecimal + 1 : 1;
177
180
  return this.calculateTaxFromDivisor(total, divisor);
178
181
  },
179
182
  /**
@@ -185,7 +188,8 @@ exports.default = {
185
188
  * @returns {number} The amount of tax
186
189
  */
187
190
  calculateTaxFromDivisor(total, divisor) {
188
- return parseInt(Math.round(total - total / divisor), 10);
191
+ const amountExcludingTax = total / divisor;
192
+ return parseInt(Math.round(total - amountExcludingTax), 10);
189
193
  },
190
194
  },
191
195
  };
@@ -5,7 +5,7 @@
5
5
  *
6
6
  * @param {String} eventName Name of the event to listen to
7
7
  * @param {Function} callback Function to fire
8
- * @constructor
8
+ * @class
9
9
  */
10
10
  export default function _default(eventName: string, callback: Function): {
11
11
  subscribe(scope: any): void;
@@ -19,7 +19,7 @@ export default class _default {
19
19
  *
20
20
  * @param {String} eventName Name of the event to listen to
21
21
  * @param {Function} callback Function to fire
22
- * @constructor
22
+ * @class
23
23
  */
24
24
  constructor(eventName: string, callback: Function);
25
25
  }
package/dist/PageEvent.js CHANGED
@@ -12,7 +12,7 @@ const PubSub_1 = __importDefault(require("./PubSub"));
12
12
  *
13
13
  * @param {String} eventName Name of the event to listen to
14
14
  * @param {Function} callback Function to fire
15
- * @constructor
15
+ * @class
16
16
  */
17
17
  function default_1(eventName, callback) {
18
18
  let id = null;
package/dist/PubSub.js CHANGED
@@ -51,7 +51,7 @@ let counter = 0;
51
51
  /**
52
52
  * Create a unique ID for each event subscriber
53
53
  * @param {String} eventName Name of the event to listen to
54
- * @return {String} unique ID
54
+ * @returns {String} unique ID
55
55
  */
56
56
  const generateID = (eventName) => {
57
57
  counter++;
@@ -60,7 +60,7 @@ const generateID = (eventName) => {
60
60
  /**
61
61
  * Find the name of the event from the ID
62
62
  * @param {string} eventID
63
- * @return {String}
63
+ * @returns {String}
64
64
  */
65
65
  const extractEventName = (eventID = '') => eventID.substring(0, eventID.indexOf('@#@'));
66
66
  const PubSubModule = {
@@ -82,12 +82,12 @@ const PubSubModule = {
82
82
  // When debugging, we just need to know who called PubSub.publish (so, all next elements in the stack)
83
83
  Log_1.default.hmmm('Error published', 0, { tplt: param.tplt, stackTrace: new Error().stack.split(' at ').slice(2) });
84
84
  }
85
- eventIDs.forEach((eventID) => {
85
+ for (const eventID of eventIDs) {
86
86
  const subscriber = eventMap[eventName][eventID];
87
87
  if (subscriber) {
88
88
  subscriber.callback.call(subscriber.scope, param);
89
89
  }
90
- });
90
+ }
91
91
  return this;
92
92
  },
93
93
  /**
@@ -113,7 +113,7 @@ const PubSubModule = {
113
113
  * @param {String} eventName Name of the event to listen
114
114
  * @param {Function} optionalCallback Callback function to call when event occur
115
115
  * @param {Object} optionalScope
116
- * @return {String} event identifier that should be used to unsubscribe
116
+ * @returns {String} event identifier that should be used to unsubscribe
117
117
  */
118
118
  subscribe(eventName, optionalCallback, optionalScope) {
119
119
  if (!eventName) {
@@ -138,12 +138,12 @@ const PubSubModule = {
138
138
  */
139
139
  unsubscribe(bindID) {
140
140
  const IDs = Array.isArray(bindID) ? bindID : [bindID];
141
- IDs.forEach((id) => {
141
+ for (const id of IDs) {
142
142
  const eventName = extractEventName(id);
143
143
  if ((0, has_1.default)(eventMap, `${eventName}.${id}`)) {
144
144
  delete eventMap[eventName][id];
145
145
  }
146
- });
146
+ }
147
147
  },
148
148
  };
149
149
  exports.default = Utils.isWindowAvailable() && window.PubSub ? window.PubSub : PubSubModule;
@@ -1,71 +1,8 @@
1
- export default class ReportHistoryStore {
2
- constructor(API: any, PubSub: any);
3
- API: any;
4
- /**
5
- * Main report history cache
6
- * Map of reportIDs with value of report history items array
7
- */
8
- cache: {};
9
- /**
10
- * PubSub instance used for the bindCacheClearingEvents method.
11
- *
12
- * Since Mobile and Web use different instances of PubSub, this is unfortunately necessary to subscribe to
13
- * events in both code bases.
14
- */
15
- PubSub: any;
16
- /**
17
- * Filters out actions we never want to display on web or mobile.
18
- *
19
- * @param {Object[]} historyItems
20
- *
21
- * @returns {Object[]}
22
- */
23
- filterHiddenActions: (historyItems: Object[]) => Object[];
24
- /**
25
- * Merges history items into the cache and creates it if it doesn't yet exist.
26
- *
27
- * @param {Number} reportID
28
- * @param {Object[]} newHistory
29
- */
30
- mergeItems(reportID: number, newHistory: Object[]): void;
31
- /**
32
- * Merges history items into the cache and creates it if it doesn't yet exist.
33
- *
34
- * @param {Number} reportID
35
- * @param {Object[]} newHistory
36
- */
37
- mergeHistoryByTimestamp(reportID: number, newHistory: Object[]): void;
38
- /**
39
- * Merges history items by reportActionID into the cache and creates it if it doesn't yet exist.
40
- *
41
- * @param {Number} reportID
42
- * @param {Object[]} newHistory
43
- */
44
- mergeHistoryByReportActionID(reportID: number, newHistory: Object[]): void;
45
- /**
46
- * Gets the history.
47
- *
48
- * @param {Number} reportID
49
- * @param {Boolean} ignoreCache
50
- *
51
- * @returns {Deferred}
52
- */
53
- get(reportID: number, ignoreCache: boolean): Deferred;
54
- /**
55
- * Gets the history. This flow does not depend on the deprecated sequence number in report actions.
56
- *
57
- * @param {Number} reportID
58
- * @param {Boolean} ignoreCache
59
- *
60
- * @returns {Deferred}
61
- */
62
- getFlatHistory(reportID: number, ignoreCache: boolean): Deferred;
63
- /**
64
- * Gets the history from the cache if it exists. Otherwise fully loads the history.
65
- *
66
- * @param {Number} reportID
67
- *
68
- * @return {Deferrred}
69
- */
70
- getFromCache(reportID: number): Deferrred;
71
- }
1
+ /**
2
+ * Creates a report history store with platform-specific API and PubSub implementations.
3
+ *
4
+ * @param {Object} API
5
+ * @param {Object} PubSub
6
+ * @returns {Object}
7
+ */
8
+ export default function ReportHistoryStore(API: Object, PubSub: Object): Object;