From 0346d26035e7e3c6af1c65a321bf3efd15acf6c3 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Thu, 11 Apr 2019 07:03:44 +0000 Subject: [PATCH] Add TypeScript definition (#34) --- .editorconfig | 2 +- .gitattributes | 3 +- .gitignore | 1 + .npmrc | 1 + .travis.yml | 4 +++ index.d.ts | 36 ++++++++++++++++++++++ index.test-d.ts | 11 +++++++ license | 20 +++---------- package.json | 80 +++++++++++++++++++++++++------------------------ readme.md | 2 +- 10 files changed, 101 insertions(+), 59 deletions(-) create mode 100644 .npmrc create mode 100644 .travis.yml create mode 100644 index.d.ts create mode 100644 index.test-d.ts diff --git a/.editorconfig b/.editorconfig index 98a761d..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,6 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[{package.json,*.yml}] +[*.yml] indent_style = space indent_size = 2 diff --git a/.gitattributes b/.gitattributes index 391f0a4..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,2 +1 @@ -* text=auto -*.js text eol=lf +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f3fa8cd --- /dev/null +++ b/.travis.yml @@ -0,0 +1,4 @@ +language: node_js +node_js: + - '10' + - '8' diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..d0c887e --- /dev/null +++ b/index.d.ts @@ -0,0 +1,36 @@ +/// + +declare namespace devTools { + type Orientation = 'vertical' | 'horizontal'; + + interface DevTools { + /** + Whether DevTools is open. + */ + readonly open: boolean; + + /** + Orientaion of the DevTools or `null` if not open. + */ + readonly orientation: Orientation | null; + } + + interface DevToolsEvent extends Event { + detail: DevTools; + } +} + +declare const devTools: devTools.DevTools; + +export = devTools; +export as namespace devTools; + +declare global { + interface Window { + addEventListener( + type: 'devtoolschange', + listener: (event: devTools.DevToolsEvent) => unknown, + options?: boolean | AddEventListenerOptions + ): void; + } +} diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..7830524 --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,11 @@ +import {expectType} from 'tsd'; +import devtools = require('.'); + +expectType(devtools.open); +expectType(devtools.orientation); + +window.addEventListener('devtoolschange', devtoolsEvent => { + expectType(devtoolsEvent); + expectType(devtoolsEvent.detail.open); + expectType(devtoolsEvent.detail.orientation); +}); diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index ea7eb23..e3b23a3 100644 --- a/package.json +++ b/package.json @@ -1,41 +1,43 @@ { - "name": "devtools-detect", - "version": "2.2.0", - "description": "Detect if DevTools is open and its orientation", - "license": "MIT", - "repository": "sindresorhus/devtools-detect", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=0.10.0" - }, - "scripts": { - "test": "xo" - }, - "files": [ - "index.js" - ], - "keywords": [ - "browser", - "detect", - "identify", - "check", - "dev", - "devtools", - "developer", - "orientation", - "placement", - "docked" - ], - "devDependencies": { - "xo": "^0.16.0" - }, - "xo": { - "envs": [ - "browser" - ] - } + "name": "devtools-detect", + "version": "2.2.0", + "description": "Detect if DevTools is open and its orientation", + "license": "MIT", + "repository": "sindresorhus/devtools-detect", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=0.10.0" + }, + "scripts": { + "test": "xo && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "browser", + "detect", + "identify", + "check", + "dev", + "devtools", + "developer", + "orientation", + "placement", + "docked" + ], + "devDependencies": { + "tsd": "^0.7.2", + "xo": "^0.16.0" + }, + "xo": { + "envs": [ + "browser" + ] + } } diff --git a/readme.md b/readme.md index 3b75a7f..53b2f49 100644 --- a/readme.md +++ b/readme.md @@ -11,7 +11,7 @@ Useful for when you want something special to happen when DevTools is open. Like ## Install ``` -$ npm install --save devtools-detect +$ npm install devtools-detect ```