Add definition for uri-template-lite (#43431)

* feat: add definition for uri-template-lite

* style: fix

* chore: fix
This commit is contained in:
Vincenzo Chianese 2020-03-31 17:14:16 -05:00 committed by GitHub
parent 83fd63a9bb
commit 6f369959fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 0 deletions

15
types/uri-template-lite/index.d.ts vendored Normal file
View File

@ -0,0 +1,15 @@
// Type definitions for uri-template-lite 19.12
// Project: https://github.com/litejs/uri-template-lite#readme
// Definitions by: Vincenzo Chianese <https://github.com/DefinitelyTyped>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Minimum TypeScript Version: 3.0
export namespace URI {
function expand(template: string, data: { [key: string]: unknown }): string;
class Template {
constructor(template: string);
expand: (data: { [key: string]: unknown }) => string;
match: (template: string) => { [key: string]: string };
}
}

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"uri-template-lite-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@ -0,0 +1,10 @@
import { URI } from 'uri-template-lite';
// Call `expand` directly
const dataSet = { domain: "example.com", user: "fred", query: "mycelium" };
URI.expand("http://{domain}/~{user}/foo{?query,number}", dataSet);
const template = new URI.Template("http://{domain}/~{user}/foo{?query,number}");
template.expand(dataSet);
template.match("http://example.com/~fred/foo?query=mycelium&number=3");
template.match("http://other.com/?query=mycelium");