mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Merge pull request #21900 from kjin/shimmer
[shimmer] Add shimmer type definitions
This commit is contained in:
Vendored
+35
@@ -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;
|
||||
@@ -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']);
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user