Add typings for anchor-js (#23957)

This commit is contained in:
Brian Surowiec
2018-02-28 14:17:33 -05:00
committed by Andy
parent 4bc50a244d
commit e274bfb6e4
4 changed files with 83 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
anchors.add();
anchors.add('h1');
anchors.add().add('h2');
anchors.remove();
anchors.remove('h1');
anchors.remove().remove('h2');
anchors.removeAll();
const headerAnchors = new AnchorJS();
const footerAnchors = new AnchorJS({
placement: 'right',
});
footerAnchors.remove('.links');

41
types/anchor-js/index.d.ts vendored Normal file
View File

@@ -0,0 +1,41 @@
// Type definitions for anchor-js 4.1
// Project: https://github.com/bryanbraun/anchorjs
// Definitions by: Brian Surowiec <https://github.com/xt0rted>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace anchorjs {
interface Anchor {
options: AnchorOptions;
add(selector?: string): Anchor;
remove(selector?: string): Anchor;
removeAll(): void;
}
type AnchorPlacement = 'left' | 'right';
type AnchorVisibility = 'always' | 'hover' | 'touch';
interface AnchorOptions {
arialabel?: string;
class?: string;
icons?: string;
placement?: AnchorPlacement;
truncate?: number;
visible?: AnchorVisibility;
}
interface AnchorStatic {
new(options?: AnchorOptions): Anchor;
}
}
declare const anchors: anchorjs.Anchor;
declare const AnchorJS: anchorjs.AnchorStatic;
export = AnchorJS;
export as namespace AnchorJS;
declare global {
const anchors: anchorjs.Anchor;
}

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"anchor-js-tests.ts"
]
}

View File

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