UNPKG

jsegd

Version:

Utilitário de ferramentas para desenvolvimento

3 lines (2 loc) 11.4 kB
let e=class{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,r.unregister(this),e}free(){const e=this.__destroy_into_raw();l.__wbg_validate_free(e,0)}static is_valid_cep(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_;return 0!==l.validate_is_valid_cep(t,r)}static is_valid_cnpj(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_;return 0!==l.validate_is_valid_cnpj(t,r)}static is_valid_cpf(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_;return 0!==l.validate_is_valid_cpf(t,r)}static is_valid_email(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_;return 0!==l.validate_is_valid_email(t,r)}static is_valid_evp(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_;return 0!==l.validate_is_valid_evp(t,r)}static is_valid_mobile(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_;return 0!==l.validate_is_valid_mobile(t,r)}};Symbol.dispose&&(e.prototype[Symbol.dispose]=e.prototype.free);let t=class{__destroy_into_raw(){const e=this.__wbg_ptr;return this.__wbg_ptr=0,n.unregister(this),e}free(){const e=this.__destroy_into_raw();l.__wbg_writtenout_free(e,0)}static format_currency(e,t){let r,n;try{const s=l.writtenout_format_currency(e,t);var i=s[0],a=s[1];if(s[3])throw i=0,a=0,takeFromExternrefTable0(s[2]);return r=i,n=a,getStringFromWasm0(i,a)}finally{l.__wbindgen_free(r,n,1)}}static format_date(e){let t,r;try{const a=l.writtenout_format_date(e);var n=a[0],i=a[1];if(a[3])throw n=0,i=0,takeFromExternrefTable0(a[2]);return t=n,r=i,getStringFromWasm0(n,i)}finally{l.__wbindgen_free(t,r,1)}}static format_deadline(e,t){let r,n;try{const s=l.writtenout_format_deadline(e,t);var i=s[0],a=s[1];if(s[3])throw i=0,a=0,takeFromExternrefTable0(s[2]);return r=i,n=a,getStringFromWasm0(i,a)}finally{l.__wbindgen_free(r,n,1)}}static format_number(e){let t,r;try{const a=l.writtenout_format_number(e);var n=a[0],i=a[1];if(a[3])throw n=0,i=0,takeFromExternrefTable0(a[2]);return t=n,r=i,getStringFromWasm0(n,i)}finally{l.__wbindgen_free(t,r,1)}}};Symbol.dispose&&(t.prototype[Symbol.dispose]=t.prototype.free);const r="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((e=>l.__wbg_validate_free(e>>>0,1))),n="undefined"==typeof FinalizationRegistry?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry((e=>l.__wbg_writtenout_free(e>>>0,1)));function getStringFromWasm0(e,t){return function(e,t){o+=t,o>=s&&(a=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),a.decode(),o=t);return a.decode(getUint8ArrayMemory0().subarray(e,e+t))}(e>>>=0,t)}let i=null;function getUint8ArrayMemory0(){return null!==i&&0!==i.byteLength||(i=new Uint8Array(l.memory.buffer)),i}function passStringToWasm0(e,t,r){if(void 0===r){const r=c.encode(e),n=t(r.length,1)>>>0;return getUint8ArrayMemory0().subarray(n,n+r.length).set(r),_=r.length,n}let n=e.length,i=t(n,1)>>>0;const a=getUint8ArrayMemory0();let s=0;for(;s<n;s++){const t=e.charCodeAt(s);if(t>127)break;a[i+s]=t}if(s!==n){0!==s&&(e=e.slice(s)),i=r(i,n,n=s+3*e.length,1)>>>0;const t=getUint8ArrayMemory0().subarray(i+s,i+n);s+=c.encodeInto(e,t).written,i=r(i,n,s,1)>>>0}return _=s,i}function takeFromExternrefTable0(e){const t=l.__wbindgen_externrefs.get(e);return l.__externref_table_dealloc(e),t}let a=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});a.decode();const s=2146435072;let o=0;const c=new TextEncoder;"encodeInto"in c||(c.encodeInto=function(e,t){const r=c.encode(e);return t.set(r),{read:e.length,written:r.length}});let l,_=0;class LocalCache{storeName;cacheExpirationMs;static instances=new Map;dbPromise=null;constructor(e,t){this.storeName=e,this.cacheExpirationMs=t}static getInstance(e,t){return LocalCache.instances.has(e)||LocalCache.instances.set(e,new LocalCache(e,t)),LocalCache.instances.get(e)}promisifyRequest(e){return new Promise(((t,r)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>r(e.error)}))}async openDatabase(){if(this.dbPromise)return this.dbPromise;const e=`jsegd_cache_${this.storeName}`;return this.dbPromise=new Promise(((t,r)=>{const n=indexedDB.open(e,1);n.onupgradeneeded=()=>{const e=n.result;e.objectStoreNames.contains(this.storeName)||e.createObjectStore(this.storeName,{keyPath:"key"})},n.onsuccess=()=>t(n.result),n.onerror=()=>{r(n.error)}})),this.dbPromise}async get(e){try{const t=await this.openDatabase(),r=t.transaction(this.storeName,"readonly").objectStore(this.storeName),n=await this.promisifyRequest(r.get(e));return n?Date.now()-n.timestamp>this.cacheExpirationMs?(await this.remove(e).catch((()=>{})),null):n.data:null}catch(e){return null}}async set(e,t){try{const r=(await this.openDatabase()).transaction(this.storeName,"readwrite"),n=r.objectStore(this.storeName),i={key:e,timestamp:Date.now(),data:t};await this.promisifyRequest(n.put(i)),await new Promise(((e,t)=>{r.oncomplete=()=>e(),r.onerror=()=>t(r.error)}))}catch(e){throw e}}async remove(e){try{const t=(await this.openDatabase()).transaction(this.storeName,"readwrite"),r=t.objectStore(this.storeName);await this.promisifyRequest(r.delete(e)),await new Promise(((e,r)=>{t.oncomplete=()=>e(),t.onerror=()=>r(t.error)}))}catch(e){throw e}}async clear(){try{const e=(await this.openDatabase()).transaction(this.storeName,"readwrite"),t=e.objectStore(this.storeName);await this.promisifyRequest(t.clear()),await new Promise(((t,r)=>{e.oncomplete=()=>t(),e.onerror=()=>r(e.error)}))}catch(e){throw e}}async purgeExpired(){try{const e=(await this.openDatabase()).transaction(this.storeName,"readwrite"),t=e.objectStore(this.storeName),r=await this.promisifyRequest(t.getAll()),n=Date.now(),i=r.filter((e=>n-e.timestamp>this.cacheExpirationMs));for(const e of i)await this.promisifyRequest(t.delete(e.key));return await new Promise(((t,r)=>{e.oncomplete=()=>t(),e.onerror=()=>r(e.error)})),i.length}catch(e){return 0}}}class EventBus{static instance;events={};constructor(){}static getInstance(){return EventBus.instance||(EventBus.instance=new EventBus),EventBus.instance}on(e,t){return this.events[e]||(this.events[e]=[]),this.events[e].push(t),()=>this.off(e,t)}once(e,t){const wrapper=(...r)=>{this.off(e,wrapper),t(...r)};return this.on(e,wrapper)}off(e,t){this.events[e]&&(this.events[e]=this.events[e].filter((e=>e!==t)),0===this.events[e].length&&delete this.events[e])}emit(e,...t){if(!this.events[e])return;const r=[...this.events[e]];for(const e of r)try{e(...t)}catch{}}clear(e){void 0!==e?delete this.events[e]:this.events={}}}var u,m;!function(e){e[e.Second=0]="Second",e[e.Minute=1]="Minute",e[e.Hour=2]="Hour",e[e.Day=3]="Day",e[e.Week=4]="Week",e[e.Month=5]="Month",e[e.Bimonth=6]="Bimonth",e[e.Quarter=7]="Quarter",e[e.Semester=8]="Semester",e[e.Year=9]="Year"}(u||(u={})),function(e){e[e.BRL=0]="BRL",e[e.USD=1]="USD",e[e.EUR=2]="EUR",e[e.JPY=3]="JPY",e[e.GBP=4]="GBP",e[e.CNY=5]="CNY"}(m||(m={}));class WrittenOut{static formatDeadline(e,r){return t.format_deadline(e,r)}static formatNumber(e){return t.format_number(e)}static formatCurrency(e,r){return t.format_currency(e,r)}static formatDate(e){return t.format_date(BigInt(e.getTime()))}}const d={[m.BRL]:{locale:"pt-BR",currency:"BRL"},[m.USD]:{locale:"en-US",currency:"USD"},[m.EUR]:{locale:"de-DE",currency:"EUR"},[m.JPY]:{locale:"ja-JP",currency:"JPY"},[m.GBP]:{locale:"en-GB",currency:"GBP"},[m.CNY]:{locale:"zh-CN",currency:"CNY"}};class Util{static async parseNumber(e){return function(e){const t=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),r=_,n=l.parse_number(t,r);if(n[2])throw takeFromExternrefTable0(n[1]);return n[0]}(e)}static convertToMonetaryValue(e,t=m.BRL){const{locale:r,currency:n}=d[t];return e.toLocaleString(r,{minimumFractionDigits:2,maximumFractionDigits:2,style:"currency",currency:n})}static async removeAccents(e){return function(e){let t,r;try{const n=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),i=_,a=l.remove_accents(n,i);return t=a[0],r=a[1],getStringFromWasm0(a[0],a[1])}finally{l.__wbindgen_free(t,r,1)}}(e)}static async abbreviate(e){return function(e){let t,r;try{const n=passStringToWasm0(e,l.__wbindgen_malloc,l.__wbindgen_realloc),i=_,a=l.abbreviate(n,i);return t=a[0],r=a[1],getStringFromWasm0(a[0],a[1])}finally{l.__wbindgen_free(t,r,1)}}(e)}}var f;!function(e){e[e.DOCUMENT=0]="DOCUMENT",e[e.EMAIL=1]="EMAIL",e[e.MOBILE=2]="MOBILE",e[e.EVP=3]="EVP"}(f||(f={}));class Validate{static async isValidEmail(t){return e.is_valid_email(t)}static async isValidMobile(t){return e.is_valid_mobile(t)}static async isValidCNPJ(t){return e.is_valid_cnpj(t)}static async isValidCPF(t){return e.is_valid_cpf(t)}static async isValidCEP(t){return e.is_valid_cep(t)}static async isValidEVP(t){return e.is_valid_evp(t)}static async isValidPix(t,r){switch(t){case f.DOCUMENT:if(11===r.length){if(!e.is_valid_cpf(r))throw new Error("O CPF informado é inválido");return!0}if(14===r.length){if(!e.is_valid_cnpj(r))throw new Error("O CNPJ informado é inválido");return!0}throw new Error("O documento informado deve conter 11 ou 14 dígitos");case f.MOBILE:if(!e.is_valid_mobile(r))throw new Error("Chave PIX do tipo Número de Telefone possivelmente é inválida");return!0;case f.EMAIL:if(!e.is_valid_email(r))throw new Error("Chave PIX do tipo E-mail possivelmente é inválida");return!0;case f.EVP:if(!e.is_valid_evp(r))throw new Error("Chave PIX do tipo Chave aleatória possivelmente é inválida");return!0;default:throw new Error("Informe o tipo da chave PIX")}}}await async function(e){if(void 0!==l)return l;void 0!==e&&(Object.getPrototypeOf(e)===Object.prototype?({module_or_path:e}=e):console.warn("using deprecated parameters for the initialization function; pass a single object instead")),void 0===e&&(e=new URL("jsegd_bg.wasm",import.meta.url));const t={__proto__:null,"./jsegd_bg.js":{__proto__:null,__wbg_Error_960c155d3d49e4c2:function(e,t){return Error(getStringFromWasm0(e,t))},__wbg___wbindgen_throw_6b64449b9b9ed33c:function(e,t){throw new Error(getStringFromWasm0(e,t))},__wbindgen_cast_0000000000000001:function(e,t){return getStringFromWasm0(e,t)},__wbindgen_init_externref_table:function(){const e=l.__wbindgen_externrefs,t=e.grow(4);e.set(0,void 0),e.set(t+0,void 0),e.set(t+1,null),e.set(t+2,!0),e.set(t+3,!1)}}};("string"==typeof e||"function"==typeof Request&&e instanceof Request||"function"==typeof URL&&e instanceof URL)&&(e=fetch(e));const{instance:r,module:n}=await async function(e,t){if("function"==typeof Response&&e instanceof Response){if("function"==typeof WebAssembly.instantiateStreaming)try{return await WebAssembly.instantiateStreaming(e,t)}catch(t){if(!e.ok||!function(e){switch(e){case"basic":case"cors":case"default":return!0}return!1}(e.type)||"application/wasm"===e.headers.get("Content-Type"))throw t;console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",t)}const r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}{const r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}}(await e,t);return function(e){return l=e.exports,i=null,l.__wbindgen_start(),l}(r)}();export{m as Currency,u as DeadlineUnit,EventBus,LocalCache,f as TypePix,Util,Validate,WrittenOut}; //# sourceMappingURL=jsegd.js.map