-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.min.js
1 lines (1 loc) · 5.75 KB
/
index.min.js
1
!function(){"use strict";function o(e){var r={"[object Object]":"object","[object Array]":"array","[object String]":"string","[object Boolean]":"boolean","[object Number]":"number","[object Null]":"null","[object Undefined]":"undefined","[object Function]":"function","[object Date]":"date","[object HTMLDivElement]":"htmlDivElement","[object Blob]":"blob","[object File]":"file","[object MouseEvent]":"mouse_event","[object KeyboardEvent]":"keyboard_event","[object HTMLElement]":"htmlElement","[object Text]":"objectText","[object Map]":"map"}[Object.prototype.toString.call(e)];return"number"==r&&"NaN"==e.toString()?"NaN":r}function a(e){var r=o(e);if("object"===r){for(var t in e)if(e.hasOwnProperty(t)&&!0===a(e[t]))return!0;return!1}if("array"===r){if(0<e.length)return!0;if(0==e.length)return!1;throw new Error(e+" comes to array if-else but the length is neither 0 or more than 0")}if("string"===r){if(0<e.length)return!0;if(0==e.length)return!1;throw new Error(e+" comes to string if-else but the length its not 0 or more than 0")}if("boolean"===r){if(!0===e)return!0;if(!1===e)return!1;throw new Error(e+" comes to boolean if-else but is neither true or false")}if("number"===r)return!0;if("null"===r)return!1;if("undefined"===r)return!1;if("function"===r){var n=e.toString();return!!a(n.substring(n.indexOf("{")+1,n.indexOf("}")).trim().replace(/\r?\n|\r/g,""))}if("date"===r)return!isNaN(e.getTime());if("htmlDivElement"===r||"htmlElement"===r)return 0<r.toString().length;if("blob"===r)return 0<e.size;if("file"===r){for(var t in e)if(e.hasOwnProperty(t))return!0;return!1}if("mouse_event"===r)return!0;if("keyboard_event"===r)return!0;if("NaN"===r)return!1;if("objectText"===r)return!0;if("map"===r)return!0;throw new Error(e+" is not an array, string, boolean or number. This fn only work with those for now")}window.kiong={init:function(){},getMonthNameFromDateObj:function(e,r){if(0<=e&&e<=11){var t=[{name:"january",shortName:"jan"},{name:"february",shortName:"feb"},{name:"march",shortName:"mac"},{name:"april",shortName:"apr"},{name:"may",shortName:"may"},{name:"june",shortName:"jun"},{name:"july",shortName:"jul"},{name:"august",shortName:"aug"},{name:"september",shortName:"sept"},{name:"october",shortName:"oct"},{name:"november",shortName:"nov"},{name:"december",shortName:"dec"}];return r?t[e].shortName:t[e].name}},isObjPresent:a,getObjType:o,getUUID:function(){for(var e=[],r=0;r<256;r++)e[r]=(r<16?"0":"")+r.toString(16);var t=4294967295*Math.random()|0,n=4294967295*Math.random()|0,o=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return e[255&t]+e[t>>8&255]+e[t>>16&255]+e[t>>24&255]+"-"+e[255&n]+e[n>>8&255]+"-"+e[n>>16&15|64]+e[n>>24&255]+"-"+e[63&o|128]+e[o>>8&255]+"-"+e[o>>16&255]+e[o>>24&255]+e[255&i]+e[i>>8&255]+e[i>>16&255]+e[i>>24&255]},isEpochTimeInMs:function(e){var r=Number(Math.floor(Date.now()/1e3)).toString().length,t=Number(Date.now()).toString().length;{if(Number(e).toString().length==t)return!0;if(Number(e).toString().length==r)return!1;throw new TypeError("Parameter passed in is not in seconds or milliseconds")}},getValInNumber:function(e){{if(o(e)==number)return e.toString().split("").map(function(e,r){return 0==r?e:"0"}).join("")-0;throw new Error(e+" must be a number!")}},flattenArray:function(e,r){var t,n=Object.prototype.toString,o=[],i=r&&e||e.slice();if(!e.length)return o;t=i.pop();for(;"[object Array]"===n.call(t)?i.push.apply(i,t):o.push(t),i.length&&void 0!==(t=i.pop()););return o.reverse(),o},removeFromLocalStorage:function(e){return localStorage.removeItem(e)},getFromLocalStorage:function(e){return JSON.parse(localStorage.getItem(e))},saveToLocalStorage:function(e,r){return localStorage.setItem(e,JSON.stringify(r))},roundNumberByDecimalPlaces:function(e,r){{if(!a(e)&&!a(r))throw new Error("roundNumberByDecimalPlaces have 2 params. Either one must be present");if(!a(e)&&a(r))return 0;if(a(e)&&!a(r))return e}{if((""+e).includes("e")){var t=(""+e).split("e"),n="";return 0<+t[1]+r&&(n="+"),+(Math.round(+t[0]+"e"+n+(+t[1]+r))+"e-"+r)}return+(Math.round(e+"e+"+r)+"e-"+r)}},getAllQueryStrings:function(e){var r=[],t={};if(e.split("?")[1]){var n="",o="";e.substring(e.indexOf("?")+1).split("&").forEach(function(e){n=e.split("=")[0],o=e.split("=")[1],r.push({key:n,val:o}),t[n]=o})}return{urlOriginal:e,urlWithoutQueryStrings:e.split("?")[0],queryStringsAsList:r,queryStringAsObj:t}},convertObjToArray:function(e,r){var t=[];for(var n in e)e.hasOwnProperty(n)&&("string"===o(r)&&a(r)&&(e[n][r]=n),t.push(e[n]));return t},isObjNotPresentInArr:function(e,r,t){for(var n=!0,o=0,i=e.length;o<i;o++)if(e[o][t]===r[t]){n=!1;break}return n},isMobileDevice:function(e){var r=navigator.userAgent.match(/Android/i),t=navigator.userAgent.match(/iPhone|iPad|iPod/i),n=navigator.userAgent.match(/BlackBerry/i),o=navigator.userAgent.match(/Opera Mini/i),i=navigator.userAgent.match(/IEMobile/i);{if(!a(e))return r?"android":n?"blackberry":t?"ios":o?"opera":!!i&&"windows";if("android"===(e=e.toLowerCase()))return!!r&&"android";if("blackberry"===e)return!!n&&"blackberry";if("ios"===e)return!!t&&"ios";if("opera"===e)return!!o&&"opera";if("windows"===e)return!!i&&"windows"}},getRandomFromRange:function(e,r){return Math.floor(Math.random()*(r-e+1))+e},recordAudio:function(){return new Promise(function(t,r){navigator.mediaDevices.getUserMedia({audio:!0}).then(function(e){var r=new MediaRecorder(e),o=[];r.addEventListener("dataavailable",function(e){o.push(e.data)});t({start:function(){r.start()},stop:function(){return new Promise(function(n,e){r.onstop=function(){var r=[];o.forEach(function(e){r.push(e)}),o.length=0;var e=new Blob(r),t=URL.createObjectURL(e);n({audioRaw:o,audioBlob:e,audioUrl:t})},r.stop()})},play:function(e){new Audio(e).play()}})},function(e){r(e)})})},thousandSeparator:function(e){var r=e.toString().split(".");return r[0]=r[0].replace(/\B(?=(\d{3})+(?!\d))/g,","),r.join(".")}}}();