feat(obsolete-web): new package definition (#42983)

- definition files
- tests for global/CommonJS usage

https://github.com/ElemeFE/obsolete-webpack-plugin/tree/master/packages/obsolete-web

Thanks!
This commit is contained in:
Piotr Błażejewicz (Peter Blazejewicz)
2020-03-12 12:52:28 -07:00
committed by GitHub
parent 383dba4d19
commit 8c8ed66d51
5 changed files with 98 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
// Type definitions for obsolete-web 0.5
// Project: https://github.elenet.me/fe/obsolete-webpack-plugin
// Definitions by: Piotr Błażejewicz (Peter Blazejewicz) <https://github.com/peterblazejewicz>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class Obsolete {
constructor(options?: Options);
static defaultOptions: Readonly<Required<Options>>;
/**
* Test browser compatibility.
*/
test(browsers: string[], done?: () => void): boolean;
}
interface Options {
/**
* The prompt html template injected to the bottom of body. The default value is:
* ```html
* <div>Your browser is not supported. <button id="obsoleteClose">&times;</button></div>
* ```
*/
template?: string;
/**
* If set 'afterbegin', the template will be injected into the start of body.
* If set 'beforeend', the template will be injected into the end of body
* @default 'afterbegin'
*/
position?: 'afterbeing' | 'beforened';
/**
* If the current browser useragent doesn't match one of the target browsers, it's considered as unsupported.
* Thus, the prompt will be shown.
* @default false
*/
promptOnNonTargetBrowser?: boolean;
/**
* If the current browser useragent is unknown, the prompt will be shown
* @default true
*/
promptOnUnknownBrowser?: boolean;
}
export as namespace Obsolete;
export = Obsolete;
@@ -0,0 +1,16 @@
/// <reference types="node" />
import Obsolete = require('obsolete-web');
const {
template, // $ExpectType string
position, // $ExpedtType string
promptOnNonTargetBrowser, // $ExpectType boolean
promptOnUnknownBrowser, // $ExpectType boolean
} = Obsolete.defaultOptions;
new Obsolete();
new Obsolete(Obsolete.defaultOptions);
new Obsolete().test(['ie 10', 'chrome 23']);
new Obsolete().test(['ie 10', 'chrome 23'], () => {
console.log('done');
});
@@ -0,0 +1,13 @@
const {
template, // $ExpectType string
position, // $ExpedtType string
promptOnNonTargetBrowser, // $ExpectType boolean
promptOnUnknownBrowser, // $ExpectType boolean
} = Obsolete.defaultOptions;
new Obsolete();
new Obsolete(Obsolete.defaultOptions);
new Obsolete().test(['ie 10', 'chrome 23']);
new Obsolete().test(['ie 10', 'chrome 23'], () => {
console.log('done');
});
+24
View File
@@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"test/obsolete-web-commonjs.tests.ts",
"test/obsolete-web-global.tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }