Skip to content

Commit

Permalink
feat(sonar-js): new definition file (DefinitelyTyped#46486)
Browse files Browse the repository at this point in the history
- definition file
- tests

https://github.com/brandonweiss/sonar-js

Thanks!
  • Loading branch information
peterblazejewicz committed Aug 6, 2020
1 parent d046b35 commit 44f519e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
28 changes: 28 additions & 0 deletions types/sonar-js/index.d.ts
@@ -0,0 +1,28 @@
// Type definitions for sonar-js 1.1
// Project: https://github.com/brandonweiss/sonar-js
// Definitions by: Piotr Błażejewicz <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

export as namespace Sonar;

/**
* A tiny library for detecting when a browser is scrolled to the bottom of a web page.
*
* You could use this, for example, on a blog to show a popover when a reader has finished a post,
* letting them know they can receive new posts by email if they submit their email address.
*/
declare class Sonar {
withinRangeOfPageBottom?: boolean;

constructor(window: Window);

ping(range: number, bottomFoundCallback?: Sonar.SonarCallback, bottomLostCallback?: Sonar.SonarCallback): void;

stop(): void;
}

declare namespace Sonar {
type SonarCallback = () => void;
}

export = Sonar;
13 changes: 13 additions & 0 deletions types/sonar-js/sonar-js-tests.ts
@@ -0,0 +1,13 @@
import Sonar = require('sonar-js');

const sonar = new Sonar(window);

const withinRangeOfPageBottom = () => {
document.querySelector('.popover')!.classList.remove('hidden');
};

const notWithinRangeOfPageBottom = () => {
document.querySelector('.popover')!.classList.add('hidden');
};

sonar.ping(600, withinRangeOfPageBottom, notWithinRangeOfPageBottom);
24 changes: 24 additions & 0 deletions types/sonar-js/tsconfig.json
@@ -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",
"sonar-js-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/sonar-js/tslint.json
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit 44f519e

Please sign in to comment.