mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-28 10:30:31 +00:00
29 lines
908 B
TypeScript
29 lines
908 B
TypeScript
import { parse as parseUriTemplate, UriTemplate, UriTemplateError } from "uritemplate";
|
|
|
|
function test_uritemplate() {
|
|
// syntax check: UriTemplate.parse
|
|
const template: UriTemplate = parseUriTemplate('http://localhost/categories{/categoryId}{?sort,pageNumber}');
|
|
|
|
// syntax check: template.expand
|
|
const url: string = template.expand({
|
|
categoryId : 'shoes',
|
|
sort: 'price',
|
|
pageNumber: 8
|
|
});
|
|
|
|
// import module check
|
|
const expectedUrl = 'http://localhost/categories/shoes?sort=price&pageNumber=8';
|
|
if (expectedUrl !== url) {
|
|
throw new Error(`Expected ${expectedUrl}, got ${url}`);
|
|
} else {
|
|
console.log('Test passed');
|
|
}
|
|
|
|
// syntax check: new UriTemplateError
|
|
const error: UriTemplateError = new UriTemplateError({
|
|
expressionText: 'error expression',
|
|
message: 'error message',
|
|
position: 5
|
|
});
|
|
}
|