mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
Add typing for is-hotkey library
This commit is contained in:
parent
a7a33da61a
commit
cdccb48a58
58
types/is-hotkey/index.d.ts
vendored
Normal file
58
types/is-hotkey/index.d.ts
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
// Type definitions for is-hotkey 0.1
|
||||
// Project: https://github.com/ianstormtaylor/is-hotkey#readme
|
||||
// Definitions by: Pierre-Marc Airoldi <https://github.com/petester42>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export interface HotKeyOptions {
|
||||
byKey: boolean;
|
||||
}
|
||||
|
||||
export interface HotKey {
|
||||
which?: number;
|
||||
key?: string;
|
||||
altKey: boolean;
|
||||
ctrlKey: boolean;
|
||||
metaKey: boolean;
|
||||
shiftKey: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is hotkey?
|
||||
*/
|
||||
export function isHotkey(
|
||||
hotkey: string,
|
||||
options?: HotKeyOptions
|
||||
): (event: KeyboardEvent) => boolean;
|
||||
|
||||
export function isHotkey(
|
||||
hotkey: string,
|
||||
options?: HotKeyOptions | KeyboardEvent,
|
||||
event?: KeyboardEvent
|
||||
): boolean;
|
||||
|
||||
export function isCodeHotkey(hotkey: string): (event: KeyboardEvent) => boolean;
|
||||
export function isCodeHotkey(hotkey: string, event: KeyboardEvent): boolean;
|
||||
|
||||
export function isKeyHotkey(hotkey: string): (event: KeyboardEvent) => boolean;
|
||||
export function isKeyHotkey(hotkey: string, event: KeyboardEvent): boolean;
|
||||
|
||||
/**
|
||||
* Parse.
|
||||
*/
|
||||
export function parseHotkey(hotkey: string, options?: HotKeyOptions): HotKey;
|
||||
|
||||
/**
|
||||
* Compare.
|
||||
*/
|
||||
export function compareHotkey(object: HotKey, event: KeyboardEvent): boolean;
|
||||
|
||||
/**
|
||||
* Utils.
|
||||
*/
|
||||
export function toKeyCode(name: string): number;
|
||||
export function toKeyName(name: string): string;
|
||||
|
||||
/**
|
||||
* Export.
|
||||
*/
|
||||
export default isHotkey;
|
||||
32
types/is-hotkey/is-hotkey-tests.ts
Normal file
32
types/is-hotkey/is-hotkey-tests.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import {
|
||||
isHotkey,
|
||||
isCodeHotkey,
|
||||
isKeyHotkey,
|
||||
toKeyName,
|
||||
toKeyCode,
|
||||
parseHotkey,
|
||||
compareHotkey
|
||||
} from "is-hotkey";
|
||||
|
||||
const event = new KeyboardEvent("");
|
||||
|
||||
isHotkey("mod+s")(event); // $ExpectType boolean
|
||||
isHotkey("mod+s", { byKey: true })(event); // $ExpectType boolean
|
||||
|
||||
isHotkey("mod+s", event); // $ExpectType boolean
|
||||
isHotkey("mod+s", { byKey: true }, event); // $ExpectType boolean
|
||||
|
||||
isCodeHotkey("mod+s")(event); // $ExpectType boolean
|
||||
isKeyHotkey("mod+s")(event); // $ExpectType boolean
|
||||
|
||||
isCodeHotkey("mod+s", event); // $ExpectType boolean
|
||||
isKeyHotkey("mod+s", event); // $ExpectType boolean
|
||||
|
||||
toKeyName("cmd"); // $ExpectType string
|
||||
|
||||
toKeyCode("shift"); // $ExpectType number
|
||||
|
||||
parseHotkey("cmd+s"); // $ExpectType HotKey
|
||||
parseHotkey("cmd+s", { byKey: true }); // $ExpectType HotKey
|
||||
|
||||
compareHotkey(parseHotkey("cmd+s"), event); // $ExpectType boolean
|
||||
25
types/is-hotkey/tsconfig.json
Normal file
25
types/is-hotkey/tsconfig.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"dom"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": false,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"is-hotkey-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/is-hotkey/tslint.json
Normal file
1
types/is-hotkey/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user