@etsoo/shared 1.2.37 → 1.2.40

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.
@@ -17,6 +17,27 @@ test('Tests for IdLabelType', () => {
17
17
  expect(item).toEqual(itemCopy);
18
18
  });
19
19
 
20
+ test('Tests for Bigint Type', () => {
21
+ type BigintType = {
22
+ id: bigint;
23
+ label: string;
24
+ };
25
+
26
+ const item: BigintType = {
27
+ id: 9007199254740999n,
28
+ label: 'Etsoo'
29
+ };
30
+
31
+ const json = JSON.stringify(item);
32
+ expect(json).toBe('{"id":"9007199254740999n","label":"Etsoo"}');
33
+
34
+ const itemBack = JSON.parse(
35
+ json,
36
+ DataTypes.jsonBigintReceiver('id')
37
+ ) as BigintType;
38
+ expect(itemBack.id).toBe(9007199254740999n);
39
+ });
40
+
20
41
  test('Tests for convert', () => {
21
42
  expect(DataTypes.convert('5', 0)).toStrictEqual(5);
22
43
  expect(
@@ -1,5 +1,15 @@
1
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);
11
+ });
12
+
3
13
  test('Tests for isTypingContent', () => {
4
14
  expect(Keyboard.isTypingContent(Keyboard.Keys.A)).toBeTruthy();
5
15
  expect(Keyboard.isTypingContent(Keyboard.Keys.Ampersand)).toBeTruthy();
@@ -3,6 +3,11 @@
3
3
  * Narrow case, uses StringRecord
4
4
  * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
5
  */
6
+ declare global {
7
+ interface BigInt {
8
+ toJSON(): String;
9
+ }
10
+ }
6
11
  /**
7
12
  * Interface data types
8
13
  */
@@ -403,6 +408,12 @@ export declare namespace DataTypes {
403
408
  * https://stackoverflow.com/questions/61681176/json-stringify-replacer-how-to-get-full-path
404
409
  */
405
410
  function jsonReplacer(replacer: (this: any, key: string, value: any, path: string) => any): (this: any, key: any, value: any) => any;
411
+ /**
412
+ * JSON.stringify receiver for bigint
413
+ * @param args Keys or paths to convert to bigint
414
+ * @returns JSON receiver function
415
+ */
416
+ function jsonBigintReceiver(...args: string[]): (this: any, key: any, value: any) => any;
406
417
  }
407
418
  /**
408
419
  * Number and string combination id type
@@ -6,6 +6,9 @@
6
6
  */
7
7
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.DataTypes = void 0;
9
+ BigInt.prototype.toJSON = function () {
10
+ return this.toString() + 'n';
11
+ };
9
12
  /**
10
13
  * Interface data types
11
14
  */
@@ -456,4 +459,22 @@ var DataTypes;
456
459
  };
457
460
  }
458
461
  DataTypes.jsonReplacer = jsonReplacer;
462
+ /**
463
+ * JSON.stringify receiver for bigint
464
+ * @param args Keys or paths to convert to bigint
465
+ * @returns JSON receiver function
466
+ */
467
+ function jsonBigintReceiver(...args) {
468
+ return jsonReplacer(function (key, value, path) {
469
+ if ((args.includes(key) || args.includes(path)) &&
470
+ typeof value === 'string') {
471
+ if (value.endsWith('n'))
472
+ return BigInt(value.slice(0, -1));
473
+ else
474
+ return BigInt(value);
475
+ }
476
+ return value;
477
+ });
478
+ }
479
+ DataTypes.jsonBigintReceiver = jsonBigintReceiver;
459
480
  })(DataTypes || (exports.DataTypes = DataTypes = {}));
@@ -15,7 +15,7 @@ export declare namespace Keyboard {
15
15
  Pause = "Pause",
16
16
  CapsLock = "CapsLock",
17
17
  Escape = "Escape",
18
- Space = "",
18
+ Space = " ",
19
19
  PageUp = "PageUp",
20
20
  PageDown = "PageDown",
21
21
  End = "End",
@@ -20,7 +20,7 @@ var Keyboard;
20
20
  Keys["Pause"] = "Pause";
21
21
  Keys["CapsLock"] = "CapsLock";
22
22
  Keys["Escape"] = "Escape";
23
- Keys["Space"] = "";
23
+ Keys["Space"] = " ";
24
24
  Keys["PageUp"] = "PageUp";
25
25
  Keys["PageDown"] = "PageDown";
26
26
  Keys["End"] = "End";
@@ -3,6 +3,11 @@
3
3
  * Narrow case, uses StringRecord
4
4
  * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
5
  */
6
+ declare global {
7
+ interface BigInt {
8
+ toJSON(): String;
9
+ }
10
+ }
6
11
  /**
7
12
  * Interface data types
8
13
  */
@@ -403,6 +408,12 @@ export declare namespace DataTypes {
403
408
  * https://stackoverflow.com/questions/61681176/json-stringify-replacer-how-to-get-full-path
404
409
  */
405
410
  function jsonReplacer(replacer: (this: any, key: string, value: any, path: string) => any): (this: any, key: any, value: any) => any;
411
+ /**
412
+ * JSON.stringify receiver for bigint
413
+ * @param args Keys or paths to convert to bigint
414
+ * @returns JSON receiver function
415
+ */
416
+ function jsonBigintReceiver(...args: string[]): (this: any, key: any, value: any) => any;
406
417
  }
407
418
  /**
408
419
  * Number and string combination id type
@@ -3,6 +3,9 @@
3
3
  * Narrow case, uses StringRecord
4
4
  * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
5
  */
6
+ BigInt.prototype.toJSON = function () {
7
+ return this.toString() + 'n';
8
+ };
6
9
  /**
7
10
  * Interface data types
8
11
  */
@@ -453,4 +456,22 @@ export var DataTypes;
453
456
  };
454
457
  }
455
458
  DataTypes.jsonReplacer = jsonReplacer;
459
+ /**
460
+ * JSON.stringify receiver for bigint
461
+ * @param args Keys or paths to convert to bigint
462
+ * @returns JSON receiver function
463
+ */
464
+ function jsonBigintReceiver(...args) {
465
+ return jsonReplacer(function (key, value, path) {
466
+ if ((args.includes(key) || args.includes(path)) &&
467
+ typeof value === 'string') {
468
+ if (value.endsWith('n'))
469
+ return BigInt(value.slice(0, -1));
470
+ else
471
+ return BigInt(value);
472
+ }
473
+ return value;
474
+ });
475
+ }
476
+ DataTypes.jsonBigintReceiver = jsonBigintReceiver;
456
477
  })(DataTypes || (DataTypes = {}));
@@ -15,7 +15,7 @@ export declare namespace Keyboard {
15
15
  Pause = "Pause",
16
16
  CapsLock = "CapsLock",
17
17
  Escape = "Escape",
18
- Space = "",
18
+ Space = " ",
19
19
  PageUp = "PageUp",
20
20
  PageDown = "PageDown",
21
21
  End = "End",
@@ -17,7 +17,7 @@ export var Keyboard;
17
17
  Keys["Pause"] = "Pause";
18
18
  Keys["CapsLock"] = "CapsLock";
19
19
  Keys["Escape"] = "Escape";
20
- Keys["Space"] = "";
20
+ Keys["Space"] = " ";
21
21
  Keys["PageUp"] = "PageUp";
22
22
  Keys["PageDown"] = "PageDown";
23
23
  Keys["End"] = "End";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/shared",
3
- "version": "1.2.37",
3
+ "version": "1.2.40",
4
4
  "description": "TypeScript shared utilities and functions",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
package/src/DataTypes.ts CHANGED
@@ -4,6 +4,16 @@
4
4
  * Before was wrong with {}, from 4.8 unknown = {} | null | undefined
5
5
  */
6
6
 
7
+ declare global {
8
+ interface BigInt {
9
+ toJSON(): String;
10
+ }
11
+ }
12
+
13
+ BigInt.prototype.toJSON = function () {
14
+ return this.toString() + 'n';
15
+ };
16
+
7
17
  /**
8
18
  * Interface data types
9
19
  */
@@ -771,6 +781,25 @@ export namespace DataTypes {
771
781
  );
772
782
  };
773
783
  }
784
+
785
+ /**
786
+ * JSON.stringify receiver for bigint
787
+ * @param args Keys or paths to convert to bigint
788
+ * @returns JSON receiver function
789
+ */
790
+ export function jsonBigintReceiver(...args: string[]) {
791
+ return jsonReplacer(function (key, value, path) {
792
+ if (
793
+ (args.includes(key) || args.includes(path)) &&
794
+ typeof value === 'string'
795
+ ) {
796
+ if (value.endsWith('n')) return BigInt(value.slice(0, -1));
797
+ else return BigInt(value);
798
+ }
799
+
800
+ return value;
801
+ });
802
+ }
774
803
  }
775
804
 
776
805
  /**
package/src/Keyboard.ts CHANGED
@@ -15,7 +15,7 @@ export namespace Keyboard {
15
15
  Pause = 'Pause',
16
16
  CapsLock = 'CapsLock',
17
17
  Escape = 'Escape',
18
- Space = '',
18
+ Space = ' ',
19
19
  PageUp = 'PageUp',
20
20
  PageDown = 'PageDown',
21
21
  End = 'End',