Comparing version 4.1.0 to 4.2.0
@@ -16,4 +16,4 @@ interface ICreateWrapperOptions { | ||
*/ | ||
declare function withCallback(fn: Function, options?: ICreateWrapperOptions): Function; | ||
declare function withCallback<T extends Function>(fn: Function, options?: ICreateWrapperOptions): T; | ||
export { type ICreateWrapperOptions, thenify, withCallback }; |
@@ -1,2 +0,2 @@ | ||
import p from"any-promise";import l from"assert";function F(t,n){return l(typeof t=="function"),f(t,n)}function b(t,n){return l(typeof t=="function"),n=n||{},n.withCallback=!0,f(t,n)}function y(t,n,r){return r===void 0&&(r=!0),function(i,o){if(i)return n(i);let a=arguments.length;if(a<=2||!r)return t(o);if(Array.isArray(r)){let u={};for(let e=1;e<a;e++)u[r[e-1]]=arguments[e];return t(u)}let c=new Array(a-1);for(let u=1;u<a;++u)c[u-1]=arguments[u];t(c)}}function f(t,n){n=n||{};let r=t.name;r=(r||"").replace(/\s|bound(?!$)/g,"");let i=function(){let o=this,a=arguments.length;if(n.withCallback&&typeof arguments[a-1]==="function")return t.apply(o,arguments);let c=new Array(a+1);for(let e=0;e<a;++e)c[e]=arguments[e];let u=a;return new p(function(e,s){c[u]=y(e,s,n==null?void 0:n.multiArgs),t.apply(o,c)})};return Object.defineProperty(i,"name",{value:r}),i}export{F as thenify,b as withCallback}; | ||
"use strict";var F=Object.create;var l=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,w=Object.prototype.hasOwnProperty;var d=(n,t)=>{for(var e in t)l(n,e,{get:t[e],enumerable:!0})},f=(n,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of h(t))!w.call(n,a)&&a!==e&&l(n,a,{get:()=>t[a],enumerable:!(i=b(t,a))||i.enumerable});return n};var p=(n,t,e)=>(e=n!=null?F(C(n)):{},f(t||!n||!n.__esModule?l(e,"default",{value:n,enumerable:!0}):e,n)),k=n=>f(l({},"__esModule",{value:!0}),n);var T={};d(T,{thenify:()=>x,withCallback:()=>I});module.exports=k(T);var y=p(require("any-promise")),s=p(require("assert"));function x(n,t){return(0,s.default)(typeof n=="function"),g(n,t)}function I(n,t){return(0,s.default)(typeof n=="function"),t=t||{},t.withCallback=!0,g(n,t)}function O(n,t,e){return e===void 0&&(e=!0),function(i,a){if(i)return t(i);let u=arguments.length;if(u<=2||!e)return n(a);if(Array.isArray(e)){let c={};for(let r=1;r<u;r++)c[e[r-1]]=arguments[r];return n(c)}let o=new Array(u-1);for(let c=1;c<u;++c)o[c-1]=arguments[c];n(o)}}function g(n,t){t=t||{};let e=n.name;e=(e||"").replace(/\s|bound(?!$)/g,"");let i=function(){let a=this,u=arguments.length;if(t.withCallback&&typeof arguments[u-1]==="function")return n.apply(a,arguments);let o=new Array(u+1);for(let r=0;r<u;++r)o[r]=arguments[r];let c=u;return new y.default(function(r,m){o[c]=O(r,m,t==null?void 0:t.multiArgs),n.apply(a,o)})};return Object.defineProperty(i,"name",{value:e}),i}0&&(module.exports={thenify,withCallback}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "thenify-ex", | ||
"description": "Promisify a callback-based function", | ||
"version": "4.1.0", | ||
"version": "4.2.0", | ||
"authors": [ | ||
@@ -17,3 +17,7 @@ "Jonathan Ong <me@jongleberry.com> (http://jongleberry.com)", | ||
"devDependencies": { | ||
"@types/mocha": "^10.0.10", | ||
"@types/node": "^22.10.10", | ||
"mocha": "11", | ||
"should": "^13.2.3", | ||
"ts-node": "^10.9.2", | ||
"tsup": "^8.3.6", | ||
@@ -20,0 +24,0 @@ "typescript": "5" |
@@ -63,3 +63,3 @@ # thenify | ||
or use `thenify.withCallback()` | ||
or use `withCallback()` | ||
@@ -66,0 +66,0 @@ ```js |
@@ -28,7 +28,7 @@ import Promise from 'any-promise' | ||
export function withCallback(fn: Function, options?: ICreateWrapperOptions) { | ||
export function withCallback<T extends Function>(fn: Function, options?: ICreateWrapperOptions): T { | ||
assert(typeof fn === 'function') | ||
options = options || {} | ||
options.withCallback = true | ||
return createWrapper(fn, options) | ||
return createWrapper(fn, options) as T; | ||
} | ||
@@ -35,0 +35,0 @@ |
Sorry, the diff of this file is not supported yet
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
26518
13
110
7
3