From e653cba45e4fde8bd631dc8eeaf12c0696717ced Mon Sep 17 00:00:00 2001 From: Sam Saint-Pettersen Date: Sat, 14 May 2016 18:03:44 +0100 Subject: [PATCH] Type definitions and tests for generic-functions (#9309) * Create generic-functions.d.ts * Create genetic-functions-tests.ts * Update generic-functions.d.ts --- generic-functions/generic-functions.d.ts | 15 +++++++++++++++ generic-functions/genetic-functions-tests.ts | 16 ++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 generic-functions/generic-functions.d.ts create mode 100644 generic-functions/genetic-functions-tests.ts diff --git a/generic-functions/generic-functions.d.ts b/generic-functions/generic-functions.d.ts new file mode 100644 index 0000000000..d25ebde7cc --- /dev/null +++ b/generic-functions/generic-functions.d.ts @@ -0,0 +1,15 @@ +// Type definitions for generic-functions +// Project: https://github.com/stpettersens/generic-functions +// Definitions by: Sam Saint-Pettersen +// 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; +} diff --git a/generic-functions/genetic-functions-tests.ts b/generic-functions/genetic-functions-tests.ts new file mode 100644 index 0000000000..d3dc53665a --- /dev/null +++ b/generic-functions/genetic-functions-tests.ts @@ -0,0 +1,16 @@ +/// + +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"