@etsoo/shared 1.2.54 → 1.2.55

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.
@@ -1,79 +1,79 @@
1
- import { EHistory, EHistoryNavigateEvent } from '../src/types/EHistory';
1
+ import { EHistory, EHistoryNavigateEvent } from "../src/types/EHistory";
2
2
 
3
3
  // Extended for tests
4
4
  class LHistory extends EHistory<number> {}
5
5
 
6
- test('Tests for history', () => {
7
- const history = new LHistory();
8
- expect(history.index).toBe(-1);
9
- history.pushState(1);
10
- expect(history.getStatus()).toStrictEqual([false, false]);
11
- history.pushState(2);
12
- history.pushState(3);
13
- expect(history.getStatus()).toStrictEqual([true, false]);
14
- expect(history.states).toStrictEqual([1, 2, 3]);
15
- expect(history.index).toBe(2);
16
- history.back();
17
- expect(history.getStatus()).toStrictEqual([true, true]);
18
- history.pushState(4);
19
- expect(history.index).toBe(2);
20
- expect(history.states).toStrictEqual([1, 2, 4]);
21
- history.go(-2);
22
- expect(history.state).toBe(1);
23
- history.forward();
24
- expect(history.index).toBe(1);
25
- history.replaceState(0);
26
- expect(history.state).toBe(0);
27
- history.clear();
28
- expect(history.length).toBe(0);
6
+ test("Tests for history", () => {
7
+ const history = new LHistory();
8
+ expect(history.index).toBe(-1);
9
+ history.pushState(1);
10
+ expect(history.getStatus()).toStrictEqual([false, false]);
11
+ history.pushState(2);
12
+ history.pushState(3);
13
+ expect(history.getStatus()).toStrictEqual([true, false]);
14
+ expect(history.states).toStrictEqual([1, 2, 3]);
15
+ expect(history.index).toBe(2);
16
+ history.back();
17
+ expect(history.getStatus()).toStrictEqual([true, true]);
18
+ history.pushState(4);
19
+ expect(history.index).toBe(2);
20
+ expect(history.states).toStrictEqual([1, 2, 4]);
21
+ history.go(-2);
22
+ expect(history.state).toBe(1);
23
+ history.forward();
24
+ expect(history.index).toBe(1);
25
+ history.replaceState(0);
26
+ expect(history.state).toBe(0);
27
+ history.clear();
28
+ expect(history.length).toBe(0);
29
29
  });
30
30
 
31
- test('Tests for events', () => {
32
- const navigatorFn = jest.fn();
33
- const navigatorStopFn = jest.fn((event: EHistoryNavigateEvent) => {
34
- event.stopImmediatePropagation();
35
- });
36
- const clearFn = jest.fn();
37
- const pushFn = jest.fn();
38
- const replaceFn = jest.fn();
31
+ test("Tests for events", () => {
32
+ const navigatorFn = jest.fn();
33
+ const navigatorStopFn = jest.fn((event: EHistoryNavigateEvent) => {
34
+ event.stopImmediatePropagation();
35
+ });
36
+ const clearFn = jest.fn();
37
+ const pushFn = jest.fn();
38
+ const replaceFn = jest.fn();
39
39
 
40
- const history = new LHistory(3);
40
+ const history = new LHistory(3);
41
41
 
42
- history.on({
43
- clear: clearFn,
44
- push: pushFn,
45
- replace: replaceFn,
46
- navigate: navigatorFn
47
- });
48
- history.on('navigate', navigatorFn);
49
- history.on('navigate', navigatorFn, { capture: true, once: true });
42
+ history.on({
43
+ clear: clearFn,
44
+ push: pushFn,
45
+ replace: replaceFn,
46
+ navigate: navigatorFn
47
+ });
48
+ history.on("navigate", navigatorFn);
49
+ history.on("navigate", navigatorFn, { capture: true, once: true });
50
50
 
51
- history.clear();
52
- expect(clearFn).toHaveBeenCalled();
51
+ history.clear();
52
+ expect(clearFn).toHaveBeenCalled();
53
53
 
54
- history.pushState(1);
55
- expect(pushFn).toHaveBeenCalled();
54
+ history.pushState(1);
55
+ expect(pushFn).toHaveBeenCalled();
56
56
 
57
- history.replaceState(11);
58
- expect(replaceFn).toHaveBeenCalled();
57
+ history.replaceState(11);
58
+ expect(replaceFn).toHaveBeenCalled();
59
59
 
60
- history.pushState(2);
61
- history.back();
62
- expect(navigatorFn).toHaveBeenCalledTimes(3);
60
+ history.pushState(2);
61
+ history.back();
62
+ expect(navigatorFn).toHaveBeenCalledTimes(3);
63
63
 
64
- history.forward();
65
- // Once handler was removed
66
- expect(navigatorFn).toHaveBeenCalledTimes(5);
64
+ history.forward();
65
+ // Once handler was removed
66
+ expect(navigatorFn).toHaveBeenCalledTimes(5);
67
67
 
68
- history.on('navigate', navigatorStopFn, { capture: true });
69
- history.go(-1);
70
- expect(navigatorStopFn).toHaveBeenCalled();
68
+ history.on("navigate", navigatorStopFn, { capture: true });
69
+ history.go(-1);
70
+ expect(navigatorStopFn).toHaveBeenCalled();
71
71
 
72
- // Previous handler stopped propagation
73
- expect(navigatorFn).toHaveBeenCalledTimes(5);
72
+ // Previous handler stopped propagation
73
+ expect(navigatorFn).toHaveBeenCalledTimes(5);
74
74
 
75
- history.pushState(3);
76
- history.pushState(4);
77
- history.pushState(5);
78
- expect(history.length).toBe(3);
75
+ history.pushState(3);
76
+ history.pushState(4);
77
+ history.pushState(5);
78
+ expect(history.length).toBe(3);
79
79
  });
@@ -1,56 +1,56 @@
1
- import { ExtendUtils } from '../src/ExtendUtils';
1
+ import { ExtendUtils } from "../src/ExtendUtils";
2
2
 
3
- test('Tests for applyMixins', () => {
4
- class a {
5
- m() {
6
- return 1;
7
- }
3
+ test("Tests for applyMixins", () => {
4
+ class a {
5
+ m() {
6
+ return 1;
8
7
  }
9
- class b {
10
- m(id: number) {
11
- return id;
12
- }
8
+ }
9
+ class b {
10
+ m(id: number) {
11
+ return id;
13
12
  }
14
- class c {
15
- m2() {
16
- return 'hello';
17
- }
13
+ }
14
+ class c {
15
+ m2() {
16
+ return "hello";
18
17
  }
18
+ }
19
19
 
20
- interface a extends b, c {}
21
- ExtendUtils.applyMixins(a, [b, c]);
22
- const item = new a();
23
- expect(item.m2()).toBe('hello');
20
+ interface a extends b, c {}
21
+ ExtendUtils.applyMixins(a, [b, c]);
22
+ const item = new a();
23
+ expect(item.m2()).toBe("hello");
24
24
  });
25
25
 
26
- test('Tests for delayedExecutor', () => {
27
- // Arrange
28
- const f = jest.fn();
26
+ test("Tests for delayedExecutor", () => {
27
+ // Arrange
28
+ const f = jest.fn();
29
29
 
30
- const e = ExtendUtils.delayedExecutor(f, 50);
30
+ const e = ExtendUtils.delayedExecutor(f, 50);
31
31
 
32
- e.call(1, false, 'a');
33
- expect(e.isRunning()).toBeTruthy();
32
+ e.call(1, false, "a");
33
+ expect(e.isRunning()).toBeTruthy();
34
34
 
35
- e.call(2, true, 'b');
35
+ e.call(2, true, "b");
36
36
 
37
- expect(f).toHaveBeenCalledTimes(0);
38
- e.clear();
39
- expect(e.isRunning()).toBeFalsy();
37
+ expect(f).toHaveBeenCalledTimes(0);
38
+ e.clear();
39
+ expect(e.isRunning()).toBeFalsy();
40
40
  });
41
41
 
42
- test('Tests for promiseHandler', async () => {
43
- // Arrange
44
- const p = (id: number) => {
45
- return new Promise((resolve, reject) => {
46
- if (id > 0) resolve(id);
47
- else reject(new Error(`Id ${id} Error`));
48
- });
49
- };
42
+ test("Tests for promiseHandler", async () => {
43
+ // Arrange
44
+ const p = (id: number) => {
45
+ return new Promise((resolve, reject) => {
46
+ if (id > 0) resolve(id);
47
+ else reject(new Error(`Id ${id} Error`));
48
+ });
49
+ };
50
50
 
51
- const handler1 = await ExtendUtils.promiseHandler(p(12));
52
- expect(handler1[0]).toBe(12);
51
+ const handler1 = await ExtendUtils.promiseHandler(p(12));
52
+ expect(handler1[0]).toBe(12);
53
53
 
54
- const handler2 = await ExtendUtils.promiseHandler(p(-1));
55
- expect(handler2[1]).toHaveProperty('message', 'Id -1 Error');
54
+ const handler2 = await ExtendUtils.promiseHandler(p(-1));
55
+ expect(handler2[1]).toHaveProperty("message", "Id -1 Error");
56
56
  });
@@ -1,18 +1,18 @@
1
- import { Keyboard } from '../src/Keyboard';
1
+ import { Keyboard } from "../src/Keyboard";
2
2
 
3
- test('Tests for KeyboardEvent.key', () => {
4
- const event = new KeyboardEvent('keydown', { key: ' ' });
5
- const callback = (e: KeyboardEvent) => {
6
- expect(e.key).toBe(Keyboard.Keys.Space);
7
- };
8
- window.addEventListener('keydown', callback);
9
- window.dispatchEvent(event);
10
- window.removeEventListener('keydown', callback);
3
+ test("Tests for KeyboardEvent.key", () => {
4
+ const event = new KeyboardEvent("keydown", { key: " " });
5
+ const callback = (e: KeyboardEvent) => {
6
+ expect(e.key).toBe(Keyboard.Keys.Space);
7
+ };
8
+ window.addEventListener("keydown", callback);
9
+ window.dispatchEvent(event);
10
+ window.removeEventListener("keydown", callback);
11
11
  });
12
12
 
13
- test('Tests for isTypingContent', () => {
14
- expect(Keyboard.isTypingContent(Keyboard.Keys.A)).toBeTruthy();
15
- expect(Keyboard.isTypingContent(Keyboard.Keys.Ampersand)).toBeTruthy();
16
- expect(Keyboard.isTypingContent(Keyboard.Keys.Shift)).toBeFalsy();
17
- expect(Keyboard.isTypingContent(Keyboard.Keys.PrintScreen)).toBeFalsy();
13
+ test("Tests for isTypingContent", () => {
14
+ expect(Keyboard.isTypingContent(Keyboard.Keys.A)).toBeTruthy();
15
+ expect(Keyboard.isTypingContent(Keyboard.Keys.Ampersand)).toBeTruthy();
16
+ expect(Keyboard.isTypingContent(Keyboard.Keys.Shift)).toBeFalsy();
17
+ expect(Keyboard.isTypingContent(Keyboard.Keys.PrintScreen)).toBeFalsy();
18
18
  });
@@ -1,54 +1,52 @@
1
- import { NumberUtils } from '../src/NumberUtils';
1
+ import { NumberUtils } from "../src/NumberUtils";
2
2
 
3
- test('Tests for format', () => {
4
- expect(NumberUtils.format(12.4, 'zh-CN', { style: 'percent' })).toBe(
5
- '1,240%'
6
- );
3
+ test("Tests for format", () => {
4
+ expect(NumberUtils.format(12.4, "zh-CN", { style: "percent" })).toBe(
5
+ "1,240%"
6
+ );
7
7
  });
8
8
 
9
- test('Tests for formatMoney', () => {
10
- expect(NumberUtils.formatMoney(1282.4, 'CNY', 'zh-CN')).toBe('¥1,282.40');
11
- expect(NumberUtils.formatMoney(1282, 'CNY', 'zh-CN', true)).toBe('¥1,282');
9
+ test("Tests for formatMoney", () => {
10
+ expect(NumberUtils.formatMoney(1282.4, "CNY", "zh-CN")).toBe("¥1,282.40");
11
+ expect(NumberUtils.formatMoney(1282, "CNY", "zh-CN", true)).toBe("¥1,282");
12
12
  });
13
13
 
14
- test('Tests for getCurrencySymbol', () => {
15
- expect(NumberUtils.getCurrencySymbol('CNY')).toBe('¥');
16
- expect(NumberUtils.getCurrencySymbol('USD')).toBe('$');
14
+ test("Tests for getCurrencySymbol", () => {
15
+ expect(NumberUtils.getCurrencySymbol("CNY")).toBe("¥");
16
+ expect(NumberUtils.getCurrencySymbol("USD")).toBe("$");
17
17
 
18
- // When locale = 'en-US' will be failed with '$'
19
- expect(NumberUtils.getCurrencySymbol('USD', 'symbol', 'zh-CN')).toBe('US$');
20
- expect(NumberUtils.getCurrencySymbol('CNY', 'name', 'zh-CN')).toBe(
21
- '人民币'
22
- );
18
+ // When locale = 'en-US' will be failed with '$'
19
+ expect(NumberUtils.getCurrencySymbol("USD", "symbol", "zh-CN")).toBe("US$");
20
+ expect(NumberUtils.getCurrencySymbol("CNY", "name", "zh-CN")).toBe("人民币");
23
21
  });
24
22
 
25
- test('Tests for parse', () => {
26
- expect(NumberUtils.parse('123')).toBe(123);
27
- expect(NumberUtils.parse(Object(123))).toBe(123);
28
- expect(NumberUtils.parse('a')).toBeUndefined();
29
- expect(NumberUtils.parse('a', 0)).toBe(0);
30
- expect(NumberUtils.parse('')).toBeUndefined();
31
- expect(NumberUtils.parse('', -1)).toBe(-1);
23
+ test("Tests for parse", () => {
24
+ expect(NumberUtils.parse("123")).toBe(123);
25
+ expect(NumberUtils.parse(Object(123))).toBe(123);
26
+ expect(NumberUtils.parse("a")).toBeUndefined();
27
+ expect(NumberUtils.parse("a", 0)).toBe(0);
28
+ expect(NumberUtils.parse("")).toBeUndefined();
29
+ expect(NumberUtils.parse("", -1)).toBe(-1);
32
30
  });
33
31
 
34
- test('Tests for parseWithUnit', () => {
35
- expect(NumberUtils.parseWithUnit('8px')).toStrictEqual([8, 'px']);
36
- expect(NumberUtils.parseWithUnit('16')).toStrictEqual([16, '']);
37
- expect(NumberUtils.parseWithUnit('a16')).toBeUndefined();
32
+ test("Tests for parseWithUnit", () => {
33
+ expect(NumberUtils.parseWithUnit("8px")).toStrictEqual([8, "px"]);
34
+ expect(NumberUtils.parseWithUnit("16")).toStrictEqual([16, ""]);
35
+ expect(NumberUtils.parseWithUnit("a16")).toBeUndefined();
38
36
  });
39
37
 
40
- test('Tests for toExact', () => {
41
- // 0.7000000000000001
42
- const result = 0.8 - 0.1;
43
- expect(result).not.toBe(0.7);
44
- expect(result.toExact()).toBe(0.7);
38
+ test("Tests for toExact", () => {
39
+ // 0.7000000000000001
40
+ const result = 0.8 - 0.1;
41
+ expect(result).not.toBe(0.7);
42
+ expect(result.toExact()).toBe(0.7);
45
43
  });
46
44
 
47
- test('Tests for toFileSize', () => {
48
- expect(NumberUtils.formatFileSize(1551859712)).toBe('1.45 GB');
49
- expect(NumberUtils.formatFileSize(1551859712, 1)).toBe('1.4 GB');
50
- expect(NumberUtils.formatFileSize(5000)).toBe('4.88 KB');
51
- expect(NumberUtils.formatFileSize(999949)).toBe('976.51 KB');
52
- expect(NumberUtils.formatFileSize(1125000)).toBe('1.07 MB');
53
- expect(NumberUtils.formatFileSize(1125000, 1)).toBe('1.1 MB');
45
+ test("Tests for toFileSize", () => {
46
+ expect(NumberUtils.formatFileSize(1551859712)).toBe("1.45 GB");
47
+ expect(NumberUtils.formatFileSize(1551859712, 1)).toBe("1.4 GB");
48
+ expect(NumberUtils.formatFileSize(5000)).toBe("4.88 KB");
49
+ expect(NumberUtils.formatFileSize(999949)).toBe("976.51 KB");
50
+ expect(NumberUtils.formatFileSize(1125000)).toBe("1.07 MB");
51
+ expect(NumberUtils.formatFileSize(1125000, 1)).toBe("1.1 MB");
54
52
  });
@@ -1,35 +1,35 @@
1
- import { StorageUtils } from '../src/StorageUtils';
1
+ import { StorageUtils } from "../src/StorageUtils";
2
2
 
3
- test('Tests for all', () => {
4
- // Arrange
5
- StorageUtils.setSessionData('string', 'test');
6
- StorageUtils.setSessionData('boolean', true);
7
- StorageUtils.setSessionData('number', 3.14);
8
- StorageUtils.setSessionData('test', { id: 123, name: 'test' });
3
+ test("Tests for all", () => {
4
+ // Arrange
5
+ StorageUtils.setSessionData("string", "test");
6
+ StorageUtils.setSessionData("boolean", true);
7
+ StorageUtils.setSessionData("number", 3.14);
8
+ StorageUtils.setSessionData("test", { id: 123, name: "test" });
9
9
 
10
- const array = StorageUtils.getSessionData<string[]>('array', []);
11
- array.push('new');
12
- StorageUtils.setSessionData('array', array);
10
+ const array = StorageUtils.getSessionData<string[]>("array", []);
11
+ array.push("new");
12
+ StorageUtils.setSessionData("array", array);
13
13
 
14
- expect(StorageUtils.getSessionData<string>('string')).toBe('test');
15
- expect(StorageUtils.getSessionData('string1', '')).toBe('');
16
- expect(StorageUtils.getSessionData('boolean', false)).toBe(true);
17
- expect(StorageUtils.getSessionData('number', 0)).toBe(3.14);
18
- expect(StorageUtils.getSessionData('number1', 0)).toBe(0);
19
- expect(StorageUtils.getSessionData('test', {})).toHaveProperty('id', 123);
20
- expect(StorageUtils.getSessionData<string[]>('array')).toEqual(array);
14
+ expect(StorageUtils.getSessionData<string>("string")).toBe("test");
15
+ expect(StorageUtils.getSessionData("string1", "")).toBe("");
16
+ expect(StorageUtils.getSessionData("boolean", false)).toBe(true);
17
+ expect(StorageUtils.getSessionData("number", 0)).toBe(3.14);
18
+ expect(StorageUtils.getSessionData("number1", 0)).toBe(0);
19
+ expect(StorageUtils.getSessionData("test", {})).toHaveProperty("id", 123);
20
+ expect(StorageUtils.getSessionData<string[]>("array")).toEqual(array);
21
21
  });
22
22
 
23
- test('Tests for getLocalObject', () => {
24
- StorageUtils.setLocalData('test', { id: 123, name: 'test' });
25
- const data = StorageUtils.getLocalObject<{ id: number }>('test');
26
- expect(data?.id).toBe(123);
27
- expect(data).toHaveProperty('name', 'test');
23
+ test("Tests for getLocalObject", () => {
24
+ StorageUtils.setLocalData("test", { id: 123, name: "test" });
25
+ const data = StorageUtils.getLocalObject<{ id: number }>("test");
26
+ expect(data?.id).toBe(123);
27
+ expect(data).toHaveProperty("name", "test");
28
28
  });
29
29
 
30
- test('Tests for getSessionObject', () => {
31
- StorageUtils.setSessionData('test', { id: 123, name: 'test' });
32
- const data = StorageUtils.getSessionObject<{ id: number }>('test');
33
- expect(data?.id).toBe(123);
34
- expect(data).toHaveProperty('name', 'test');
30
+ test("Tests for getSessionObject", () => {
31
+ StorageUtils.setSessionData("test", { id: 123, name: "test" });
32
+ const data = StorageUtils.getSessionObject<{ id: number }>("test");
33
+ expect(data?.id).toBe(123);
34
+ expect(data).toHaveProperty("name", "test");
35
35
  });