@etsoo/shared 1.1.3 → 1.1.7

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.
@@ -0,0 +1,265 @@
1
+ /**
2
+ * Keyboard functions
3
+ */
4
+ export namespace Keyboard {
5
+ /**
6
+ * Keys for KeyboardEvent.key
7
+ */
8
+ export enum Keys {
9
+ Backspace = 'Backspace',
10
+ Tab = 'Tab',
11
+ Enter = 'Enter',
12
+ Shift = 'Shift',
13
+ Control = 'Control',
14
+ Alt = 'Alt',
15
+ Pause = 'Pause',
16
+ CapsLock = 'CapsLock',
17
+ Escape = 'Escape',
18
+ Space = '',
19
+ PageUp = 'PageUp',
20
+ PageDown = 'PageDown',
21
+ End = 'End',
22
+ Home = 'Home',
23
+ ArrowLeft = 'ArrowLeft',
24
+ ArrowUp = 'ArrowUp',
25
+ ArrowRight = 'ArrowRight',
26
+ ArrowDown = 'ArrowDown',
27
+ PrintScreen = 'PrintScreen',
28
+ Insert = 'Insert',
29
+ Delete = 'Delete',
30
+ Digit0 = '0',
31
+ Digit1 = '1',
32
+ Digit2 = '2',
33
+ Digit3 = '3',
34
+ Digit4 = '4',
35
+ Digit5 = '5',
36
+ Digit6 = '6',
37
+ Digit7 = '7',
38
+ Digit8 = '8',
39
+ Digit9 = '9',
40
+ A = 'A',
41
+ B = 'B',
42
+ C = 'C',
43
+ D = 'D',
44
+ E = 'E',
45
+ F = 'F',
46
+ G = 'G',
47
+ H = 'H',
48
+ I = 'I',
49
+ J = 'J',
50
+ K = 'K',
51
+ L = 'L',
52
+ M = 'M',
53
+ N = 'N',
54
+ O = 'O',
55
+ P = 'P',
56
+ Q = 'Q',
57
+ R = 'R',
58
+ S = 'S',
59
+ T = 'T',
60
+ U = 'U',
61
+ V = 'V',
62
+ W = 'W',
63
+ X = 'X',
64
+ Y = 'Y',
65
+ Z = 'Z',
66
+ a = 'a',
67
+ b = 'b',
68
+ c = 'c',
69
+ d = 'd',
70
+ e = 'e',
71
+ f = 'f',
72
+ g = 'g',
73
+ h = 'h',
74
+ i = 'i',
75
+ j = 'j',
76
+ k = 'k',
77
+ l = 'l',
78
+ m = 'm',
79
+ n = 'n',
80
+ o = 'o',
81
+ p = 'p',
82
+ q = 'q',
83
+ r = 'r',
84
+ s = 's',
85
+ t = 't',
86
+ u = 'u',
87
+ v = 'v',
88
+ w = 'w',
89
+ x = 'x',
90
+ y = 'y',
91
+ z = 'z',
92
+ Meta = 'Meta',
93
+ ContextMenu = 'ContextMenu',
94
+ AudioVolumeMute = 'AudioVolumeMute',
95
+ AudioVolumeDown = 'AudioVolumeDown',
96
+ AudioVolumeUp = 'AudioVolumeUp',
97
+ F1 = 'F1',
98
+ F2 = 'F2',
99
+ F3 = 'F3',
100
+ F4 = 'F4',
101
+ F5 = 'F5',
102
+ F6 = 'F6',
103
+ F7 = 'F7',
104
+ F8 = 'F8',
105
+ F9 = 'F9',
106
+ F10 = 'F10',
107
+ F11 = 'F11',
108
+ F12 = 'F12',
109
+ NumLock = 'NumLock',
110
+ ScrollLock = 'ScrollLock',
111
+ Semicolon = ';',
112
+ Equal = '=',
113
+ Comma = ',',
114
+ Minus = '-',
115
+ Period = '.',
116
+ Slash = '/',
117
+ Backquote = '`',
118
+ BracketLeft = '[',
119
+ Backslash = '\\',
120
+ BracketRight = ']',
121
+ Quote = "'",
122
+ Tilde = '~',
123
+ Exclamation = '!',
124
+ At = '@',
125
+ Sharp = '#',
126
+ Dollar = '$',
127
+ Percent = '%',
128
+ Caret = '^',
129
+ Ampersand = '&',
130
+ Asterisk = '*',
131
+ ParenthesisLeft = '(',
132
+ ParenthesisRight = ')',
133
+ Underscore = '_',
134
+ Plus = '+',
135
+ OpenBrace = '{',
136
+ CloseBrace = '}',
137
+ Pipe = '|',
138
+ Colon = ':',
139
+ Quote2 = '"',
140
+ AngleBracketLeft = '<',
141
+ AngleBracketRight = '>',
142
+ QuestionMark = '?'
143
+ }
144
+
145
+ /**
146
+ * Codes for KeyboardEvent.code
147
+ */
148
+ export enum Codes {
149
+ Backspace = 'Backspace',
150
+ Tab = 'Tab',
151
+ Enter = 'Enter',
152
+ ShiftLeft = 'ShiftLeft',
153
+ ShiftRight = 'ShiftRight',
154
+ ControlLeft = 'ControlLeft',
155
+ ControlRight = 'ControlRight',
156
+ AltLeft = 'AltLeft',
157
+ AltRight = 'AltRight',
158
+ Pause = 'Pause',
159
+ CapsLock = 'CapsLock',
160
+ Escape = 'Escape',
161
+ Space = 'Space',
162
+ PageUp = 'PageUp',
163
+ PageDown = 'PageDown',
164
+ End = 'End',
165
+ Home = 'Home',
166
+ ArrowLeft = 'ArrowLeft',
167
+ ArrowUp = 'ArrowUp',
168
+ ArrowRight = 'ArrowRight',
169
+ ArrowDown = 'ArrowDown',
170
+ PrintScreen = 'PrintScreen',
171
+ Insert = 'Insert',
172
+ Delete = 'Delete',
173
+ Digit0 = 'Digit0',
174
+ Digit1 = 'Digit1',
175
+ Digit2 = 'Digit2',
176
+ Digit3 = 'Digit3',
177
+ Digit4 = 'Digit4',
178
+ Digit5 = 'Digit5',
179
+ Digit6 = 'Digit6',
180
+ Digit7 = 'Digit7',
181
+ Digit8 = 'Digit8',
182
+ Digit9 = 'Digit9',
183
+ AudioVolumeMute = 'AudioVolumeMute',
184
+ AudioVolumeDown = 'AudioVolumeDown',
185
+ AudioVolumeUp = 'AudioVolumeUp',
186
+ KeyA = 'KeyA',
187
+ KeyB = 'KeyB',
188
+ KeyC = 'KeyC',
189
+ KeyD = 'KeyD',
190
+ KeyE = 'KeyE',
191
+ KeyF = 'KeyF',
192
+ KeyG = 'KeyG',
193
+ KeyH = 'KeyH',
194
+ KeyI = 'KeyI',
195
+ KeyJ = 'KeyJ',
196
+ KeyK = 'KeyK',
197
+ KeyL = 'KeyL',
198
+ KeyM = 'KeyM',
199
+ KeyN = 'KeyN',
200
+ KeyO = 'KeyO',
201
+ KeyP = 'KeyP',
202
+ KeyQ = 'KeyQ',
203
+ KeyR = 'KeyR',
204
+ KeyS = 'KeyS',
205
+ KeyT = 'KeyT',
206
+ KeyU = 'KeyU',
207
+ KeyV = 'KeyV',
208
+ KeyW = 'KeyW',
209
+ KeyX = 'KeyX',
210
+ KeyY = 'KeyY',
211
+ KeyZ = 'KeyZ',
212
+ MetaLeft = 'MetaLeft',
213
+ MetaRight = 'MetaRight',
214
+ ContextMenu = 'ContextMenu',
215
+ Numpad0 = 'Numpad0',
216
+ Numpad1 = 'Numpad1',
217
+ Numpad2 = 'Numpad2',
218
+ Numpad3 = 'Numpad3',
219
+ Numpad4 = 'Numpad4',
220
+ Numpad5 = 'Numpad5',
221
+ Numpad6 = 'Numpad6',
222
+ Numpad7 = 'Numpad7',
223
+ Numpad8 = 'Numpad8',
224
+ Numpad9 = 'Numpad9',
225
+ NumpadMultiply = 'NumpadMultiply',
226
+ NumpadAdd = 'NumpadAdd',
227
+ NumpadSubtract = 'NumpadSubtract',
228
+ NumpadDecimal = 'NumpadDecimal',
229
+ NumpadDivide = 'NumpadDivide',
230
+ F1 = 'F1',
231
+ F2 = 'F2',
232
+ F3 = 'F3',
233
+ F4 = 'F4',
234
+ F5 = 'F5',
235
+ F6 = 'F6',
236
+ F7 = 'F7',
237
+ F8 = 'F8',
238
+ F9 = 'F9',
239
+ F10 = 'F10',
240
+ F11 = 'F11',
241
+ F12 = 'F12',
242
+ NumLock = 'NumLock',
243
+ ScrollLock = 'ScrollLock',
244
+ Semicolon = 'Semicolon',
245
+ Equal = 'Equal',
246
+ Comma = 'Comma',
247
+ Minus = 'Minus',
248
+ Period = 'Period',
249
+ Slash = 'Slash',
250
+ Backquote = 'Backquote',
251
+ BracketLeft = 'BracketLeft',
252
+ Backslash = 'Backslash',
253
+ BracketRight = 'BracketRight',
254
+ Quote = 'Quote'
255
+ }
256
+
257
+ /**
258
+ * Is typing content or press command key
259
+ * @param input Input key
260
+ * @returns Result
261
+ */
262
+ export function isTypingContent(input: Keys | string) {
263
+ return input.length === 1;
264
+ }
265
+ }
package/src/Utils.ts CHANGED
@@ -93,6 +93,24 @@ export namespace Utils {
93
93
  }, 0);
94
94
  }
95
95
 
96
+ /**
97
+ * Correct object's property value type
98
+ * @param input Input object
99
+ * @param fields Fields to correct
100
+ */
101
+ export function correctTypes<
102
+ T extends {},
103
+ F extends { [P in keyof T]: DataTypes.BasicNames }
104
+ >(input: T, fields: F) {
105
+ for (const field in fields) {
106
+ const value = Reflect.get(input, field);
107
+ const newValue = DataTypes.convertByType(value, fields[field]);
108
+ if (newValue !== value) {
109
+ Reflect.set(input, field, newValue);
110
+ }
111
+ }
112
+ }
113
+
96
114
  /**
97
115
  * Two values equal
98
116
  * @param v1 Value 1
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './DataTypes';
7
7
  export * from './DateUtils';
8
8
  export * from './DomUtils';
9
9
  export * from './ExtendUtils';
10
+ export * from './Keyboard';
10
11
  export * from './NumberUtils';
11
12
  export * from './StorageUtils';
12
13
  export * from './Utils';