From 2a24bbb7ca4f13e52c7f6a0ab6144b565bf1ef55 Mon Sep 17 00:00:00 2001 From: Nick Zelei Date: Fri, 29 Jul 2016 23:12:55 -0500 Subject: [PATCH] Add definitions for utf8 module (#10329) * added utf8 module typings added utf8 module typings * added tests for utf8 added tests for utf8 * moved import to es6 compatible moved import to es6 compatible * updated var to const updated var to const * removed interface and moved into module removed interface and moved into module * update const with let as it can be changed update const with let as it can be changed --- utf8/utf8-tests.ts | 19 +++++++++++++++++++ utf8/utf8.d.ts | 24 ++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 utf8/utf8-tests.ts create mode 100644 utf8/utf8.d.ts diff --git a/utf8/utf8-tests.ts b/utf8/utf8-tests.ts new file mode 100644 index 0000000000..852311ea6c --- /dev/null +++ b/utf8/utf8-tests.ts @@ -0,0 +1,19 @@ +/// + +import * as utf8 from "utf8"; + +function test_encode(): void { + utf8.encode("\x49"); + utf8.encode("\uD800\uDC01"); +} + +function test_decode(): void { + utf8.decode("\xC2\x49"); + utf8.decode("\xF0\x90\x80\x81"); +} + +function test_version(): void { + if (typeof utf8.version === "string") { + console.log(utf8.version); + } +} diff --git a/utf8/utf8.d.ts b/utf8/utf8.d.ts new file mode 100644 index 0000000000..e9ee9d16b1 --- /dev/null +++ b/utf8/utf8.d.ts @@ -0,0 +1,24 @@ +// Type definitions for utf8 v2.1.1 +// Project: https://github.com/mathiasbynens/utf8.js +// Definitions by: Nick Zelei +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module "utf8" { + /** + * A string representing the semantic version number. + */ + let version: string; + /** + * Encodes any given JavaScript string (string) as UTF-8, and returns the UTF-8-encoded version of the string. + * It throws an error if the input string contains a non-scalar value, i.e. a lone surrogate. + * @param {string} inputString + */ + function encode(inputString: string): string; + + /** + * Decodes any given UTF-8-encoded string (byteString) as UTF-8, and returns the UTF-8-decoded version of the string. + * It throws an error when malformed UTF-8 is detected. + * @param {string} byteString + */ + function decode(byteString: string): string; +}