1
1
import { NativeAdapter } from "./adapter/native.adapter.class" ;
2
2
import { Key } from "./key.enum" ;
3
3
4
- export class Keyboard {
4
+ type StringOrKey = string [ ] | Key [ ] ;
5
5
6
- private static inputIsString ( input : string [ ] | Key [ ] ) : boolean {
7
- return input . every ( ( elem : string | Key ) => typeof elem === "string" ) ;
8
- }
6
+ const inputIsString = ( input : string [ ] | Key [ ] ) : input is string [ ] => {
7
+ return input . every ( ( elem : string | Key ) => typeof elem === "string" ) ;
8
+ } ;
9
+
10
+ export class Keyboard {
9
11
10
12
public config = {
11
13
autoDelayMs : 500 ,
@@ -18,11 +20,11 @@ export class Keyboard {
18
20
this . lastAction = Date . now ( ) ;
19
21
}
20
22
21
- public type ( ...input : string [ ] | Key [ ] ) : Promise < Keyboard > {
23
+ public type ( ...input : StringOrKey ) : Promise < Keyboard > {
22
24
return new Promise < Keyboard > ( async resolve => {
23
- if ( Keyboard . inputIsString ( input ) ) {
25
+ if ( inputIsString ( input ) ) {
24
26
for ( const char of input . join ( " " ) . split ( "" ) ) {
25
- await this . waitForNextTick ( ) ;
27
+ await this . nextTick ( ) ;
26
28
this . nativeAdapter . type ( char ) ;
27
29
this . updateTick ( ) ;
28
30
}
@@ -51,7 +53,7 @@ export class Keyboard {
51
53
this . lastAction = Date . now ( ) ;
52
54
}
53
55
54
- private async waitForNextTick ( ) : Promise < void > {
56
+ private async nextTick ( ) : Promise < void > {
55
57
return new Promise < void > ( resolve => {
56
58
let current = Date . now ( ) ;
57
59
while ( current - this . lastAction < this . config . autoDelayMs ) {
0 commit comments