callable-instance
Advanced tools
Comparing version
@@ -1,5 +0,8 @@ | ||
export declare const CallableInstance: ICallableInstance; | ||
export interface ICallableInstance { | ||
new <T>(property: string | symbol): (...argv) => T; | ||
<T>(...argv: any[]): T; | ||
type Func<Args extends unknown[], Return> = (...argv: Args) => Return; | ||
interface ICallableInstance { | ||
// prettier-ignore | ||
new <Args extends unknown[], Return>(property: string | symbol): | ||
Func<Args, Return>; | ||
} | ||
declare const CallableInstance: ICallableInstance; | ||
export = CallableInstance; |
{ | ||
"name": "callable-instance", | ||
"version": "1.0.1", | ||
"description": | ||
"Instances of classes which are directly callable as functions.", | ||
"version": "2.0.0", | ||
"description": "Instances of classes which are directly callable as functions.", | ||
"repository": "CGamesPlay/node-callable-instance", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"test": "grunt test" | ||
"test": "mocha -c -R progress" | ||
}, | ||
"keywords": ["instance", "function", "object", "class", "callable"], | ||
"keywords": [ | ||
"instance", | ||
"function", | ||
"object", | ||
"class", | ||
"callable" | ||
], | ||
"bugs": { | ||
@@ -18,8 +24,10 @@ "url": "https://github.com/CGamesPlay/node-callable-instance/issues" | ||
"devDependencies": { | ||
"grunt": "^1.0.1", | ||
"grunt-contrib-watch": "^1.0.0", | ||
"grunt-exec": "^1.0.1", | ||
"mocha": "^3.1.2" | ||
"mocha": "^8.0.1" | ||
}, | ||
"files": ["index.js", "index.d.ts", "LICENSE", "README.md"] | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"LICENSE", | ||
"README.md" | ||
] | ||
} |
# node-callable-instance | ||
[](https://travis-ci.org/CGamesPlay/node-callable-instance) | ||
[](https://travis-ci.org/CGamesPlay/node-callable-instance)   [](https://www.npmjs.com/package/callable-instance)  | ||
@@ -17,4 +17,4 @@ This module allows you to create an ES6 class that is callable as a function. The invocation is sent to one of the object's normal prototype methods. | ||
``` | ||
var CallableInstance = require('callable-instance'); | ||
```javascript | ||
var CallableInstance = require("callable-instance"); | ||
@@ -25,3 +25,3 @@ class ExampleClass extends CallableInstance { | ||
// method. | ||
super('instanceMethod'); | ||
super("instanceMethod"); | ||
} | ||
@@ -41,5 +41,21 @@ | ||
// normal function. | ||
test.apply(null, [ 1, 2, 3 ]); | ||
test.apply(null, [1, 2, 3]); | ||
``` | ||
For TypeScript, you need to supply the arguments and return value of the function. Note that the types specified may differ from the argument and return value types of the target method; this is an error due to a limitation of TypeScript. | ||
```typescript | ||
import * as CallableInstance from "callable-instance"; | ||
class ExampleClass extends CallableInstance<[number], string> { | ||
constructor() { | ||
super("instanceMethod"); | ||
} | ||
instanceMethod(input: number): string { | ||
return `${input}`; | ||
} | ||
} | ||
``` | ||
### Inherited Properties | ||
@@ -53,5 +69,5 @@ | ||
``` | ||
```javascript | ||
var test = new ExampleClass(); | ||
test.name = "hello!" | ||
test.name = "hello!"; | ||
console.log(test.name); // Will print 'instanceMethod' | ||
@@ -61,8 +77,8 @@ | ||
constructor() { | ||
super('instanceMethod'); | ||
Object.defineProperty(this, 'name', { | ||
super("instanceMethod"); | ||
Object.defineProperty(this, "name", { | ||
value: void 0, | ||
enumerable: true, | ||
writeable: true, | ||
configurable: true | ||
configurable: true, | ||
}); | ||
@@ -69,0 +85,0 @@ } |
6270
18.41%1
-75%19
18.75%107
17.58%