UNPKG

necessary-utils-core

Version:
2 lines (1 loc) 4 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["nu-core"]={})}(this,(function(e){"use strict";class t{constructor(e,t){this.Key=e,this.Value=t}toJSON(){return JSON.stringify(this)}}class r extends Array{constructor(){super()}add(e,r){return super.push(new t(e,r))}getValue(e){var t;return null===(t=super.find((t=>t.Key===e)))||void 0===t?void 0:t.Value}setValue(e,t){const r=super.findIndex((t=>t.Key===e));-1!=r&&(this[r].Value=t)}static fromObject(e){var t;if("string"==typeof e)throw new Error("Data cannot be returned from a String type.");if("number"==typeof e)throw new Error("Data cannot be returned from a Number type.");if("boolean"==typeof e)throw new Error("Data cannot be returned from a Boolean type.");const n=Object.keys(e);if(0===n.length)throw new Error("Object is empty.");let i=new r;for(let r in n){const o=null!==(t=Object.values(e)[r])&&void 0!==t?t:null;i.add(n[r],o)}return i}toValueList(){return this.map((e=>e.Value))}toKeyList(){return this.map((e=>e.Key))}}e.Material=void 0,(e.Material||(e.Material={})).Replacer=class{static ReplaceTRCharsToEN(e){return e.replace(/\Ğ/,"G").replace(/\Ü/g,"U").replace(/\Ş/g,"S").replace(/\İ/g,"I").replace(/\Ö/g,"O").replace(/\Ç/g,"C").replace(/\ğ/g,"g").replace(/\ü/g,"u").replace(/\ş/g,"s").replace(/\ı/g,"i").replace(/\ö/g,"o").replace(/\ç/g,"c")}},e.RegularExpression=void 0,function(e){class t{}t.Email=/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/,e.Validation=t}(e.RegularExpression||(e.RegularExpression={}));class n{constructor(e=0,t=0,r=0,n=0){this._hour=0,this._minute=0,this._second=0,this._millisecond=0,this.Hour=e,this.Minute=t,this.Second=r,this.Millisecond=n}get Hour(){return this._hour}set Hour(e){if(!(e>=0))throw new Error("Hour value cannot be negative.");this._hour=e}get Minute(){return this._minute}set Minute(e){if(!(e>=0))throw new Error("Minute value cannot be negative.");this._minute=e}get Second(){return this._second}set Second(e){if(!(e>=0))throw new Error("Second value cannot be negative.");this._second=e}get Millisecond(){return this._millisecond}set Millisecond(e){if(!(e>=0))throw new Error("Millisecond value cannot be negative.");this._millisecond=e}Ticks(){return n.FromHour(this.Hour)+n.FromMinute(this.Minute)+n.FromSecond(this.Second)+this.Millisecond}SetToDate(e){return e.setHours(this.Hour),e.setMinutes(this.Minute),e.setSeconds(this.Second),e.setMilliseconds(this.Millisecond),e}static FromSecond(e){return 1e3*e}static FromMinute(e){return 60*e*1e3}static FromHour(e){return 60*e*60*1e3}static FromDay(e){return 24*e*60*60*1e3}static FromWeek(e){return 7*e*24*60*60*1e3}}function i(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}class o{static Sleep(e){return i(this,void 0,void 0,(function*(){return new Promise((t=>setTimeout(t,e)))}))}}o.CancellationWork=function(){let e;return function(t,r){clearTimeout(e),e=setTimeout(t,r)}}(),e.Dictionary=r,e.StopWatch=class{constructor(){this.startTime=null,this.endTime=null}get elapsedTime(){return null===this.startTime||null===this.endTime?0:this.endTime-this.startTime}Start(){this.startTime=Date.now()}Stop(){if(null===this.startTime)throw new Error("Watch cannot stopped.");return this.endTime=Date.now(),this.elapsedTime}Reset(){this.startTime=null,this.endTime=null}Resume(){this.endTime=null}},e.TimeSpan=n,e.Timing=o,e.UUID=class{static V4(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}))}},Object.defineProperty(e,"__esModule",{value:!0})}));