From 7ecabec1bf754c8fac3b1de8b5bb91f7d6d45380 Mon Sep 17 00:00:00 2001 From: delphinus Date: Mon, 18 Apr 2016 00:18:47 +0900 Subject: [PATCH] Add definition for iconv (#8999) --- iconv/iconv-tests.ts | 28 ++++++++++++++++++++++++++++ iconv/iconv.d.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 iconv/iconv-tests.ts create mode 100644 iconv/iconv.d.ts diff --git a/iconv/iconv-tests.ts b/iconv/iconv-tests.ts new file mode 100644 index 0000000000..5c121c1b45 --- /dev/null +++ b/iconv/iconv-tests.ts @@ -0,0 +1,28 @@ +/// + +import {Iconv} from "iconv"; +import {Writable} from "stream"; + +const iconv: Iconv.Iconv = new Iconv("utf-8", "cp932"); +const iconvFromFunction: Iconv.Iconv = Iconv("utf-8", "cp932"); + +iconv.writable = true; + +let buffer: Buffer; + +buffer = iconv.convert("hoge"); +buffer = iconv.convert("hoge", "utf-8"); +buffer = iconv.convert(new Buffer("hoge"), "utf-8"); + +let result: boolean; + +result = iconv.write("hoge"); +result = iconv.write("hoge", "utf-8"); +result = iconv.write(new Buffer("hoge"), "utf-8"); + +iconv.end(); +iconv.end("hoge"); +iconv.end("hoge", "utf-8"); +iconv.end(new Buffer("hoge"), "utf-8"); + +const st: Writable = iconv.pipe(new Writable, {end: true}); diff --git a/iconv/iconv.d.ts b/iconv/iconv.d.ts new file mode 100644 index 0000000000..9e21b4bbe6 --- /dev/null +++ b/iconv/iconv.d.ts @@ -0,0 +1,39 @@ +// Type definitions for iconv 2.1.11 +// Project: https://github.com/bnoordhuis/node-iconv +// Definitions by: delphinus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace Iconv { + + interface Static { + + new(fromEncoding: string, toEncoding: string): Iconv; + (fromEncoding: string, toEncoding: string): Iconv; + } + + interface Iconv extends NodeJS.WritableStream { + + writable: boolean; + convert(input: string | Buffer, encoding?: string): Buffer; + write(input: string | Buffer, encoding?: string): boolean; + end(input?: string | Buffer, encoding?: string): void; + + // copy from NodeJS.WritableStream for compatibility + write(buffer: Buffer|string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + + // copy from stream.Stream + pipe(destination: T, options?: { end?: boolean; }): T; + } +} + +declare module "iconv" { + + var Iconv: Iconv.Static; +}