From d34cfd7426d05c6fa33744ce187f1a6070d1fa57 Mon Sep 17 00:00:00 2001 From: Peter Safranek Date: Sat, 8 Oct 2016 01:14:55 -0700 Subject: [PATCH 1/3] Add type definitions for koa-send. --- koa-send/koa-send-tests.ts | 23 +++++++++++++++++++++++ koa-send/koa-send.d.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 koa-send/koa-send-tests.ts create mode 100644 koa-send/koa-send.d.ts diff --git a/koa-send/koa-send-tests.ts b/koa-send/koa-send-tests.ts new file mode 100644 index 0000000000..630bdcbddb --- /dev/null +++ b/koa-send/koa-send-tests.ts @@ -0,0 +1,23 @@ +/// +/// + +import * as Koa from "koa"; +import * as send from "koa-send"; + +const app = new Koa(); + +app.use(async (ctx: Koa.Context) => { + const path: string = await send(ctx, 'stimpy.html'); +}); + +app.use(async (ctx: Koa.Context) => { + await send(ctx, 'stimpy.html', { + root: '../static-files', + index: 'index.html', + maxAge: 10, + hidden: true, + format: true, + gzip: true, + setHeaders: () => {}, + }); +}); diff --git a/koa-send/koa-send.d.ts b/koa-send/koa-send.d.ts new file mode 100644 index 0000000000..9ed8805412 --- /dev/null +++ b/koa-send/koa-send.d.ts @@ -0,0 +1,27 @@ +// Type definitions for koa-send v3.x +// Project: https://github.com/koajs/send +// Definitions by: Peter Safranek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module "koa-send" { + + import * as Koa from "koa"; + + interface ISendOptions { + root?: string; + index?: string; + maxAge?: number; + hidden?: boolean; + format?: boolean; + gzip?: boolean; + setHeaders?: Function; + } + + function send(ctx: Koa.Context, path: string, opts?: ISendOptions): Promise; + + namespace send {} + + export = send; +} From 1940248920cac6a16922652b318b4247e00d6e38 Mon Sep 17 00:00:00 2001 From: Peter Safranek Date: Sun, 16 Oct 2016 17:56:04 -0700 Subject: [PATCH 2/3] Use correct file name and add tsconfig. --- koa-send/index.d.ts | 22 ++++++++++++++++++++++ koa-send/koa-send-tests.ts | 6 ++---- koa-send/koa-send.d.ts | 27 --------------------------- koa-send/tsconfig.json | 19 +++++++++++++++++++ 4 files changed, 43 insertions(+), 31 deletions(-) create mode 100644 koa-send/index.d.ts delete mode 100644 koa-send/koa-send.d.ts create mode 100644 koa-send/tsconfig.json diff --git a/koa-send/index.d.ts b/koa-send/index.d.ts new file mode 100644 index 0000000000..f8424c1a85 --- /dev/null +++ b/koa-send/index.d.ts @@ -0,0 +1,22 @@ +// Type definitions for koa-send v3.x +// Project: https://github.com/koajs/send +// Definitions by: Peter Safranek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import * as Koa from 'koa'; + +interface ISendOptions { + root?: string; + index?: string; + maxAge?: number; + hidden?: boolean; + format?: boolean; + gzip?: boolean; + setHeaders?: Function; +} + +declare function send(ctx: Koa.Context, path: string, opts?: ISendOptions): Promise; + +declare namespace send {} + +export = send; diff --git a/koa-send/koa-send-tests.ts b/koa-send/koa-send-tests.ts index 630bdcbddb..e231d4e6b3 100644 --- a/koa-send/koa-send-tests.ts +++ b/koa-send/koa-send-tests.ts @@ -1,8 +1,6 @@ -/// -/// -import * as Koa from "koa"; -import * as send from "koa-send"; +import * as Koa from 'koa'; +import * as send from 'koa-send'; const app = new Koa(); diff --git a/koa-send/koa-send.d.ts b/koa-send/koa-send.d.ts deleted file mode 100644 index 9ed8805412..0000000000 --- a/koa-send/koa-send.d.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Type definitions for koa-send v3.x -// Project: https://github.com/koajs/send -// Definitions by: Peter Safranek -// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - -/// - -declare module "koa-send" { - - import * as Koa from "koa"; - - interface ISendOptions { - root?: string; - index?: string; - maxAge?: number; - hidden?: boolean; - format?: boolean; - gzip?: boolean; - setHeaders?: Function; - } - - function send(ctx: Koa.Context, path: string, opts?: ISendOptions): Promise; - - namespace send {} - - export = send; -} diff --git a/koa-send/tsconfig.json b/koa-send/tsconfig.json new file mode 100644 index 0000000000..6544b6f3e1 --- /dev/null +++ b/koa-send/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", + "koa-send-tests.ts" + ] +} From b93dc24e1bb336852b9ad97509b84b90afe4e28a Mon Sep 17 00:00:00 2001 From: Peter Safranek Date: Thu, 24 Nov 2016 00:50:58 -0800 Subject: [PATCH 3/3] Add typings for argon2. --- argon2/argon2-tests.ts | 35 +++++++++++++++++++++++++++++++++ argon2/index.d.ts | 44 ++++++++++++++++++++++++++++++++++++++++++ argon2/tsconfig.json | 19 ++++++++++++++++++ argon2/tslint.json | 1 + 4 files changed, 99 insertions(+) create mode 100644 argon2/argon2-tests.ts create mode 100644 argon2/index.d.ts create mode 100644 argon2/tsconfig.json create mode 100644 argon2/tslint.json diff --git a/argon2/argon2-tests.ts b/argon2/argon2-tests.ts new file mode 100644 index 0000000000..566292b4fa --- /dev/null +++ b/argon2/argon2-tests.ts @@ -0,0 +1,35 @@ + +import { defaults, limits, hash, verify, generateSalt } from 'argon2'; + +main(); + +async function main() { + + const defaultTimeCost: number = defaults.timeCost; + const defaultMemoryCost: number = defaults.memoryCost; + const defaultParallelism: number = defaults.parallelism; + const defaultArgon2d: boolean = defaults.argon2d; + + const minMemoryCost: number = limits.memoryCost.min; + const maxMemoryCost: number = limits.memoryCost.max; + const minTimeCost: number = limits.timeCost.min; + const maxTimeCost: number = limits.timeCost.max; + const minParallelism: number = limits.parallelism.min; + const maxParallelism: number = limits.parallelism.max; + + const options = { + timeCost: 4, + memoryCost: 13, + parallelism: 2, + argon2d: true, + }; + + const hash1: string = await hash('secret', new Buffer(''), options); + const hash2: string = await hash('secret', new Buffer(''), {}); + const hash3: string = await hash('secret', new Buffer('')); + + const verified: boolean = await verify('long-hash', 'secret'); + + const salt1: Buffer = await generateSalt(); + const salt2: Buffer = await generateSalt(32); +} diff --git a/argon2/index.d.ts b/argon2/index.d.ts new file mode 100644 index 0000000000..f4e4c41d1f --- /dev/null +++ b/argon2/index.d.ts @@ -0,0 +1,44 @@ +// Type definitions for argon2 0.14 +// Project: https://github.com/ranisalt/node-argon2#readme +// Definitions by: Peter Safranek +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare namespace argon2 { + + export var defaults: { + timeCost: number; + memoryCost: number; + parallelism: number; + argon2d: boolean; + }; + + export var limits: { + memoryCost: { + min: number; + max: number; + }; + timeCost: { + min: number; + max: number; + }; + parallelism: { + min: number; + max: number; + }; + }; + + export function hash(plain: string, salt: Buffer, options?: { + timeCost?: number; + memoryCost?: number; + parallelism?: number; + argon2d?: boolean; + }): Promise; + + export function verify(hash: string, plain: string): Promise; + + export function generateSalt(length?: number): Promise; +} + +export = argon2; diff --git a/argon2/tsconfig.json b/argon2/tsconfig.json new file mode 100644 index 0000000000..5af6cc5d73 --- /dev/null +++ b/argon2/tsconfig.json @@ -0,0 +1,19 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "noImplicitAny": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "argon2-tests.ts" + ] +} diff --git a/argon2/tslint.json b/argon2/tslint.json new file mode 100644 index 0000000000..377cc837d4 --- /dev/null +++ b/argon2/tslint.json @@ -0,0 +1 @@ +{ "extends": "../tslint.json" }