@companix/utils-js 0.0.14 → 0.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.cjs.js +1 -1
- package/dist/bundle.esm.js +1 -1
- package/dist/regex.d.ts +5 -1
- package/package.json +1 -1
package/dist/bundle.cjs.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var t=require("axios");const e=(t,e)=>{if(e<=0)throw new Error("Number of parts must be greater than 0");const r=[],s=Math.floor(t.length/e);let o=t.length%e,n=0;for(let i=0;i<e;i++){const e=n+s+(o>0?1:0),i=t.slice(n,e);i.length>0&&r.push(i),n=e,o--}return r};const r=(t,e)=>{const r=Math.pow(10,e);return Math.round(t*r)/r},s=(t,e=1)=>t>0?[0,".",...new Array(t-1).fill(0),e].join(""):`${e}`,o=t=>Object.keys(t);const n=(t,e)=>Math.floor(Math.random()*(e-t+1))+t;var i;!function(t){t.Get="GET",t.Post="POST"}(i||(i={}));const a=(t,e="token")=>{const r=t??localStorage.getItem(e);return r?`Bearer ${r}`:""},u=t=>t.toString().padStart(2,"0"),
|
|
1
|
+
"use strict";var t=require("axios");const e=(t,e)=>{if(e<=0)throw new Error("Number of parts must be greater than 0");const r=[],s=Math.floor(t.length/e);let o=t.length%e,n=0;for(let i=0;i<e;i++){const e=n+s+(o>0?1:0),i=t.slice(n,e);i.length>0&&r.push(i),n=e,o--}return r};const r=(t,e)=>{const r=Math.pow(10,e);return Math.round(t*r)/r},s=(t,e=1)=>t>0?[0,".",...new Array(t-1).fill(0),e].join(""):`${e}`,o=t=>Object.keys(t);const n=(t,e)=>Math.floor(Math.random()*(e-t+1))+t;var i;!function(t){t.Get="GET",t.Post="POST"}(i||(i={}));const a=(t,e="token")=>{const r=t??localStorage.getItem(e);return r?`Bearer ${r}`:""},u={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,}))$/,phone:/^[0-9]+$/},c={email:t=>u.email.test(t),phone:t=>u.phone.test(t)},p=t=>t.toString().padStart(2,"0"),h={"1s":1e3,"1m":6e4,"3m":18e4,"5m":3e5},l=(t,e)=>Math.floor(t/h[e])*h[e];exports.EventBroadcaster=class{subscribers=[];emit(t){this.subscribers.forEach(e=>{e(t)})}subscribe(t){return this.subscribers.push(t),()=>{this.unsubscribe(t)}}unsubscribe(t){const e=this.subscribers.findIndex(e=>e===t);-1!==e&&this.subscribers.splice(e,1)}},exports.EventDispatcher=class{store={};emit(t,e){this.store[t]&&this.store[t](e)}on(t,e){return this.store[t]=e,()=>{this.rm(t)}}rm(t){delete this.store[t]}},exports.EventEmmiter=class{store={};emit(t,e){this.store[t]&&this.store[t].forEach(t=>t(e))}subscribe(t,e){return this.store[t]||(this.store[t]=[]),this.store[t].push(e),()=>{this.unsubscribe(t,e)}}unsubscribe(t,e){if(this.store[t]){const r=this.store[t].findIndex(t=>t===e);-1!==r&&(this.store[t].splice(r,1),0===this.store[t].length&&delete this.store[t])}}},exports.HttpAPI=class{http;constructor(e){this.http=t.create(e)}async request(t){const{url:e,body:r={},method:s,config:o={}}=t,n=s===i.Get?"params":"data";return this.http({url:e,method:s,[n]:r,...o}).then(({data:t})=>t)}post(t,e,r){return this.request({method:i.Post,url:t,config:r,body:e})}get(t,e,r){return this.request({method:i.Get,url:t,config:r,body:e})}},exports.QueueManager=class{active=!1;queue=[];add(t){return new Promise((e,r)=>{this.queue.push({resolve:e,reject:r,target:t}),this.active||this.next()})}async next(){const t=this.queue[0];t?(this.active=!0,await t.target().then(e=>t.resolve(e)).catch(e=>t.reject(e)).finally(()=>this.queue.shift()),await this.next()):this.active=!1}},exports.applyAlphaToHex=(t,e)=>{t.startsWith("#")&&(t=t.slice(1));return`rgba(${parseInt(t.slice(0,2),16)}, ${parseInt(t.slice(2,4),16)}, ${parseInt(t.slice(4,6),16)}, ${Math.max(0,Math.min(100,e))/100})`},exports.bigMoneyAmount=t=>{const e=t/1e3;if(e>=1e3){const t=e/1e3;return t>=1e3?t/1e3+" МЛРД. ₽":`${t} МЛН. ₽`}return`${e} ТЫС. ₽`},exports.checkPattern=c,exports.contain=t=>t.reduce((t,e)=>[...t,...e],[]),exports.cutNumber=(t,e)=>{const r=Math.pow(10,e);return Math.floor(t*r)/r},exports.dollars=(t,e)=>t.toLocaleString("us-US",{style:"currency",currency:"USD"}),exports.formatBytes=t=>{const e=t/1024;return e>1024?+(e/1024).toFixed(1)+" MB":e<1?t+" B":Math.trunc(+e.toFixed(2))+" KB"},exports.formatTime=p,exports.generateCode=t=>{const e="A0B1C2D3E4F5G6H7W89K0L1M2N34P5Q6R7S8T9U0V3XYZ",r=[];for(let s=0;s<t;s++){const t=Math.floor(45*Math.random());r.push(e[t])}return r.join("")},exports.generatePreview=t=>{const e=URL.createObjectURL(t);return{url:e,destroy:()=>{URL.revokeObjectURL(e)}}},exports.getAuthToken=a,exports.getCurrentCandleTime=l,exports.getDate=(t,e=!0)=>{const r=new Date(t),s=e?"UTC":"";return[p(r[`get${s}Date`]()),p(r[`get${s}Month`]()+1),p(r[`get${s}FullYear`]())].join(":")},exports.getFiles=t=>Array.from(t),exports.getFloatDigits=t=>{if(t.includes("e")){const[e,r]=t.split("e");return Math.max((e.split(".")[1]?.length||0)-+r,0)}return t.split(".")[1]?.length||0},exports.getHeaders=({token:t,tokenStore:e,multipart:r}={})=>{const s=a(t,e),o={"Content-Type":r?"multipart/form-data; charset=utf-8":"application/json"};return s&&(o.Authorization=s),o},exports.getLastClosedCandleTime=(t,e)=>l(t,e)-h[e],exports.getNextCandleTime=(t,e)=>l(t,e)+h[e],exports.getNoun=(t,e,r,s)=>{let o=Math.abs(t);return o%=100,o>=5&&o<=20?s:(o%=10,1===o?e:o>=2&&o<=4?r:s)},exports.getNum=t=>isNaN(Number(t))?null:+t,exports.getPrecisionStep=s,exports.getRandomInt=n,exports.getRandomIntString=t=>new Array(t).fill(0).map(()=>n(0,9)).join(""),exports.getRandomItemFromArray=(t,e)=>{const r=e&&e.exceptions.length<t.length?t.filter(t=>!e.exceptions.some(r=>e.isEqual(t,r))):t;return r[r.length*Math.random()|0]},exports.getTime=(t,e=!0)=>{const r=new Date(t),s=e?"UTC":"";return[p(r[`get${s}Hours`]()),p(r[`get${s}Minutes`]()),p(r[`get${s}Seconds`]())].join(":")},exports.getTimes=t=>{t<0&&(t=0);const e=Math.floor(t/1e3);return{hours:Math.floor(e/3600),minutes:Math.floor(e%3600/60),seconds:e%60}},exports.hash=()=>{const t="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=(16*Math.random()+t)%16|0;return("x"===e?r:3&r|8).toString(16)})},exports.intervals=h,exports.isEmpty=t=>{for(const e in t)return!1;return!0},exports.isValidPrecision=(t,e)=>{const r=t.toString();return!r.includes(".")||0!==e&&r.split(".")[1].length<=e},exports.keys=o,exports.keysLength=t=>o(t).length,exports.nonNullable=t=>null!=t,exports.normalize=r,exports.omit=(t,e)=>(delete t[e],t),exports.partial=t=>{const e={};for(const r in t)t[r]&&(e[r]=t[r]);return e},exports.range=(t,e,r=1)=>{const s=t<e?1:-1,o=Math.abs(t-e)+1,n=Math.ceil(o/r),i=Array(n);for(let e=0;e<i.length;e++)i[e]=t+e*r*s;return i},exports.regex=u,exports.rgbaToHex=t=>{const e=t.match(/rgba?\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d.]+)\s*\)/);if(!e)throw new Error("Некорректный формат RGBA");const[,r,s,o,n]=e,i=t=>parseInt(t).toString(16).padStart(2,"0"),a=Math.round(255*parseFloat(n));return`#${i(r)}${i(s)}${i(o)}${i(a.toString())}`},exports.roundSeparateArray=(t,r)=>{const s=Math.round(t.length/r);return s>1?e(t,s):[t]},exports.roundUp2=(t,e)=>{const o=t.toFixed(e);return t>+o?r(+o+ +s(e),e):+o},exports.rubles=(t,e)=>t.toLocaleString("ru-RU",{style:"currency",currency:"RUB",...e?.noPennies?{minimumFractionDigits:0,maximumFractionDigits:0}:{}}),exports.separateArray=e,exports.sleep=t=>new Promise(e=>setTimeout(e,t)),exports.splitByChunks=(t,e)=>{const r=[];for(let s=0;s<t.length;s+=e)r.push(t.slice(s,s+e));return r},exports.stringify=(...t)=>t.map(t=>JSON.stringify(t)).join(" "),exports.transport=t=>{const e=new FormData;return e.append("file",t),e.append("type","file"),e},exports.truncateNumber=(t,e)=>{const r=t.toFixed(e);return+r>t?(+r-Math.sign(t)*Math.pow(.1,e)).toFixed(e):r};
|
package/dist/bundle.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import t from"axios";const e=(t,e,r=1)=>{const s=t<e?1:-1,n=Math.abs(t-e)+1,o=Math.ceil(n/r),i=Array(o);for(let e=0;e<i.length;e++)i[e]=t+e*r*s;return i},r=(t,e)=>{const r=[];for(let s=0;s<t.length;s+=e)r.push(t.slice(s,s+e));return r},s=(t,e)=>{if(e<=0)throw new Error("Number of parts must be greater than 0");const r=[],s=Math.floor(t.length/e);let n=t.length%e,o=0;for(let i=0;i<e;i++){const e=o+s+(n>0?1:0),i=t.slice(o,e);i.length>0&&r.push(i),o=e,n--}return r},n=(t,e)=>{const r=Math.round(t.length/e);return r>1?s(t,r):[t]},o=(t,e)=>{t.startsWith("#")&&(t=t.slice(1));return`rgba(${parseInt(t.slice(0,2),16)}, ${parseInt(t.slice(2,4),16)}, ${parseInt(t.slice(4,6),16)}, ${Math.max(0,Math.min(100,e))/100})`},i=t=>{const e=t.match(/rgba?\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d.]+)\s*\)/);if(!e)throw new Error("Некорректный формат RGBA");const[,r,s,n,o]=e,i=t=>parseInt(t).toString(16).padStart(2,"0"),a=Math.round(255*parseFloat(o));return`#${i(r)}${i(s)}${i(n)}${i(a.toString())}`};class a{store={};emit(t,e){this.store[t]&&this.store[t](e)}on(t,e){return this.store[t]=e,()=>{this.rm(t)}}rm(t){delete this.store[t]}}class c{store={};emit(t,e){this.store[t]&&this.store[t].forEach(t=>t(e))}subscribe(t,e){return this.store[t]||(this.store[t]=[]),this.store[t].push(e),()=>{this.unsubscribe(t,e)}}unsubscribe(t,e){if(this.store[t]){const r=this.store[t].findIndex(t=>t===e);-1!==r&&(this.store[t].splice(r,1),0===this.store[t].length&&delete this.store[t])}}}class u{subscribers=[];emit(t){this.subscribers.forEach(e=>{e(t)})}subscribe(t){return this.subscribers.push(t),()=>{this.unsubscribe(t)}}unsubscribe(t){const e=this.subscribers.findIndex(e=>e===t);-1!==e&&this.subscribers.splice(e,1)}}const h=t=>{if(t.includes("e")){const[e,r]=t.split("e");return Math.max((e.split(".")[1]?.length||0)-+r,0)}return t.split(".")[1]?.length||0},l=(t,e)=>{const r=Math.pow(10,e);return Math.round(t*r)/r},
|
|
1
|
+
import t from"axios";const e=(t,e,r=1)=>{const s=t<e?1:-1,n=Math.abs(t-e)+1,o=Math.ceil(n/r),i=Array(o);for(let e=0;e<i.length;e++)i[e]=t+e*r*s;return i},r=(t,e)=>{const r=[];for(let s=0;s<t.length;s+=e)r.push(t.slice(s,s+e));return r},s=(t,e)=>{if(e<=0)throw new Error("Number of parts must be greater than 0");const r=[],s=Math.floor(t.length/e);let n=t.length%e,o=0;for(let i=0;i<e;i++){const e=o+s+(n>0?1:0),i=t.slice(o,e);i.length>0&&r.push(i),o=e,n--}return r},n=(t,e)=>{const r=Math.round(t.length/e);return r>1?s(t,r):[t]},o=(t,e)=>{t.startsWith("#")&&(t=t.slice(1));return`rgba(${parseInt(t.slice(0,2),16)}, ${parseInt(t.slice(2,4),16)}, ${parseInt(t.slice(4,6),16)}, ${Math.max(0,Math.min(100,e))/100})`},i=t=>{const e=t.match(/rgba?\s*\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*([\d.]+)\s*\)/);if(!e)throw new Error("Некорректный формат RGBA");const[,r,s,n,o]=e,i=t=>parseInt(t).toString(16).padStart(2,"0"),a=Math.round(255*parseFloat(o));return`#${i(r)}${i(s)}${i(n)}${i(a.toString())}`};class a{store={};emit(t,e){this.store[t]&&this.store[t](e)}on(t,e){return this.store[t]=e,()=>{this.rm(t)}}rm(t){delete this.store[t]}}class c{store={};emit(t,e){this.store[t]&&this.store[t].forEach(t=>t(e))}subscribe(t,e){return this.store[t]||(this.store[t]=[]),this.store[t].push(e),()=>{this.unsubscribe(t,e)}}unsubscribe(t,e){if(this.store[t]){const r=this.store[t].findIndex(t=>t===e);-1!==r&&(this.store[t].splice(r,1),0===this.store[t].length&&delete this.store[t])}}}class u{subscribers=[];emit(t){this.subscribers.forEach(e=>{e(t)})}subscribe(t){return this.subscribers.push(t),()=>{this.unsubscribe(t)}}unsubscribe(t){const e=this.subscribers.findIndex(e=>e===t);-1!==e&&this.subscribers.splice(e,1)}}const h=t=>{if(t.includes("e")){const[e,r]=t.split("e");return Math.max((e.split(".")[1]?.length||0)-+r,0)}return t.split(".")[1]?.length||0},l=(t,e)=>{const r=Math.pow(10,e);return Math.round(t*r)/r},p=(t,e)=>{const r=Math.pow(10,e);return Math.floor(t*r)/r},m=(t,e)=>{const r=t.toFixed(e);return t>+r?l(+r+ +d(e),e):+r},x=(t,e)=>{const r=t.toFixed(e);return+r>t?(+r-Math.sign(t)*Math.pow(.1,e)).toFixed(e):r},d=(t,e=1)=>t>0?[0,".",...new Array(t-1).fill(0),e].join(""):`${e}`,f=(t,e)=>{const r=t.toString();return!r.includes(".")||0!==e&&r.split(".")[1].length<=e},g=t=>isNaN(Number(t))?null:+t,b=t=>Object.keys(t),M=t=>b(t).length,y=t=>{for(const e in t)return!1;return!0},$=(t,e)=>(delete t[e],t),w=t=>{const e={};for(const r in t)t[r]&&(e[r]=t[r]);return e};class S{active=!1;queue=[];add(t){return new Promise((e,r)=>{this.queue.push({resolve:e,reject:r,target:t}),this.active||this.next()})}async next(){const t=this.queue[0];t?(this.active=!0,await t.target().then(e=>t.resolve(e)).catch(e=>t.reject(e)).finally(()=>this.queue.shift()),await this.next()):this.active=!1}}const j=t=>{const e="A0B1C2D3E4F5G6H7W89K0L1M2N34P5Q6R7S8T9U0V3XYZ",r=[];for(let s=0;s<t;s++){const t=Math.floor(45*Math.random());r.push(e[t])}return r.join("")},F=(t,e)=>Math.floor(Math.random()*(e-t+1))+t,U=t=>new Array(t).fill(0).map(()=>F(0,9)).join(""),A=()=>{const t="undefined"==typeof performance?Date.now():1e3*performance.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const r=(16*Math.random()+t)%16|0;return("x"===e?r:3&r|8).toString(16)})},D=(t,e)=>{const r=e&&e.exceptions.length<t.length?t.filter(t=>!e.exceptions.some(r=>e.isEqual(t,r))):t;return r[r.length*Math.random()|0]},q=t=>new Promise(e=>setTimeout(e,t)),v=(...t)=>t.map(t=>JSON.stringify(t)).join(" "),R=t=>t.reduce((t,e)=>[...t,...e],[]),B=t=>null!=t;var E;!function(t){t.Get="GET",t.Post="POST"}(E||(E={}));class I{http;constructor(e){this.http=t.create(e)}async request(t){const{url:e,body:r={},method:s,config:n={}}=t,o=s===E.Get?"params":"data";return this.http({url:e,method:s,[o]:r,...n}).then(({data:t})=>t)}post(t,e,r){return this.request({method:E.Post,url:t,config:r,body:e})}get(t,e,r){return this.request({method:E.Get,url:t,config:r,body:e})}}const L=({token:t,tokenStore:e,multipart:r}={})=>{const s=P(t,e),n={"Content-Type":r?"multipart/form-data; charset=utf-8":"application/json"};return s&&(n.Authorization=s),n},P=(t,e="token")=>{const r=t??localStorage.getItem(e);return r?`Bearer ${r}`:""},T=t=>{const e=new FormData;return e.append("file",t),e.append("type","file"),e},G=t=>{const e=URL.createObjectURL(t);return{url:e,destroy:()=>{URL.revokeObjectURL(e)}}},N=t=>Array.from(t),k=t=>{const e=t/1e3;if(e>=1e3){const t=e/1e3;return t>=1e3?t/1e3+" МЛРД. ₽":`${t} МЛН. ₽`}return`${e} ТЫС. ₽`},O=(t,e)=>t.toLocaleString("ru-RU",{style:"currency",currency:"RUB",...e?.noPennies?{minimumFractionDigits:0,maximumFractionDigits:0}:{}}),C=(t,e)=>t.toLocaleString("us-US",{style:"currency",currency:"USD"}),z=(t,e,r,s)=>{let n=Math.abs(t);return n%=100,n>=5&&n<=20?s:(n%=10,1===n?e:n>=2&&n<=4?r:s)},Z={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,}))$/,phone:/^[0-9]+$/},H={email:t=>Z.email.test(t),phone:t=>Z.phone.test(t)},K=t=>{const e=t/1024;return e>1024?+(e/1024).toFixed(1)+" MB":e<1?t+" B":Math.trunc(+e.toFixed(2))+" KB"},W=t=>t.toString().padStart(2,"0"),Y=t=>{t<0&&(t=0);const e=Math.floor(t/1e3);return{hours:Math.floor(e/3600),minutes:Math.floor(e%3600/60),seconds:e%60}},J=(t,e=!0)=>{const r=new Date(t),s=e?"UTC":"";return[W(r[`get${s}Hours`]()),W(r[`get${s}Minutes`]()),W(r[`get${s}Seconds`]())].join(":")},Q=(t,e=!0)=>{const r=new Date(t),s=e?"UTC":"";return[W(r[`get${s}Date`]()),W(r[`get${s}Month`]()+1),W(r[`get${s}FullYear`]())].join(":")},V={"1s":1e3,"1m":6e4,"3m":18e4,"5m":3e5},X=(t,e)=>_(t,e)-V[e],_=(t,e)=>Math.floor(t/V[e])*V[e],tt=(t,e)=>_(t,e)+V[e];export{u as EventBroadcaster,a as EventDispatcher,c as EventEmmiter,I as HttpAPI,S as QueueManager,o as applyAlphaToHex,k as bigMoneyAmount,H as checkPattern,R as contain,p as cutNumber,C as dollars,K as formatBytes,W as formatTime,j as generateCode,G as generatePreview,P as getAuthToken,_ as getCurrentCandleTime,Q as getDate,N as getFiles,h as getFloatDigits,L as getHeaders,X as getLastClosedCandleTime,tt as getNextCandleTime,z as getNoun,g as getNum,d as getPrecisionStep,F as getRandomInt,U as getRandomIntString,D as getRandomItemFromArray,J as getTime,Y as getTimes,A as hash,V as intervals,y as isEmpty,f as isValidPrecision,b as keys,M as keysLength,B as nonNullable,l as normalize,$ as omit,w as partial,e as range,Z as regex,i as rgbaToHex,n as roundSeparateArray,m as roundUp2,O as rubles,s as separateArray,q as sleep,r as splitByChunks,v as stringify,T as transport,x as truncateNumber};
|
package/dist/regex.d.ts
CHANGED