Skip to content

Commit

Permalink
core-js-compat: Add more typescript types
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux authored and zloirock committed Jun 10, 2023
1 parent a854694 commit 0400546
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 72 deletions.
48 changes: 48 additions & 0 deletions packages/core-js-compat/compat.d.ts
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { ModuleName, TargetVersion } from "./shared";

declare function getModulesListForTargetVersion(version: TargetVersion): readonly ModuleName[];

export = getModulesListForTargetVersion;
78 changes: 6 additions & 72 deletions packages/core-js-compat/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,84 +1,18 @@
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]: {
[target in Target]?: TargetVersion
}
};

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,
Expand Down
27 changes: 27 additions & 0 deletions packages/core-js-compat/shared.d.ts
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 0400546

Please sign in to comment.