Skip to content

Commit fc0d31f

Browse files
committed
feat: add definitely-typed module
1 parent 9e23c9e commit fc0d31f

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/utils/definitely-typed.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { expect, test } from "vitest";
2+
import { getDTPackageName, isDTPackage } from "./definitely-typed";
3+
4+
test("getDTPackageName", () => {
5+
expect(getDTPackageName("foo")).toBe("@types/foo");
6+
expect(getDTPackageName("@foo/bar")).toBe("@types/foo__bar");
7+
expect(getDTPackageName("@types/foo")).toBe("@types/foo");
8+
});
9+
10+
test("isDTPackage", () => {
11+
expect(isDTPackage("foo")).toBeFalsy();
12+
expect(isDTPackage("@foo/bar")).toBeFalsy();
13+
expect(isDTPackage("@types/foo")).toBeTruthy();
14+
});

lib/utils/definitely-typed.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
`getDTPackageName` returns the name of the corresponding DefinitelyTyped package
3+
(e.g., `foo` => `@types/foo`, `@foo/bar` => `@types/foo__bar`).
4+
*/
5+
export function getDTPackageName(name: string): string {
6+
if (name.startsWith("@types/")) return name;
7+
return `@types/${name.replace("@", "").replace("/", "__")}`;
8+
}
9+
10+
/** `isDTPackage` returns true if the package belongs to the `@types` scope. */
11+
export function isDTPackage(name: string): boolean {
12+
return name.startsWith("@types/");
13+
}

0 commit comments

Comments
 (0)