core-js-compat: Add more typescript types

Signed-off-by: Ferdinand Thiessen <[email protected]>
This commit is contained in:
Ferdinand Thiessen
2023-06-10 22:12:36 +07:00
committed by Denis Pushkarev
parent c7c611a79d
commit 27bbec7dc1
4 changed files with 86 additions and 72 deletions
+48
View File
@@ -0,0 +1,48 @@
import type { ModuleName, Target, TargetVersion } from "./shared";
type StringOrRegExp = string | RegExp;
type Modules = StringOrRegExp | readonly StringOrRegExp[];
type BrowserslistQuery = string | ReadonlyArray<string>;
type Environments = {
[target in Target]?: string | number;
};
type Targets = Environments & {
browsers?: Environments | BrowserslistQuery,
esmodules?: boolean,
};
type CompatOptions = {
/** entry / module / namespace / an array of them, by default - all `core-js` modules */
modules?: Modules,
/** a blacklist, entry / module / namespace / an array of them, by default - empty list */
exclude?: Modules,
/** optional browserslist or core-js-compat format query */
targets?: Targets | BrowserslistQuery,
/** used `core-js` version, by default the latest */
version?: string,
/** inverse of the result, shows modules that are NOT required for the target environment */
inverse?: boolean,
/**
* @deprecated use `modules` instead
*/
filter?: Modules
};
type CompatOutput = {
/** array of required modules */
list: ModuleName[],
/** object with targets for each module */
targets: {
[module: ModuleName]: {
[target in Target]?: TargetVersion
}
}
}
declare function compat(options?: CompatOptions): CompatOutput;
export = compat;
@@ -0,0 +1,5 @@
import type { ModuleName, TargetVersion } from "./shared";
declare function getModulesListForTargetVersion(version: TargetVersion): readonly ModuleName[];
export = getModulesListForTargetVersion;
+6 -72
View File
@@ -1,72 +1,6 @@
type StringOrRegExp = string | RegExp;
type Modules = StringOrRegExp | readonly StringOrRegExp[];
type ModuleName = string;
type Target =
| 'android'
| 'bun'
| 'chrome'
| 'chrome-android'
| 'deno'
| 'edge'
| 'electron'
| 'firefox'
| 'firefox-android'
| 'hermes'
| 'ie'
| 'ios'
| 'node'
| 'opera'
| 'opera-android'
| 'phantom'
| 'quest'
| 'react-native'
| 'rhino'
| 'safari'
| 'samsung';
type BrowserslistQuery = string | ReadonlyArray<string>;
type Environments = {
[target in Target]?: string | number;
};
type Targets = Environments & {
browsers?: Environments | BrowserslistQuery,
esmodules?: boolean,
};
type Options = {
/** entry / module / namespace / an array of them, by default - all `core-js` modules */
modules?: Modules,
/** a blacklist, entry / module / namespace / an array of them, by default - empty list */
exclude?: Modules,
/** optional browserslist or core-js-compat format query */
targets?: Targets | BrowserslistQuery,
/** used `core-js` version, by default the latest */
version?: string,
/** inverse of the result, shows modules that are NOT required for the target environment */
inverse?: boolean,
/**
* @deprecated use `modules` instead
*/
filter?: Modules
};
type TargetVersion = string;
type Output = {
/** array of required modules */
list: ModuleName[],
/** object with targets for each module */
targets: {
[module: ModuleName]: {
[target in Target]?: TargetVersion
}
}
}
import type compat from './compat'
import type getModulesListForTargetVersion from './get-modules-list-for-target-version';
import type { ModuleName, Target, TargetVersion } from './shared'
type CompatData = {
[module: ModuleName]: {
@@ -74,11 +8,11 @@ type CompatData = {
}
};
declare const ExportedCompatObject: {
compat(options?: Options): Output,
declare const ExportedCompatObject: typeof compat & {
compat: typeof compat,
/** The subset of modules which available in the passed `core-js` version */
getModulesListForTargetVersion(version: string): readonly ModuleName[],
getModulesListForTargetVersion: typeof getModulesListForTargetVersion,
/** Full list compatibility data */
data: CompatData,
+27
View File
@@ -0,0 +1,27 @@
export type ModuleName = string;
export type Target =
| 'android'
| 'bun'
| 'chrome'
| 'chrome-android'
| 'deno'
| 'edge'
| 'electron'
| 'firefox'
| 'firefox-android'
| 'hermes'
| 'ie'
| 'ios'
| 'node'
| 'opera'
| 'opera-android'
| 'phantom'
| 'quest'
| 'react-native'
| 'rhino'
| 'safari'
| 'samsung';
export type TargetVersion = string;