@onehat/data 1.4.12 → 1.4.13

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.
@@ -60,6 +60,28 @@ describe('CurrencyProperty', function() {
60
60
  expect(formatted).to.be.eq('$1,234.56');
61
61
  });
62
62
 
63
+ it('omitZeros', function() {
64
+ this.property.setValue('1234.56');
65
+ expect(this.property.displayValue).to.be.eq('$1,234.56');
66
+
67
+ this.property.setValue('1234.50');
68
+ expect(this.property.displayValue).to.be.eq('$1,234.50');
69
+
70
+ this.property.setValue('1234.00');
71
+ expect(this.property.displayValue).to.be.eq('$1,234.00');
72
+
73
+ this.property.omitZeros = true;
74
+
75
+ this.property.setValue('1234.56');
76
+ expect(this.property.displayValue).to.be.eq('$1,234.56');
77
+
78
+ this.property.setValue('1234.50');
79
+ expect(this.property.displayValue).to.be.eq('$1,234.50');
80
+
81
+ this.property.setValue('1234.00');
82
+ expect(this.property.displayValue).to.be.eq('$1,234');
83
+ });
84
+
63
85
  it('submitValue', function() {
64
86
  this.property.setValue(123.156);
65
87
  const formatted = this.property.submitValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onehat/data",
3
- "version": "1.4.12",
3
+ "version": "1.4.13",
4
4
  "description": "JS data modeling package with adapters for many storage mediums.",
5
5
  "main": "src/index.js",
6
6
  "type": "module",
@@ -26,6 +26,7 @@ export default class CurrencyProperty extends Property {
26
26
  },
27
27
  submitAsString: true, // NOTE, we want to use the accounting.toFixed() method by default
28
28
  defaultValue: 0.00,
29
+ omitZeros: false, // Should we omit any .00 at the end?
29
30
  };
30
31
 
31
32
  _.merge(this, defaults, config);
@@ -45,7 +46,12 @@ export default class CurrencyProperty extends Property {
45
46
  if (this.isDestroyed) {
46
47
  throw Error('this.getDisplayValue is no longer valid. Property has been destroyed.');
47
48
  }
48
- return accounting.formatMoney(this.parsedValue, this.displayOptions);
49
+
50
+ let ret = accounting.formatMoney(this.parsedValue, this.displayOptions)
51
+ if (this.omitZeros && ret.match(/\.00$/)) {
52
+ ret = ret.replace(/\.00$/, '');
53
+ }
54
+ return ret;
49
55
  }
50
56
 
51
57
  getSubmitValue = () => {