@onehat/data 1.8.2 → 1.8.5

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.
@@ -21,4 +21,26 @@ describe('PercentProperty', function() {
21
21
  expect(this.property.displayValue).to.be.eq('12.325%');
22
22
  });
23
23
 
24
+ it('omitZeros', function() {
25
+ this.property.setValue('1234.56');
26
+ expect(this.property.displayValue).to.be.eq('1234.560%');
27
+
28
+ this.property.setValue('1234.50');
29
+ expect(this.property.displayValue).to.be.eq('1234.500%');
30
+
31
+ this.property.setValue('1234.00');
32
+ expect(this.property.displayValue).to.be.eq('1234.000%');
33
+
34
+ this.property.omitZeros = true;
35
+
36
+ this.property.setValue('1234.56');
37
+ expect(this.property.displayValue).to.be.eq('1234.56%');
38
+
39
+ this.property.setValue('1234.50');
40
+ expect(this.property.displayValue).to.be.eq('1234.5%');
41
+
42
+ this.property.setValue('1234.00');
43
+ expect(this.property.displayValue).to.be.eq('1234%');
44
+ });
45
+
24
46
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.8.2",
3
+ "version": "1.8.5",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -2,18 +2,29 @@
2
2
 
3
3
  import FloatProperty from './Float';
4
4
  import Formatters from '../Util/Formatters';
5
+ import _ from 'lodash';
5
6
 
6
7
  /**
7
8
  * Class represents a Property that stores a percentage value.
8
9
  * @extends PercentProperty
9
10
  */
10
11
  export default class PercentIntProperty extends FloatProperty {
12
+
13
+ constructor(config = {}) {
14
+ super(...arguments);
15
+
16
+ const defaults = {
17
+ omitZeros: false, // Should we omit any .00 at the end?
18
+ };
19
+
20
+ _.merge(this, defaults, config);
21
+ }
11
22
 
12
23
  getDisplayValue = () => {
13
24
  if (this.isDestroyed) {
14
25
  throw Error('this.getDisplayValue is no longer valid. Property has been destroyed.');
15
26
  }
16
- return Formatters.FormatPercentInt(this.parsedValue);
27
+ return Formatters.FormatPercentInt(this.parsedValue, this.omitZeros);
17
28
  }
18
29
 
19
30
  };
@@ -291,6 +291,36 @@ class OneBuildRepository extends AjaxRepository {
291
291
  });
292
292
  }
293
293
 
294
+ forgotPassword = (email = null, username = null) => {
295
+ const data = {
296
+ url: 'forgotPassword',
297
+ data: qs.stringify({
298
+ email,
299
+ username,
300
+ }),
301
+ method: 'POST',
302
+ baseURL: this.api.baseURL,
303
+ };
304
+
305
+ if (this.debugMode) {
306
+ console.log('forgotPassword', data);
307
+ }
308
+
309
+ return this.axios(data)
310
+ .then((result) => {
311
+ if (this.debugMode) {
312
+ console.log('forgotPassword result', result);
313
+ }
314
+
315
+ const response = result.data;
316
+ if (!response.success) {
317
+ throw new Error(response.data);
318
+ }
319
+
320
+ return response;
321
+ });
322
+ }
323
+
294
324
  }
295
325
 
296
326
 
@@ -168,10 +168,13 @@ class Formatters {
168
168
  return value.toFixed(precision) + '%';
169
169
  }
170
170
 
171
- static FormatPercentInt = (str) => {
171
+ static FormatPercentInt = (str, omitZeros = false) => {
172
172
  if (_.isNil(str)) {
173
173
  return str;
174
174
  }
175
+ if (omitZeros) {
176
+ str = parseFloat(str).toString();
177
+ }
175
178
  return '' + str + '%';
176
179
  }
177
180