From f7c4e50fc1053dace974f97e545fde1dc06b9a6a Mon Sep 17 00:00:00 2001 From: Titan Date: Thu, 27 Oct 2016 09:53:14 +0800 Subject: [PATCH] Add typings for nanomsg --- nanomsg/index.d.ts | 22 ++++++++++++++++++++++ nanomsg/nanomsg-tests.ts | 17 +++++++++++++++++ nanomsg/tsconfig.json | 19 +++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 nanomsg/index.d.ts create mode 100644 nanomsg/nanomsg-tests.ts create mode 100644 nanomsg/tsconfig.json diff --git a/nanomsg/index.d.ts b/nanomsg/index.d.ts new file mode 100644 index 0000000000..c2fb7e7f1f --- /dev/null +++ b/nanomsg/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for nanomsg 3.2.3 +// Project: https://github.com/nickdesaulniers/node-nanomsg +// Definitions by: Titan +// Definitions: https://github.com/DefinitelyTyped/nanomsg + +/// + +declare module "nanomsg" { + export interface EventCallback { + (data: Buffer): void; + } + export class Socket { + constructor(type: string, opts: Object); + shutdown(addr: string): void; + bind(addr: string): void; + connect(addr: string): void; + close(): void; + send(buf: Buffer | string): number; + on(event: string, cb: EventCallback): void; + } + export function socket(type: string, opts?: Object): Socket; +} diff --git a/nanomsg/nanomsg-tests.ts b/nanomsg/nanomsg-tests.ts new file mode 100644 index 0000000000..a731312890 --- /dev/null +++ b/nanomsg/nanomsg-tests.ts @@ -0,0 +1,17 @@ +import { Socket, socket } from "nanomsg"; +const pub: Socket = socket("pub"); +const sub: Socket = socket("sub"); + +const addr: string = "tcp://127.0.0.1:7789" +pub.bind(addr); +sub.connect(addr); + +sub.on('data', function (buf) { + console.log(String(buf)); + pub.close(); + sub.close(); +}); + +setTimeout(function () { + pub.send("Hello from nanomsg!"); +}, 100); diff --git a/nanomsg/tsconfig.json b/nanomsg/tsconfig.json new file mode 100644 index 0000000000..cd61d8df57 --- /dev/null +++ b/nanomsg/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": false, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "nanomsg-tests.ts" + ] +}