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:
Piotr Błażejewicz (Peter Blazejewicz) 2020-09-08 22:58:29 +02:00 committed by GitHub
parent 7ba2557c42
commit 2b9f574b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 84 additions and 0 deletions

44
types/user-idle-observer/index.d.ts vendored Normal file
View 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;

View 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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View 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,
});