UNPKG

@ahmetilhn/handy-utils

Version:

Handy utils offers developers a powerful and easy-to-use toolset. With its clean, modular and scalable code structure, it accelerates development processes and reduces code complexity. With a wide range of functions, it offers ready-made methods for solvi

2 lines (1 loc) 2.67 kB
"use strict";var e;!function(e){e.OBJECT="[object Object]",e.ARRAY="[object Array]",e.STRING="[object String]",e.NUMBER="[object Number]",e.BOOLEAN="[object Boolean]",e.FUNCTION="[object Function]",e.UNDEFINED="[object Undefined]",e.NULL="[object Null]",e.DATE="[object Date]"}(e||(e={}));var t=e;const r=e=>null===e?void 0===e?t.UNDEFINED:t.NULL:Object.prototype.toString.call(e),o=e=>Array.isArray(e)&&r(e)===t.ARRAY,n=e=>"object"==typeof e&&r(e)===t.DATE,i=e=>null!==e&&"object"==typeof e,s=e=>{if(o(e)){const t=[];return e.forEach((e=>{t.push(i(e)?s(e):e)})),t}if(n(e))return new Date(e);if(i(e)){const t={};for(const r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=s(e[r]));return t}return e},c=e=>i(e)&&!o(e)&&!n(e),u=(e,t)=>{if(e===t)return!0;if(typeof e!=typeof t||null===e||null===t)return!1;if(c(e)&&c(t)&&!f(e)&&!f(t))return!0;if(n(e)&&n(t))return u(e.getTime(),t.getTime());if(o(e)&&o(t)){if(!e.length&&!t.length)return!0;if(e.length!==t.length)return!1;let r=0;for(;r<e.length;){if(!u(e[r],t[r]))return!1;r++}return!0}if(c(e)&&c(t)){if(Object.keys(e).length!==Object.keys(t).length)return!1;for(const r in e)if(!u(e[r],t[r]))return!1;return!0}return l(e)&&l(t)?u(e.toString(),t.toString()):e===t},l=e=>"function"==typeof e&&r(e)===t.FUNCTION,f=e=>{if(!c(e))throw new Error("hasPlainObjectRecord should only use for plain object type.");return!!Object.keys(e).length};function p(e,t,r,o){return new(r||(r=Promise))((function(n,i){function s(e){try{u(o.next(e))}catch(e){i(e)}}function c(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?n(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,c)}u((o=o.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const a=e=>null===e,d=e=>void 0===e,b=e=>!d(e)&&!a(e),y=()=>b(globalThis.window);exports.deepClone=s,exports.hasPlainObjectRecord=f,exports.isAndroid=e=>{if(e)return!!/Android/i.exec(e);if(!y())throw new Error("Os detecetor only works on client!");return!!/Android/i.exec(navigator.userAgent)},exports.isArray=o,exports.isBoolean=e=>"boolean"==typeof e&&(!0===e||!1===e)&&r(e)===t.BOOLEAN,exports.isClient=y,exports.isDate=n,exports.isDeepEqual=u,exports.isDefined=b,exports.isFunction=l,exports.isIos=e=>{if(e)return!!/iPhone|iPad|iPod/i.exec(e);if(!y())throw new Error("Os detecetor only works on client!");return!!/iPhone|iPad|iPod/i.exec(navigator.userAgent)},exports.isNull=a,exports.isNumber=e=>"number"==typeof e&&!isNaN(e)&&r(e)===t.NUMBER,exports.isObject=i,exports.isPlainObject=c,exports.isServer=()=>!y(),exports.isUndefined=d,exports.sleep=e=>p(void 0,void 0,void 0,(function*(){return new Promise((t=>setTimeout(t,e)))}));