From 468a3b55178aedb632fdb411cdd161a9399e5de8 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Sun, 24 Mar 2019 00:34:49 -0500 Subject: [PATCH 1/2] Add types for license-checker-webpack-plugin --- .../license-checker-webpack-plugin/index.d.ts | 73 +++++++++++++++++++ .../license-checker-webpack-plugin-tests.ts | 24 ++++++ .../tsconfig.json | 23 ++++++ .../tslint.json | 1 + 4 files changed, 121 insertions(+) create mode 100644 types/license-checker-webpack-plugin/index.d.ts create mode 100644 types/license-checker-webpack-plugin/license-checker-webpack-plugin-tests.ts create mode 100644 types/license-checker-webpack-plugin/tsconfig.json create mode 100644 types/license-checker-webpack-plugin/tslint.json diff --git a/types/license-checker-webpack-plugin/index.d.ts b/types/license-checker-webpack-plugin/index.d.ts new file mode 100644 index 0000000000..ff131df767 --- /dev/null +++ b/types/license-checker-webpack-plugin/index.d.ts @@ -0,0 +1,73 @@ +// Type definitions for license-checker-webpack-plugin 0.0 +// Project: https://github.com/Microsoft/license-checker-webpack-plugin#readme +// Definitions by: Joel Spadin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.3 + +import { Plugin } from 'webpack'; + +declare class LicenseCheckerWebpackPlugin extends Plugin { + constructor(options: LicenseCheckerWebpackPlugin.Options); +} + +declare namespace LicenseCheckerWebpackPlugin { + interface Dependency { + name: string; + version: string; + repository: string; + licenseName: string; + licenseText: string; + } + + interface Options { + /** + * Regular expression that matches the file paths of dependencies to check. + */ + filter?: RegExp; + + /** + * SPDX expression with allowed licenses. + * + * Default: `"(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)"` + */ + allow?: string; + + /** + * Array of dependencies to ignore, in the format `["@"]`. + * For example, `["assignment@^2.0.0"]`. + * + * Default: `[]` + */ + ignore?: string[]; + + /** + * Object of dependencies to override, in the format `{"@": { ... }}`. + * For example, `{"assignment@^2.0.0": { licenseName: "MIT" }}`. + * + * Default: `{}` + */ + override?: Record>; + + /** + * Whether to emit errors instead of warnings. + * + * Default: `false` + */ + emitError?: boolean; + + /** + * Path to a `.ejs` template, or function that will generate the contents + * of the third-party notices file. + */ + outputWriter?: string | ((dependencies: Dependency[]) => string); + + /** + * Name of the third-party notices file with all licensing information. + * + * Default: `"ThirdPartyNotices.txt"` + */ + outputFilename?: string; + } +} + +export = LicenseCheckerWebpackPlugin; diff --git a/types/license-checker-webpack-plugin/license-checker-webpack-plugin-tests.ts b/types/license-checker-webpack-plugin/license-checker-webpack-plugin-tests.ts new file mode 100644 index 0000000000..f476b515f5 --- /dev/null +++ b/types/license-checker-webpack-plugin/license-checker-webpack-plugin-tests.ts @@ -0,0 +1,24 @@ +import * as path from 'path'; +import LicenseCheckerWebpackPlugin = require('license-checker-webpack-plugin'); + +// $ExpectType LicenseCheckerWebpackPlugin +new LicenseCheckerWebpackPlugin({ + allow: "(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT)", + ignore: ["@microsoft/*"], + override: { + "assignment@2.0.0": { licenseName: "MIT" }, + "intersection-observer@0.5.0": { licenseName: "MIT" }, + "querystring-es3@0.2.1": { licenseName: "MIT" } + }, + emitError: true, + outputWriter: path.resolve(__dirname, "customTemplate.ejs"), + outputFilename: "ThirdPartyNotices.txt" +}); + +// $ExpectType LicenseCheckerWebpackPlugin +new LicenseCheckerWebpackPlugin({ + filter: /.*/, + outputWriter: (dependencies) => { + return dependencies.map(d => `${d.name} ${d.licenseName}`).join('\n'); + }, +}); diff --git a/types/license-checker-webpack-plugin/tsconfig.json b/types/license-checker-webpack-plugin/tsconfig.json new file mode 100644 index 0000000000..2e9aebac73 --- /dev/null +++ b/types/license-checker-webpack-plugin/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", + "license-checker-webpack-plugin-tests.ts" + ] +} diff --git a/types/license-checker-webpack-plugin/tslint.json b/types/license-checker-webpack-plugin/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/license-checker-webpack-plugin/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From f0d51bcda9e48b0ab5bd33b5e52ff59995c642d3 Mon Sep 17 00:00:00 2001 From: Joel Spadin Date: Fri, 5 Apr 2019 16:19:54 -0500 Subject: [PATCH 2/2] Add types for use-dark-mode --- types/use-dark-mode/index.d.ts | 77 ++++++++++++++++++++++ types/use-dark-mode/tsconfig.json | 24 +++++++ types/use-dark-mode/tslint.json | 1 + types/use-dark-mode/use-dark-mode-tests.ts | 26 ++++++++ 4 files changed, 128 insertions(+) create mode 100644 types/use-dark-mode/index.d.ts create mode 100644 types/use-dark-mode/tsconfig.json create mode 100644 types/use-dark-mode/tslint.json create mode 100644 types/use-dark-mode/use-dark-mode-tests.ts diff --git a/types/use-dark-mode/index.d.ts b/types/use-dark-mode/index.d.ts new file mode 100644 index 0000000000..e81ef48b48 --- /dev/null +++ b/types/use-dark-mode/index.d.ts @@ -0,0 +1,77 @@ +// Type definitions for use-dark-mode 2.3 +// Project: https://github.com/donavon/use-dark-mode#readme +// Definitions by: Joel Spadin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 + +interface DarkMode { + /** + * The current state of dark mode. + */ + value: boolean; + /** + * A function that allows you to set dark mode to `true`. + */ + enable(): void; + /** + * A function that allows you to set dark mode to `false`. + */ + disable(): void; + /** + * A function that allows you to toggle dark mode. + */ + toggle(): void; +} + +interface DarkModeConfig { + /** + * The class to apply. Default = `dark-mode`. + */ + classNameDark: string; + /** + * The class to apply. Default = `light-mode`. + */ + classNameLight: string; + /** + * The element to apply the class name. Default = `document.body`. + */ + element: Element; + /** + * A function that will be called when the dark mode value changes and + * it is safe to access the DOM (i.e. it is called from within a + * `useEffect`). If you specify `onChange` then `classNameDark`, + * `classNameLight`, and `element` are ignored (i.e. no classes are + * automatically placed on the DOM). You have full control! + */ + onChange: (value: boolean) => void; + /** + * A string that will be used by the `storageProvider` to persist the + * dark mode value. If you specify a value of `null`, nothing will not + * be persisted. Default = `darkMode`. + */ + storageKey: string | null; + /** + * A storage provider. Default = `localStorage`. You will generally + * never need to change this value. + */ + storageProvider: Storage; +} + +/** + * A custom React Hook to help you implement a "dark mode" component for + * your application. The user setting persists to `localStorage` by default. + * + * `useDarkMode` works in one of two ways: + * 1. By toggling a CSS class on whatever element you specify (defaults to + * `document.body`). You then setup your CSS to display different views + * based on the presence of the selector. + * 2. If you don't use global classes, you can specify an `onChange` handler + * and take care of the implementation of switching to dark mode + * yourself. + * + * @param initialState Specifies whether it should be in dark mode by defualt. + * @param darkModeConfig Optional configuration. + */ +declare function useDarkMode(initialState: boolean, darkModeConfig?: Partial): DarkMode; + +export default useDarkMode; diff --git a/types/use-dark-mode/tsconfig.json b/types/use-dark-mode/tsconfig.json new file mode 100644 index 0000000000..dc40a1fa3c --- /dev/null +++ b/types/use-dark-mode/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "dom", + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "use-dark-mode-tests.ts" + ] +} diff --git a/types/use-dark-mode/tslint.json b/types/use-dark-mode/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/use-dark-mode/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/use-dark-mode/use-dark-mode-tests.ts b/types/use-dark-mode/use-dark-mode-tests.ts new file mode 100644 index 0000000000..33c54bfd80 --- /dev/null +++ b/types/use-dark-mode/use-dark-mode-tests.ts @@ -0,0 +1,26 @@ +import useDarkMode from "use-dark-mode"; + +// $ExpectType DarkMode +const darkMode = useDarkMode(false); + +darkMode.value; // $ExpectType boolean +darkMode.disable(); // $ExpectType void +darkMode.enable(); // $ExpectType void +darkMode.toggle(); // $ExpectType void + +// $ExpectType DarkMode +useDarkMode(true, { + classNameDark: 'dark-mode', + classNameLight: 'light-mode', + element: document.body, + storageKey: 'darkMode', + storageProvider: localStorage, +}); + +// $ExpectType DarkMode +useDarkMode(true, { + onChange: (value) => { + value; // $ExpectType: boolean + }, + storageKey: null, +});