@onehat/data 1.8.1 → 1.8.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.
@@ -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.1",
3
+ "version": "1.8.4",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
package/src/Entity.js CHANGED
@@ -331,6 +331,7 @@ class Entity extends EventEmitter {
331
331
  if (this.isDeleted) {
332
332
  this.undelete();
333
333
  }
334
+ this.markStaged(false);
334
335
  this.setLastModified();
335
336
 
336
337
  this.emit('reset', this._proxy);
@@ -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
  };
@@ -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