mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-06 07:47:04 +00:00
Fix incorrect uritemplate typings
This commit is contained in:
Vendored
+27
-42
@@ -1,6 +1,7 @@
|
||||
// Type definitions for URI Template JS 0.3.4
|
||||
// Project: https://github.com/fxa/uritemplate-js
|
||||
// Definitions by: Chui Tey <https://github.com/teyc>
|
||||
// Ruben Taelman <https://github.com/rubensworks>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
/*
|
||||
@@ -8,49 +9,33 @@
|
||||
Available via the MIT license.
|
||||
*/
|
||||
|
||||
declare namespace uritemplate {
|
||||
|
||||
interface UriTemplate {
|
||||
|
||||
/**
|
||||
* Expands template into a string using parameter
|
||||
* supplied
|
||||
*/
|
||||
expand(data: {}): string;
|
||||
}
|
||||
|
||||
interface UriTemplateErrorOptions {
|
||||
expressionText: string
|
||||
message: string
|
||||
position: number
|
||||
}
|
||||
|
||||
interface UriTemplateError {
|
||||
new (options: UriTemplateErrorOptions): UriTemplateError
|
||||
}
|
||||
|
||||
|
||||
interface UriTemplateStatic {
|
||||
|
||||
/**
|
||||
* parse template text returning instance of UriTemplate
|
||||
* @param template text
|
||||
* @return instance of UriTemplate
|
||||
* @example
|
||||
* import UriTemplate = require('uritemplate');
|
||||
* let template = UriTemplate.parse('http://localhost/query{?name,city}');
|
||||
* let result = template.expand({name: 'Jayden', city: 'Wodonga'});
|
||||
* // returns http://localhost/query?name=Jayden&city=Wodonga
|
||||
*/
|
||||
parse(templateText: string): uritemplate.UriTemplate;
|
||||
|
||||
UriTemplateError: new (options: uritemplate.UriTemplateErrorOptions) => uritemplate.UriTemplateError;
|
||||
}
|
||||
export class UriTemplate {
|
||||
|
||||
/**
|
||||
* Expands template into a string using parameter
|
||||
* supplied
|
||||
*/
|
||||
expand(data: {}): string;
|
||||
}
|
||||
|
||||
declare module 'uritemplate' {
|
||||
|
||||
export var UriTemplate: uritemplate.UriTemplateStatic;
|
||||
|
||||
interface UriTemplateErrorOptions {
|
||||
expressionText: string
|
||||
message: string
|
||||
position: number
|
||||
}
|
||||
|
||||
export class UriTemplateError {
|
||||
constructor(options: UriTemplateErrorOptions);
|
||||
}
|
||||
|
||||
/**
|
||||
* parse template text returning instance of UriTemplate
|
||||
* @param template text
|
||||
* @return instance of UriTemplate
|
||||
* @example
|
||||
* import UriTemplate = require('uritemplate');
|
||||
* let template = UriTemplate.parse('http://localhost/query{?name,city}');
|
||||
* let result = template.expand({name: 'Jayden', city: 'Wodonga'});
|
||||
* // returns http://localhost/query?name=Jayden&city=Wodonga
|
||||
*/
|
||||
export function parse(templateText: string): UriTemplate;
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
|
||||
import { UriTemplate } from 'uritemplate';
|
||||
import {parse as parseUriTemplate, UriTemplate, UriTemplateError} from "uritemplate";
|
||||
|
||||
function test_uritemplate() {
|
||||
|
||||
// syntax check: UriTemplate.parse
|
||||
var template = UriTemplate.parse('http://localhost/categories{/categoryId}{?sort,pageNumber}');
|
||||
var template: UriTemplate = parseUriTemplate('http://localhost/categories{/categoryId}{?sort,pageNumber}');
|
||||
|
||||
// syntax check: template.expand
|
||||
var url = template.expand({
|
||||
var url: string = template.expand({
|
||||
categoryId : 'shoes',
|
||||
sort: 'price',
|
||||
pageNumber: 8
|
||||
});
|
||||
|
||||
// import module check
|
||||
var expectedUrl = 'http://localhost/categories/shoes?sort=price&pageNumber=8';
|
||||
var expectedUrl: string = 'http://localhost/categories/shoes?sort=price&pageNumber=8';
|
||||
if (expectedUrl != url) {
|
||||
throw `Expected ${expectedUrl}, got ${url}`;
|
||||
} else {
|
||||
console.log('Test passed');
|
||||
}
|
||||
|
||||
// syntax check: new UriTemplate.UriTemplateError
|
||||
let error = new UriTemplate.UriTemplateError({
|
||||
// syntax check: new UriTemplateError
|
||||
let error: UriTemplateError = new UriTemplateError({
|
||||
expressionText: 'error expression',
|
||||
message: 'error message',
|
||||
position: 5
|
||||
|
||||
Reference in New Issue
Block a user