UNPKG

@ruingl/pcall

Version:

Calls your functions protected from errors.

7 lines (6 loc) 887 B
"use strict";var s=Object.defineProperty;var o=Object.getOwnPropertyDescriptor;var a=Object.getOwnPropertyNames;var l=Object.prototype.hasOwnProperty;var c=(e,t)=>{for(var r in t)s(e,r,{get:t[r],enumerable:!0})},T=(e,t,r,u)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of a(t))!l.call(e,n)&&n!==r&&s(e,n,{get:()=>t[n],enumerable:!(u=o(t,n))||u.enumerable});return e};var i=e=>T(s({},"__esModule",{value:!0}),e);var w={};c(w,{pcall:()=>p,pcallSync:()=>f});module.exports=i(w);async function p(e,...t){try{return{status:!0,result:await e(...t)}}catch(r){return{status:!1,error:r instanceof Error?r:new Error(String(r))}}}function f(e,...t){try{return{status:!0,result:e(...t)}}catch(r){return{status:!1,error:r instanceof Error?r:new Error(String(r))}}}0&&(module.exports={pcall,pcallSync}); /*! * @ruingl/pcall (1.0.0) * made with <3 by rui reogo * licensed with mit */