Type definitions and tests for generic-functions (#9309)

* Create generic-functions.d.ts

* Create genetic-functions-tests.ts

* Update generic-functions.d.ts
This commit is contained in:
Sam Saint-Pettersen
2016-05-14 18:03:44 +01:00
committed by Masahiro Wakame
parent eeede9d1ad
commit e653cba45e
2 changed files with 31 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
// Type definitions for generic-functions
// Project: https://github.com/stpettersens/generic-functions
// Definitions by: Sam Saint-Pettersen <https://github.com/stpettersens>
// Definitions: https://github.com/definitelytyped/DefinitelyTyped
declare module "generic-functions" {
function strcmp(str1: string, str2: string): boolean;
function icstrcmp(str1: string, str2: string): boolean;
function strendswith(str: string, suffix: string): boolean;
function icstrendswith(str: string, suffix: string): boolean;
function endswithdot(str: string): string;
function println(message: string): void;
function printlns(message: string[]): void;
function objGetKeyByValue(object: Object, value: any): string;
}

View File

@@ -0,0 +1,16 @@
/// <reference path="generic-functions.d.ts" />
import g = require('generic-functions');
var tvShow: Object = {
seasons: 2,
show: "Better Call Saul"
};
console.log(g.strcmp("foo", "foo")); // => true
console.log(g.icstrcmp("BAR", "bar")); // => true
console.log(g.strendswith("file.pdf", "pdf")); // => true
console.log(g.icstrendswith("file.PDF", "pdf")); // => true
console.log(g.endswithdot("file.pdf")); // => ".pdf"
console.log(g.objGetKeyByValue(tvShow, 2)); // => "seasons"
console.log(g.objGetKeyByValue(tvShow, "Better Call Saul")); // => "show"