From e04481995185d21b09f4c4570c3dc27dff58ccc0 Mon Sep 17 00:00:00 2001 From: Kelvin Jin Date: Fri, 1 Dec 2017 15:03:59 -0800 Subject: [PATCH] [shimmer] Add shimmer type definitions --- types/shimmer/index.d.ts | 35 ++++++++++++++++++++++++++++++++++ types/shimmer/shimmer-tests.ts | 23 ++++++++++++++++++++++ types/shimmer/tsconfig.json | 23 ++++++++++++++++++++++ types/shimmer/tslint.json | 1 + 4 files changed, 82 insertions(+) create mode 100644 types/shimmer/index.d.ts create mode 100644 types/shimmer/shimmer-tests.ts create mode 100644 types/shimmer/tsconfig.json create mode 100644 types/shimmer/tslint.json diff --git a/types/shimmer/index.d.ts b/types/shimmer/index.d.ts new file mode 100644 index 0000000000..fd62f8074c --- /dev/null +++ b/types/shimmer/index.d.ts @@ -0,0 +1,35 @@ +// Type definitions for Shimmer 1.x +// Project: https://github.com/othiym23/shimmer +// Definitions by: Kelvin Jin +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +declare global { + interface Function { + __wrapped?: boolean; + } +} + +declare const shimmer: { + (options: { logger?(msg: string): void }): void; + wrap any>( + nodule: object, + name: string, + wrapper: (original: T) => T + ): void; + massWrap any>( + nodules: object[], + names: string[], + wrapper: (original: T) => T + ): void; + unwrap( + nodule: object, + name: string + ): void; + massUnwrap( + nodules: object[], + names: string[] + ): void; +}; + +export = shimmer; diff --git a/types/shimmer/shimmer-tests.ts b/types/shimmer/shimmer-tests.ts new file mode 100644 index 0000000000..c7b51debe2 --- /dev/null +++ b/types/shimmer/shimmer-tests.ts @@ -0,0 +1,23 @@ +import * as shimmer from 'shimmer'; + +const isWrapped: boolean = [].forEach.__wrapped || false; + +shimmer.wrap(Array.prototype, 'forEach', (forEach) => { + return (...args: any[]) => { + forEach(...args); + }; +}); + +shimmer.unwrap(Array.prototype, 'forEach'); + +shimmer.massWrap([Map.prototype, Set.prototype], ['clear', 'forEach'], (fn) => { + return (...args: any[]) => { + const result = fn(...args); + if (result) { + throw new Error(); + } + return result; + }; +}); + +shimmer.massUnwrap([Map.prototype, Set.prototype], ['clear', 'forEach']); diff --git a/types/shimmer/tsconfig.json b/types/shimmer/tsconfig.json new file mode 100644 index 0000000000..3883d26b91 --- /dev/null +++ b/types/shimmer/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "shimmer-tests.ts" + ] +} \ No newline at end of file diff --git a/types/shimmer/tslint.json b/types/shimmer/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/shimmer/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }