File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments