@etsoo/shared 1.0.88 → 1.0.89

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.
@@ -11,6 +11,7 @@ test('Tests for all', () => {
11
11
  expect(StorageUtils.getSessionData('string1', '')).toBe('');
12
12
  expect(StorageUtils.getSessionData('boolean', false)).toBe(true);
13
13
  expect(StorageUtils.getSessionData('number', 0)).toBe(3.14);
14
+ expect(StorageUtils.getSessionData('number1', 0)).toBe(0);
14
15
  expect(StorageUtils.getSessionData('test', {})).toHaveProperty('id', 123);
15
16
  });
16
17
 
@@ -107,6 +107,7 @@ test('Tests for parseString', () => {
107
107
  expect(Utils.parseString<boolean>('')).toBeUndefined();
108
108
  expect(Utils.parseString<number>(undefined)).toBeUndefined();
109
109
  expect(Utils.parseString('3.14', 0)).toBe(3.14);
110
+ expect(Utils.parseString(null, 0)).toBe(0);
110
111
  expect(Utils.parseString('2021/4/13', new Date())).toStrictEqual(
111
112
  new Date('2021/4/13')
112
113
  );
@@ -0,0 +1,16 @@
1
+ import { WindowStorage } from '../src/storage/WindowStorage';
2
+
3
+ // Arrange
4
+ const storage = new WindowStorage([], (_field, data, _index) => data);
5
+
6
+ test('Tests for getInstanceCount', () => {
7
+ expect(storage.getInstanceCount()).toBe(0);
8
+ });
9
+
10
+ test('Tests for updateInstanceCount / getInstanceCount', () => {
11
+ // Current index -1
12
+ storage.updateInstanceCount(true);
13
+
14
+ // Always make sure it starts with 0
15
+ expect(storage.getInstanceCount()).toBe(0);
16
+ });
@@ -94,7 +94,11 @@ class WindowStorage {
94
94
  * @returns Current instance count
95
95
  */
96
96
  getInstanceCount() {
97
- return this.getData(this.instanceCountField, 0, true);
97
+ const count = this.getData(this.instanceCountField, 0, true);
98
+ // Make sure starting from 0
99
+ if (count < 0)
100
+ return 0;
101
+ return count;
98
102
  }
99
103
  /**
100
104
  * Update instance count
@@ -91,7 +91,11 @@ export class WindowStorage {
91
91
  * @returns Current instance count
92
92
  */
93
93
  getInstanceCount() {
94
- return this.getData(this.instanceCountField, 0, true);
94
+ const count = this.getData(this.instanceCountField, 0, true);
95
+ // Make sure starting from 0
96
+ if (count < 0)
97
+ return 0;
98
+ return count;
95
99
  }
96
100
  /**
97
101
  * Update instance count
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.0.88",
3
+ "version": "1.0.89",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -127,7 +127,10 @@ export class WindowStorage implements IStorage {
127
127
  * @returns Current instance count
128
128
  */
129
129
  getInstanceCount() {
130
- return this.getData(this.instanceCountField, 0, true);
130
+ const count = this.getData(this.instanceCountField, 0, true);
131
+ // Make sure starting from 0
132
+ if (count < 0) return 0;
133
+ return count;
131
134
  }
132
135
 
133
136
  /**