UNPKG

call-to-promise

Version:

A lightweight, production-ready, universal library for transforming callback-style functions into Promise-based ones. Works seamlessly across Node.js, Deno, and browsers.

1 lines 2.17 kB
!function(r,n){if("object"==typeof exports&&"object"==typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var t=n();for(var e in t)("object"==typeof exports?exports:r)[e]=t[e]}}(self,(()=>(()=>{"use strict";var r={189:r=>{function n(){var r,n,t,e,i=!0;this.isPending=function(){return i},this.isSucceed=function(){return n},this.isFailed=function(){return r},this.__pointerTestingProperty=0,this.isSameObjectAs=function(r){return r.__pointerTestingProperty=3,this.__pointerTestingProperty=4,r.__pointerTestingProperty===this.__pointerTestingProperty},this.resolve=function(){},this.reject=function(){},this.promise=(t=this,e=function(t){if(!i)throw new Error("Promise is not pending");i=!1,n=t,r=!t},new Promise((function(r,n){t.resolve=function(){e(!0),r.apply(t,arguments.length>1?{0:arguments,length:1}:arguments)},t.reject=function(){e(!1),n.apply(t,arguments.length>1?{0:arguments,length:1}:arguments)}})))}r.exports.defer=function(){return new n}},875:(r,n)=>{function t(r){return"string"==typeof r}n.isString=t,n.isArrayOfStrings=function(r){return Array.isArray(r)&&r.every(t)}},986:(r,n,t)=>{var e=t(189),i=t(875),o={};function s(r,n){if(!i.isString(r))throw new Error('ID has to be "string" only');return n[r]||(n[r]=e.defer()),n[r]}function u(r,n){if(i.isString(r))return s(r,n).promise;if(i.isArrayOfStrings(r))return Promise.all(r.map((function(r){return s(r,n).promise})));throw new Error("getPromise expecting id(string) or id(array<string>)")}n.id=function(r){return s(r,o)},n.successfn=function(r){return s(r,o).resolve},n.failfn=function(r){return s(r,o).reject},n.when=function(r){return u(r,o)},n.build=function(){var r={};return{id:function(n){return s(n,r)},successfn:function(n){return s(n,r).resolve},failfn:function(n){return s(n,r).reject},when:function(n){return u(n,r)}}}}},n={};function t(e){var i=n[e];if(void 0!==i)return i.exports;var o=n[e]={exports:{}};return r[e](o,o.exports,t),o.exports}return t.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(r){if("object"==typeof window)return window}}(),t.g.window.c2p=t(986),{}})()));