mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
feat(user-idle-observer): new definition (#47239)
Simple lib tracking client side user inactivity - definition file - tests https://www.npmjs.com/package/user-idle-observer https://github.com/vladagurets/user-idle-observer#example Thanks!
This commit is contained in:
parent
7ba2557c42
commit
2b9f574b03
44
types/user-idle-observer/index.d.ts
vendored
Normal file
44
types/user-idle-observer/index.d.ts
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
// Type definitions for user-idle-observer 1.0
|
||||
// Project: https://github.com/vladagurets/user-idle-observer#readme
|
||||
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
export as namespace userIDLEObserver;
|
||||
|
||||
/**
|
||||
* This lib allows you to track user inactivity time.
|
||||
*/
|
||||
declare function userIDLEObserver(opts?: userIDLEObserver.Options): userIDLEObserver.UserIDLEObserver;
|
||||
|
||||
declare namespace userIDLEObserver {
|
||||
/**
|
||||
* observer options
|
||||
*/
|
||||
interface Options {
|
||||
/**
|
||||
* fire callback on user inactivity time in ms
|
||||
* @default 3_000
|
||||
*/
|
||||
idleTime?: number;
|
||||
/**
|
||||
* callback that will triger after opts.idleTime of user's IDLE
|
||||
* @default console.log
|
||||
*/
|
||||
cb?: Callback;
|
||||
/**
|
||||
* @default ["mousemove", "mousedown", "keydown", "scroll", "touchstart", "resize", "visibilitychange"]
|
||||
*/
|
||||
listeners?: Array<keyof WindowEventMap>;
|
||||
}
|
||||
|
||||
interface UserIDLEObserver {
|
||||
/**
|
||||
* destroy observer instance
|
||||
*/
|
||||
destroy(): void;
|
||||
}
|
||||
|
||||
type Callback = (time: number) => void;
|
||||
}
|
||||
|
||||
export = userIDLEObserver;
|
||||
24
types/user-idle-observer/tsconfig.json
Normal file
24
types/user-idle-observer/tsconfig.json
Normal file
@ -0,0 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": [
|
||||
"es6",
|
||||
"DOM"
|
||||
],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictFunctionTypes": true,
|
||||
"strictNullChecks": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": [
|
||||
"../"
|
||||
],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"user-idle-observer-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/user-idle-observer/tslint.json
Normal file
1
types/user-idle-observer/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
15
types/user-idle-observer/user-idle-observer-tests.ts
Normal file
15
types/user-idle-observer/user-idle-observer-tests.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import IDLEObserver = require('user-idle-observer');
|
||||
|
||||
const observer = IDLEObserver({
|
||||
idleTime: 5000,
|
||||
cb: time => {
|
||||
console.log(`User was innactive for ${time}ms`);
|
||||
},
|
||||
listeners: ['mousemove', 'mousedown', 'keydown'],
|
||||
});
|
||||
|
||||
IDLEObserver();
|
||||
IDLEObserver({});
|
||||
IDLEObserver({
|
||||
cb: console.log,
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user