UNPKG

@junobuild/utils

Version:

A collection of utilities and constants for Juno JS libs.

3 lines (2 loc) 3.47 kB
var a=class extends Error{},f=class extends Error{},i=(r,n)=>{if(r==null)throw new f(n)},T=(r,n)=>(i(r,n),r),N=r=>{if(r<0||r>100)throw new a(`${r} is not a valid percentage number.`)},d=(r,n)=>{throw new Error(n)};var h=r=>{let n=new DataView(r.buffer,r.byteOffset,r.byteLength);if(typeof n.getBigUint64=="function")return n.getBigUint64(0);let t=BigInt(n.getUint32(0)),e=BigInt(n.getUint32(4));return(t<<BigInt(32))+e},B=r=>{let n=new ArrayBuffer(8),t=new DataView(n);if(typeof t.setBigUint64=="function")t.setBigUint64(0,r);else{let e=Number(r>>BigInt(32)),s=Number(r&BigInt(4294967295));t.setUint32(0,e),t.setUint32(4,s)}return new Uint8Array(n)},_=r=>{let n=new DataView(new ArrayBuffer(8));for(let t=7;t>=0;--t)n.setUint8(t,r%256),r=r>>8;return new Uint8Array(n.buffer)},I=r=>new Uint8Array(r),S=r=>Array.from(r),k=r=>new Uint8Array(r),O=r=>Array.from(r).map(n=>n.charCodeAt(0)),j=r=>{let n=r.match(/.{1,2}/g);return i(n,"Invalid hex string."),Uint8Array.from(n.map(t=>parseInt(t,16)))},C=({a:r,b:n})=>r.length===n.length&&r.every((t,e)=>t===n[e]),E=r=>(r instanceof Uint8Array||(r=Uint8Array.from(r)),r.reduce((n,t)=>n+t.toString(16).padStart(2,"0"),"")),R=r=>{let n=0n;for(let t=r.length-1;t>=0;t--)n=(n<<32n)+BigInt(r[t]);return n};var P=r=>{let t=[];for(let e=0;e<r.length;e+=32768)t.push(String.fromCharCode(...r.subarray(e,e+32768)));return btoa(t.join(""))},J=r=>Uint8Array.from(atob(r),n=>n.charCodeAt(0));var y=1000000n,L=()=>BigInt(Date.now())*y,V=r=>BigInt(r.getTime())*y;var K=(r,n)=>{let t;return(...e)=>{let s=()=>r(...e);t&&clearTimeout(t),t=setTimeout(s,n!==void 0&&n>0?n:300)}};var x=r=>r==null,o=r=>!x(r),b=r=>o(r)&&r!=="",Z=r=>!b(r);var H=r=>o(r)?[r]:[],m=r=>r?.[0],M=r=>{let n=m(r);return i(n),n},Q=r=>m(r??[]);import{Principal as u}from"@icp-sdk/core/principal";var c="__bigint__",l="__principal__",p="__uint8array__",g=(r,n)=>typeof n=="bigint"?{[c]:`${n}`}:o(n)&&u.isPrincipal(n)?{[l]:u.from(n).toText()}:o(n)&&n instanceof Uint8Array?{[p]:Array.from(n)}:n,A=(r,n)=>{let t=e=>n[e];return o(n)&&typeof n=="object"&&c in n?BigInt(t(c)):o(n)&&typeof n=="object"&&l in n?u.fromText(t(l)):o(n)&&typeof n=="object"&&p in n?Uint8Array.from(t(p)):n};var tr=async r=>{let n=new Blob([JSON.stringify(r,g)],{type:"application/json; charset=utf-8"});return new Uint8Array(await n.arrayBuffer())},er=async r=>{let n=new Blob([r instanceof Uint8Array?r:new Uint8Array(r)],{type:"application/json; charset=utf-8"});return JSON.parse(await n.text(),A)};var ir=()=>typeof window<"u";var ar=r=>r.replace(/([a-zA-Z])(?=[A-Z])/g,"$1_").toLowerCase(),fr=r=>r.charAt(0).toUpperCase()+r.slice(1);export{a as InvalidPercentageError,f as NullishError,I as arrayBufferToUint8Array,k as arrayOfNumberToUint8Array,T as asNonNullish,O as asciiStringToByteArray,d as assertNever,i as assertNonNullish,N as assertPercentageNumber,J as base64ToUint8Array,B as bigIntToUint8Array,R as candidNumberArrayToBigInt,fr as capitalize,ar as convertCamelToSnake,K as debounce,er as fromArray,M as fromDefinedNullable,m as fromNullable,Q as fromNullishNullable,j as hexStringToUint8Array,ir as isBrowser,Z as isEmptyString,x as isNullish,g as jsonReplacer,A as jsonReviver,o as nonNullish,b as notEmptyString,L as nowInBigIntNanoSeconds,_ as numberToUint8Array,tr as toArray,V as toBigIntNanoSeconds,H as toNullable,S as uint8ArrayToArrayOfNumber,P as uint8ArrayToBase64,h as uint8ArrayToBigInt,E as uint8ArrayToHexString,C as uint8ArraysEqual}; //# sourceMappingURL=index.js.map