docuri
docuri copied to clipboard
typescript definition file
Would you be open to adding a typescript definition file to your repository? I can create one for you
What is a typescript definition file?
It's basically a file that helps typescript to know whether code is using the library correctly, and editors can use it for autocomplete and syntax checking. Documentation here
I created one locally, but by adding it to your repository (and modifying package.json to point to it) anyone using your library would get the definitions automatically. It looks like this:
docuri.d.ts
:
declare module "docuri" {
interface Route<T> {
// parse DocURI string to object
(str: string): T | false;
// generate DocURI string from object
(obj: T): string;
// change DocURI string parts with values provided by object returning a string
(str: string, obj: T): string;
}
export function route<T>(route: string): Route<T>;
}
ok thanks, I'd accept a pull
Thanks @arolson101, I'd also like to see this typescript definition file in the npm package. Since you've already done the work of creating the definition, do you want to make the pull request? If you don't, I could make the pull request, and naturally give you credit.
Here's my variation on a typescript definition file, in case you want to specify what kind of string is output.
declare module "docuri" {
interface Route<RouteObj, RouteString> {
// parse DocURI string to object
(str: RouteString): RouteObj | false;
// generate DocURI string from object
(obj: RouteObj): RouteString;
// change DocURI string parts with values provided by object returning a string
(str: RouteString, obj: RouteObj): RouteString;
}
export function route<RouteObj, RouteString>(
route: string,
): Route<RouteObj, RouteString>;
}