From e274bfb6e46d6f9ad53333b01344b376f177f4ef Mon Sep 17 00:00:00 2001 From: Brian Surowiec Date: Wed, 28 Feb 2018 14:17:33 -0500 Subject: [PATCH] Add typings for anchor-js (#23957) --- types/anchor-js/anchor-js-tests.ts | 16 ++++++++++++ types/anchor-js/index.d.ts | 41 ++++++++++++++++++++++++++++++ types/anchor-js/tsconfig.json | 23 +++++++++++++++++ types/anchor-js/tslint.json | 3 +++ 4 files changed, 83 insertions(+) create mode 100644 types/anchor-js/anchor-js-tests.ts create mode 100644 types/anchor-js/index.d.ts create mode 100644 types/anchor-js/tsconfig.json create mode 100644 types/anchor-js/tslint.json diff --git a/types/anchor-js/anchor-js-tests.ts b/types/anchor-js/anchor-js-tests.ts new file mode 100644 index 0000000000..a27e09605a --- /dev/null +++ b/types/anchor-js/anchor-js-tests.ts @@ -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'); diff --git a/types/anchor-js/index.d.ts b/types/anchor-js/index.d.ts new file mode 100644 index 0000000000..1f59c295e2 --- /dev/null +++ b/types/anchor-js/index.d.ts @@ -0,0 +1,41 @@ +// Type definitions for anchor-js 4.1 +// Project: https://github.com/bryanbraun/anchorjs +// Definitions by: Brian Surowiec +// 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; +} diff --git a/types/anchor-js/tsconfig.json b/types/anchor-js/tsconfig.json new file mode 100644 index 0000000000..19f6891217 --- /dev/null +++ b/types/anchor-js/tsconfig.json @@ -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" + ] +} diff --git a/types/anchor-js/tslint.json b/types/anchor-js/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/anchor-js/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +}