@etsoo/shared 1.1.5 → 1.1.9

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