Merge pull request #21900 from kjin/shimmer

[shimmer] Add shimmer type definitions
This commit is contained in:
Bowden Kelly
2017-12-06 11:16:58 -08:00
committed by GitHub
4 changed files with 82 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
// Type definitions for Shimmer 1.x
// Project: https://github.com/othiym23/shimmer
// Definitions by: Kelvin Jin <https://github.com/kjin>
// 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<T extends (...args: any[]) => any>(
nodule: object,
name: string,
wrapper: (original: T) => T
): void;
massWrap<T extends (...args: any[]) => any>(
nodules: object[],
names: string[],
wrapper: (original: T) => T
): void;
unwrap(
nodule: object,
name: string
): void;
massUnwrap(
nodules: object[],
names: string[]
): void;
};
export = shimmer;
+23
View File
@@ -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']);
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }